-
Notifications
You must be signed in to change notification settings - Fork 265
Add comprehensive authority configuration and precedence documentation #3617
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
Open
Copilot
wants to merge
7
commits into
master
Choose a base branch
from
copilot/update-docs-for-authority-precedence
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d4c1360
Fix Authority-only configuration: Parse to Instance/TenantId for AAD,…
Copilot 64139f1
Add high-performance warning logging for Authority + Instance/TenantI…
Copilot bab62bd
Initial plan
Copilot 28e7e5b
Add comprehensive authority configuration documentation
Copilot 4491701
Remove PreserveAuthority from documentation and add sovereign cloud link
Copilot 0927e20
Sync branch with master to resolve conflicts
Copilot 170ad8a
Sync branch with master (4.8.0) to resolve conflicts
Copilot 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,239 @@ | ||||||
| # Authority Configuration & Precedence in Microsoft.Identity.Web | ||||||
|
|
||||||
| ## Overview | ||||||
|
|
||||||
| Microsoft.Identity.Web provides flexible options for configuring authentication authority URLs. Understanding how these configuration options interact is crucial for proper application setup, especially when working with Azure Active Directory (AAD), Azure AD B2C, and Customer Identity and Access Management (CIAM). | ||||||
|
|
||||||
| This guide explains: | ||||||
| - How authority-related configuration properties work together | ||||||
| - The precedence rules when multiple properties are set | ||||||
| - Best practices for different authentication scenarios | ||||||
| - How to interpret and resolve configuration warnings | ||||||
|
|
||||||
| ## Terminology | ||||||
|
|
||||||
| ### Core Configuration Properties | ||||||
|
|
||||||
| - **Authority**: A complete URL to the authentication endpoint, including the instance and tenant identifier. Examples: | ||||||
| - `https://login.microsoftonline.com/common` | ||||||
| - `https://login.microsoftonline.com/contoso.onmicrosoft.com` | ||||||
| - `https://contoso.b2clogin.com/contoso.onmicrosoft.com/B2C_1_susi` | ||||||
|
|
||||||
| - **Instance**: The base URL of the authentication service without tenant information. Examples: | ||||||
| - `https://login.microsoftonline.com/` | ||||||
| - `https://login.microsoftonline.us/` (Azure Government) | ||||||
| - `https://contoso.b2clogin.com/` | ||||||
|
|
||||||
|
jmprieur marked this conversation as resolved.
|
||||||
| - **TenantId**: The tenant identifier, which can be: | ||||||
| - A GUID (e.g., `12345678-1234-1234-1234-123456789012`) | ||||||
| - A tenant domain (e.g., `contoso.onmicrosoft.com`) | ||||||
| - Special values (`common`, `organizations`, `consumers`) | ||||||
|
|
||||||
| - **Domain**: The primary domain of your tenant (e.g., `contoso.onmicrosoft.com`). Used primarily with B2C configurations. | ||||||
|
|
||||||
| - **PreserveAuthority**: A boolean flag (default: `false`) that prevents parsing of the Authority URL into Instance and TenantId components. This is particularly important for CIAM scenarios with custom domains. | ||||||
|
|
||||||
| - **Policy IDs**: B2C-specific identifiers for user flows: | ||||||
| - `SignUpSignInPolicyId` (e.g., `B2C_1_susi`) | ||||||
| - `ResetPasswordPolicyId` (e.g., `B2C_1_reset`) | ||||||
| - `EditProfilePolicyId` (e.g., `B2C_1_edit_profile`) | ||||||
|
|
||||||
| ## Authority Resolution Decision Tree | ||||||
|
|
||||||
| The following flowchart illustrates how Microsoft.Identity.Web resolves the authority configuration: | ||||||
|
|
||||||
| ```mermaid | ||||||
| flowchart TD | ||||||
| A[Configuration Provided] --> B{Instance & TenantId set?} | ||||||
| B -- Yes --> C[Use Instance & TenantId<br/>Ignore Authority if present] | ||||||
| B -- No --> D{Authority Provided?} | ||||||
| D -- No --> E[Configuration Invalid<br/>Requires Instance+TenantId] | ||||||
| D -- Yes --> F{PreserveAuthority True?} | ||||||
| F -- Yes --> G[Use full Authority as Instance<br/>TenantId = null] | ||||||
| F -- No --> H[Parse Authority<br/>Extract Instance + TenantId] | ||||||
| H --> I{Is B2C?} | ||||||
| I -- Yes --> J[Normalize /tfp/ if present<br/>Derive PreparedInstance] | ||||||
| I -- No --> K[Derive PreparedInstance] | ||||||
| C --> K | ||||||
| G --> K | ||||||
| K --> L[Pass PreparedInstance to MSAL] | ||||||
| ``` | ||||||
|
|
||||||
| ## Precedence Rules | ||||||
|
|
||||||
| The following table summarizes how different configuration combinations are resolved: | ||||||
|
|
||||||
| | Authority Set | Instance Set | TenantId Set | PreserveAuthority | Result | Warning | | ||||||
| |---------------|--------------|--------------|-------------------|--------|---------| | ||||||
| | ✅ | ❌ | ❌ | `false` | Authority is parsed → Instance + TenantId | No | | ||||||
| | ✅ | ❌ | ❌ | `true` | Full Authority used as Instance, TenantId = null | No | | ||||||
| | ✅ | ✅ | ❌ | any | Instance used, Authority **ignored** | ⚠️ Yes (EventId 408) | | ||||||
| | ✅ | ❌ | ✅ | any | TenantId used, Authority **ignored** | ⚠️ Yes (EventId 408) | | ||||||
| | ✅ | ✅ | ✅ | any | Instance + TenantId used, Authority **ignored** | ⚠️ Yes (EventId 408) | | ||||||
| | ❌ | ✅ | ✅ | any | Instance + TenantId used | No | | ||||||
| | ❌ | ✅ | ❌ | any | Instance used, tenant resolved at runtime | No* | | ||||||
| | ❌ | ❌ | ✅ | any | Invalid configuration | Error | | ||||||
|
|
||||||
| \* For single-tenant apps, this may cause issues. Always specify TenantId when using Instance. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the footnote text as suggested in commit 4491701. |
||||||
|
|
||||||
| ## Recommended Configuration Patterns | ||||||
|
|
||||||
| ### AAD Single-Tenant Application | ||||||
|
|
||||||
| **Recommended**: Use `Instance` and `TenantId` separately for clarity and flexibility. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAd": { | ||||||
| "Instance": "https://login.microsoftonline.com/", | ||||||
| "TenantId": "12345678-1234-1234-1234-123456789012", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| **Alternative**: Use `Authority` (will be parsed automatically). | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAd": { | ||||||
| "Authority": "https://login.microsoftonline.com/12345678-1234-1234-1234-123456789012", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### AAD Multi-Tenant Application | ||||||
|
|
||||||
| **Option 1**: Use `Instance` with special tenant value. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAd": { | ||||||
| "Instance": "https://login.microsoftonline.com/", | ||||||
| "TenantId": "organizations", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| **Option 2**: Use complete `Authority`. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAd": { | ||||||
| "Authority": "https://login.microsoftonline.com/organizations", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### Azure AD B2C | ||||||
|
|
||||||
| **Recommended**: Use `Authority` including the policy path. Do NOT mix with `Instance`/`TenantId`. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAdB2C": { | ||||||
| "Authority": "https://contoso.b2clogin.com/contoso.onmicrosoft.com/B2C_1_susi", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111", | ||||||
| "Domain": "contoso.onmicrosoft.com" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| **Note**: The legacy `/tfp/` path segment is automatically normalized by Microsoft.Identity.Web: | ||||||
| - `https://contoso.b2clogin.com/tfp/contoso.onmicrosoft.com/B2C_1_susi` | ||||||
| - Becomes: `https://contoso.b2clogin.com/contoso.onmicrosoft.com/B2C_1_susi` | ||||||
|
|
||||||
| See [B2C Authority Examples](b2c-authority-examples.md) for more details. | ||||||
|
|
||||||
| ### CIAM (Customer Identity and Access Management) | ||||||
|
|
||||||
| **Recommended**: Use `Authority` with `PreserveAuthority: true` to prevent unwanted parsing, especially with custom domains. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAd": { | ||||||
| "Authority": "https://contoso.ciamlogin.com/contoso.onmicrosoft.com", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111", | ||||||
| "PreserveAuthority": true | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| See [CIAM Authority Examples](ciam-authority-examples.md) for more details. | ||||||
|
|
||||||
| ## Understanding the Warning Log Message | ||||||
|
|
||||||
| When both `Authority` and (`Instance` and/or `TenantId`) are configured, you'll see a warning like: | ||||||
|
|
||||||
| ``` | ||||||
| [Warning] [MsIdWeb] Authority 'https://login.microsoftonline.com/common' is being ignored | ||||||
| because Instance 'https://login.microsoftonline.com/' and/or TenantId 'contoso.onmicrosoft.com' | ||||||
| are already configured. To use Authority, remove Instance and TenantId from the configuration. | ||||||
| ``` | ||||||
|
|
||||||
| **What it means**: Microsoft.Identity.Web detected conflicting configuration. The `Instance` and `TenantId` properties take precedence, and the `Authority` value is completely ignored. | ||||||
|
|
||||||
| **How to fix**: | ||||||
| 1. **Option 1 (Recommended)**: Remove `Authority` from your configuration, keep `Instance` and `TenantId`. | ||||||
| 2. **Option 2**: Remove both `Instance` and `TenantId`, keep only `Authority`. | ||||||
|
|
||||||
| **Event ID**: 408 (AuthorityConflict) | ||||||
|
|
||||||
| ## Edge Cases and Special Scenarios | ||||||
|
|
||||||
| ### Scheme-less Authority | ||||||
|
|
||||||
| If you provide an authority without the `https://` scheme, you may encounter parsing errors. Always include the full URL: | ||||||
|
|
||||||
| ❌ Wrong: `"Authority": "login.microsoftonline.com/common"` | ||||||
| ✅ Correct: `"Authority": "https://login.microsoftonline.com/common"` | ||||||
|
|
||||||
| ### Trailing Slashes | ||||||
|
|
||||||
| Trailing slashes are automatically normalized. Both forms work identically: | ||||||
| - `https://login.microsoftonline.com/` | ||||||
| - `https://login.microsoftonline.com` | ||||||
|
|
||||||
| ### Query Parameters in Authority | ||||||
|
|
||||||
| Query parameters in the Authority URL are preserved during parsing but generally not recommended. Use `ExtraQueryParameters` configuration option instead. | ||||||
|
|
||||||
| ### Missing v2.0 Endpoint Suffix | ||||||
|
|
||||||
| Microsoft.Identity.Web and MSAL.NET use the v2.0 endpoint by default. You do NOT need to append `/v2.0` to your authority: | ||||||
|
|
||||||
| ❌ Avoid: `https://login.microsoftonline.com/common/v2.0` | ||||||
| ✅ Correct: `https://login.microsoftonline.com/common` | ||||||
|
|
||||||
| ### Custom Domains with CIAM | ||||||
|
|
||||||
| When using custom domains with CIAM, always set `PreserveAuthority: true` to prevent the library from attempting to parse the custom domain URL: | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "AzureAd": { | ||||||
| "Authority": "https://login.contoso.com/", | ||||||
| "ClientId": "11111111-1111-1111-1111-111111111111", | ||||||
| "PreserveAuthority": true | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ## Migration Guidance | ||||||
|
|
||||||
| If you're upgrading from older configurations or mixing authority properties, see the [Migration Guide](migration-authority-vs-instance.md) for detailed upgrade paths. | ||||||
|
|
||||||
| ## Frequently Asked Questions | ||||||
|
|
||||||
| For answers to common configuration questions and troubleshooting tips, see the [Authority Precedence FAQ](faq-authority-precedence.md). | ||||||
|
|
||||||
| ## Additional Resources | ||||||
|
|
||||||
| - [Azure AD B2C Authority Examples](b2c-authority-examples.md) | ||||||
| - [CIAM Authority Examples](ciam-authority-examples.md) | ||||||
| - [Migration Guide: Authority vs Instance/TenantId](migration-authority-vs-instance.md) | ||||||
| - [Microsoft identity platform documentation](https://learn.microsoft.com/azure/active-directory/develop/) | ||||||
| - [Azure AD B2C documentation](https://learn.microsoft.com/azure/active-directory-b2c/) | ||||||
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.