-
Notifications
You must be signed in to change notification settings - Fork 1
[LFXV2-502] alternate email linking - authelia #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mauriciozanettisalomao
merged 8 commits into
linuxfoundation:main
from
mauriciozanettisalomao:feat/lfxv2-501-alternate-email-linking-authelia
Oct 27, 2025
+3,116
−216
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2482f48
feat: implement email OTP functionality for passwordless flows
mauriciozanettisalomao 23c749e
feat: add user email retrieval functionality and update documentation
mauriciozanettisalomao 4d68080
feat: add OTP verification flow for alternate email linking
mauriciozanettisalomao 71f7cac
fix: update configuration references in SMTP client and documentation
mauriciozanettisalomao 7bc67ba
fix: update SMTP sender to use direct client fields for host and port
mauriciozanettisalomao a1194de
fix: update comments and references in configuration files
mauriciozanettisalomao e6c0c36
fix: modify error handling in NewRegularWebAuthConfig function
mauriciozanettisalomao 0e1129c
fix: update comment formatting in NewRegularWebAuthConfig function
mauriciozanettisalomao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| # User Emails Operations | ||
|
|
||
| This document describes the NATS subject for retrieving user email addresses. | ||
|
|
||
| --- | ||
|
|
||
| ## User Emails Retrieval | ||
|
|
||
| To retrieve user email addresses (both primary and alternate emails), send a NATS request to the following subject: | ||
|
|
||
| **Subject:** `lfx.auth-service.user_emails.read` | ||
| **Pattern:** Request/Reply | ||
|
|
||
| The service supports a **hybrid approach** for user email retrieval, accepting multiple input types and automatically determining the appropriate lookup strategy based on the input format. | ||
|
|
||
| ### Hybrid Input Support | ||
|
|
||
| The service intelligently handles different input types: | ||
|
|
||
| 1. **JWT Tokens** (Auth0) or **Authelia Tokens** (Authelia) | ||
| 2. **Subject Identifiers** (canonical user IDs) | ||
| 3. **Usernames** | ||
|
|
||
| ### Request Payload | ||
|
|
||
| The request payload can be any of the following formats (no JSON wrapping required): | ||
|
|
||
| **JWT Token (Auth0):** | ||
| ``` | ||
| eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9... | ||
| ``` | ||
|
|
||
| **Subject Identifier:** | ||
| ``` | ||
| auth0|123456789 | ||
| ``` | ||
|
|
||
| **Username:** | ||
| ``` | ||
| john.doe | ||
| ``` | ||
|
|
||
| ### Lookup Strategy | ||
|
|
||
| The service automatically determines the lookup strategy based on input format: | ||
|
|
||
| - **Token Strategy**: If input is a JWT/Authelia token, validates the token and extracts the subject identifier | ||
| - **Canonical Lookup**: If input contains `|` (pipe character) or is a UUID, treats as subject identifier for direct lookup | ||
| - **Username Search**: If input doesn't match above patterns, treats as username for search lookup | ||
|
|
||
| ### Reply | ||
|
|
||
| The service returns a structured reply with user email information: | ||
|
|
||
| **Success Reply:** | ||
| ```json | ||
| { | ||
| "success": true, | ||
| "data": { | ||
| "primary_email": "[email protected]", | ||
| "alternate_emails": [ | ||
| { | ||
| "email": "[email protected]", | ||
| "verified": true | ||
| }, | ||
| { | ||
| "email": "[email protected]", | ||
| "verified": false | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Success Reply (No Alternate Emails):** | ||
| ```json | ||
| { | ||
| "success": true, | ||
| "data": { | ||
| "primary_email": "[email protected]", | ||
| "alternate_emails": [] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Error Reply (User Not Found):** | ||
| ```json | ||
| { | ||
| "success": false, | ||
| "error": "user not found" | ||
| } | ||
| ``` | ||
|
|
||
| **Error Reply (Invalid Token):** | ||
| ```json | ||
| { | ||
| "success": false, | ||
| "error": "invalid token" | ||
| } | ||
| ``` | ||
|
|
||
| ### Response Fields | ||
|
|
||
| - `primary_email` (string): The user's primary email address registered with the identity provider | ||
| - `alternate_emails` (array): List of alternate email addresses linked to the user account | ||
| - `email` (string): The alternate email address | ||
| - `verified` (boolean): Whether the alternate email has been verified | ||
|
|
||
| ### Example using NATS CLI | ||
|
|
||
| ```bash | ||
| # Retrieve user emails using JWT token | ||
| nats request lfx.auth-service.user_emails.read "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." | ||
|
|
||
| # Retrieve user emails using subject identifier | ||
| nats request lfx.auth-service.user_emails.read "auth0|123456789" | ||
|
|
||
| # Retrieve user emails using username | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | ||
| ``` | ||
|
|
||
| ### Example Response Processing | ||
|
|
||
| ```bash | ||
| # Get and format the response | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | jq '.' | ||
|
|
||
| # Extract only the primary email | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | jq -r '.data.primary_email' | ||
|
|
||
| # List all verified alternate emails | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | jq -r '.data.alternate_emails[] | select(.verified == true) | .email' | ||
|
|
||
| # Count total email addresses (primary + alternates) | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | jq '.data.alternate_emails | length + 1' | ||
| ``` | ||
|
|
||
| **Important Notes:** | ||
| - The service automatically detects input type and applies the appropriate lookup strategy | ||
| - JWT tokens are validated for signature and expiration before extracting subject information | ||
| - The target identity provider is determined by the `USER_REPOSITORY_TYPE` environment variable | ||
| - Primary email is always present if the user exists | ||
| - Alternate emails array may be empty if the user has not linked any additional email addresses | ||
| - Only verified alternate emails should be considered as confirmed user identities | ||
| - For detailed Auth0-specific behavior and limitations, see: [`../internal/infrastructure/auth0/README.md`](../internal/infrastructure/auth0/README.md) | ||
| - For detailed Authelia-specific behavior and SUB management, see: [`../internal/infrastructure/authelia/README.md`](../internal/infrastructure/authelia/README.md) | ||
|
|
||
| --- | ||
|
|
||
| ## Use Cases | ||
|
|
||
| ### Identity Verification | ||
| When you need to verify if a user owns a specific email address: | ||
| ```bash | ||
| # Get all user emails | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | ||
| ``` | ||
|
|
||
| ### Email Communication | ||
| When you need to send notifications to all verified user email addresses: | ||
| ```bash | ||
| # Extract all verified emails (primary + verified alternates) | ||
| nats request lfx.auth-service.user_emails.read "john.doe" | \ | ||
| jq -r '(.data.primary_email, (.data.alternate_emails[] | select(.verified == true) | .email))' | ||
| ``` | ||
|
|
||
| ### Account Recovery | ||
| When displaying email options for account recovery: | ||
| ```bash | ||
| # Show all verified email addresses for recovery selection | ||
| nats request lfx.auth-service.user_emails.read "auth0|123456789" | \ | ||
| jq '.data.alternate_emails[] | select(.verified == true)' | ||
| ``` | ||
|
|
||
| ### Email Uniqueness Check | ||
| To check if an email is already associated with a user account, use the email lookup subjects: | ||
| - `lfx.auth-service.email_to_username` - Get username from email | ||
| - `lfx.auth-service.email_to_sub` - Get user ID from email | ||
|
|
||
| See [`email_lookups.md`](email_lookups.md) for more details on these subjects. | ||
|
|
||
| --- | ||
|
|
||
| ## Related Subjects | ||
|
|
||
| - **Email Lookup**: [`email_lookups.md`](email_lookups.md) | ||
| - **Email Verification**: [`email_verification.md`](email_verification.md) | ||
| - **User Metadata**: [`user_metadata.md`](user_metadata.md) | ||
| - **Identity Linking**: [`identity_linking.md`](identity_linking.md) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.