-
Notifications
You must be signed in to change notification settings - Fork 243
Support for Agent User identities #3435
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
Merged
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
d558326
Initial plan
Copilot 1e0698b
Initial analysis and plan for OidcIdpSignedAssertionLoader IConfigura…
Copilot 67ce505
Fix OidcIdpSignedAssertionLoader to use IServiceProvider instead of I…
Copilot 62ef492
Implement high-performance logging and unit tests for OidcIdpSignedAs…
Copilot 7ec62f0
Address PR feedback: improve error message, remove unnecessary files …
Copilot 84f632b
Restore InternalsVisibleTo.cs file for Microsoft.Identity.Web.OidcFIC…
Copilot 59a5f52
Remove accidentally added dotnet-install.sh file
Copilot e505000
Remove DynamicProxyGenAssembly2 InternalsVisibleTo attribute from Oid…
Copilot b36c926
Remove unnecessary InternalsVisibleTo attributes from OidcFIC project
Copilot ec19f7b
Fixing the logger initialization
jmprieur 7601075
Implement attribute-based LoggerMessage for OidcIdpSignedAssertionLoader
Copilot ff8419c
Merge branch 'master' into copilot/fix-3411
jmprieur 92bd1ad
Merge branch 'master' into copilot/fix-3411
jmprieur 24bd420
Simplify logging to use only LoggerMessageAttribute approach and remo…
Copilot ceb2c7e
Merge branch 'master' into copilot/fix-3411
jmprieur 72f0668
First cut
jmprieur 2aaad4d
merge from master
jmprieur 03f45ac
WP
jmprieur a3262ed
Flow attempt
jmprieur 130827b
Prototype
jmprieur 31b2093
Clean-up
jmprieur e52bf58
Improving the tests
jmprieur 38684d2
Change of approach
jmprieur fa5d7b0
Update with cloned options
jmprieur 69f24d0
Fixing the tests
jmprieur 7a43c8a
Simplifying
jmprieur 5161ed0
Simplifying even more
jmprieur 2fe77a7
Adding a test for the cached user
jmprieur 3276501
Merge from master
jmprieur 72b1bc4
Update tests/E2E Tests/AgentApplications/TokenAcquirerFactorySingleto…
jmprieur 81889ff
Update src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs
jmprieur 96e6a45
Update src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs
jmprieur a0cdfec
Addreessing PR feedback
jmprieur 781c0d7
Fixing typo
jmprieur 337677d
Updating tests
jmprieur 84aa4ea
work in progress
jmprieur e7b12a7
Updated code for AUI
jmprieur d3ca549
Cleaning-up the tests.
jmprieur c937f4f
Adressing feedback
jmprieur efe6fe7
removing unused constant
jmprieur 5d9a120
Accelerating the tests, and avoid running them in GitHub actions
jmprieur dad6250
Disabling tests when run in GitHub actionss
jmprieur c49ad28
Disabling Agent E2E tests in GitHub actions
jmprieur d97d5d0
Removing the agents tests in GitHub Actions
jmprieur 5379a51
Update src/Microsoft.Identity.Web.AgentIdentities/AgentIdentitiesExte…
jmprieur dc3ea2b
Renaming (PR review)
jmprieur 450e7b7
Merge branch 'origin/jmprieur/aui2' of https://github.com/AzureAD/mic…
jmprieur 0f669d0
Adrressing PR feedback
jmprieur 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
88 changes: 88 additions & 0 deletions
88
src/Microsoft.Identity.Web.AgentIdentities/AgentUserIdentityMsalAddIn.cs
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,88 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Security.Claims; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Options; | ||
| using Microsoft.Identity.Abstractions; | ||
| using Microsoft.Identity.Client; | ||
| using Microsoft.Identity.Client.Extensibility; | ||
|
|
||
| namespace Microsoft.Identity.Web.AgentIdentities | ||
| { | ||
| internal static class AgentUserIdentityMsalAddIn | ||
| { | ||
| internal static Task OnBeforeUserFicForAgentUserIdentityAsync( | ||
| AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder builder, | ||
| AcquireTokenOptions? options, | ||
| ClaimsPrincipal user) | ||
| { | ||
| if (options == null || options.ExtraParameters == null) | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
| IServiceProvider serviceProvider = (IServiceProvider)options.ExtraParameters![Constants.ExtensionOptionsServiceProviderKey]; | ||
| options.ExtraParameters.TryGetValue(Constants.AgentIdentityKey, out object? agentIdentityObject); | ||
| options.ExtraParameters.TryGetValue(Constants.UsernameKey, out object? usernameObject); | ||
| if (agentIdentityObject is string agentIdentity && usernameObject is string username) | ||
| { | ||
| // Register the MSAL extension that will modify the token request just in time. | ||
| MsalAuthenticationExtension extension = new() | ||
| { | ||
| OnBeforeTokenRequestHandler = async (request) => | ||
| { | ||
| // Get the services from the service provider. | ||
| ITokenAcquirerFactory tokenAcquirerFactory = serviceProvider.GetRequiredService<ITokenAcquirerFactory>(); | ||
| IAuthenticationSchemeInformationProvider authenticationSchemeInformationProvider = | ||
| serviceProvider.GetRequiredService<IAuthenticationSchemeInformationProvider>(); | ||
| IOptionsMonitor<MicrosoftIdentityApplicationOptions> optionsMonitor = | ||
| serviceProvider.GetRequiredService<IOptionsMonitor<MicrosoftIdentityApplicationOptions>>(); | ||
|
|
||
| // Get the FIC token for the agent application. | ||
| string authenticationScheme = authenticationSchemeInformationProvider.GetEffectiveAuthenticationScheme(options.AuthenticationOptionsName); | ||
| ITokenAcquirer tokenAcquirer = tokenAcquirerFactory.GetTokenAcquirer(authenticationScheme); | ||
| ITokenAcquirer agentApplicationTokenAcquirer = tokenAcquirerFactory.GetTokenAcquirer(); | ||
| AcquireTokenResult aaFic = await agentApplicationTokenAcquirer.GetFicTokenAsync(new() { FmiPath = agentIdentity }); // Uses the regular client credentials | ||
| string? clientAssertion = aaFic.AccessToken; | ||
|
|
||
| // Get the FIC token for the agent identity. | ||
| MicrosoftIdentityApplicationOptions microsoftIdentityApplicationOptions = optionsMonitor.Get(authenticationScheme); | ||
| ITokenAcquirer agentIdentityTokenAcquirer = tokenAcquirerFactory.GetTokenAcquirer(new MicrosoftIdentityApplicationOptions | ||
| { | ||
| ClientId = agentIdentity, | ||
| Instance = microsoftIdentityApplicationOptions.Instance, | ||
| Authority = microsoftIdentityApplicationOptions.Authority, | ||
| TenantId = microsoftIdentityApplicationOptions.TenantId | ||
| }); | ||
| AcquireTokenResult aidFic = await agentIdentityTokenAcquirer.GetFicTokenAsync(clientAssertion: clientAssertion); // Uses the agent identity | ||
| string? userFicAssertion = aidFic.AccessToken; | ||
|
|
||
| // Already in the request: | ||
| // - client_id = agentIdentity; | ||
|
|
||
| // User FIC parameters | ||
| request.BodyParameters["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"; | ||
| request.BodyParameters["client_assertion"] = clientAssertion; | ||
| request.BodyParameters["username"] = username; | ||
| request.BodyParameters["user_federated_identity_credential"] = userFicAssertion; | ||
| request.BodyParameters["grant_type"] = "user_fic"; | ||
| request.BodyParameters.Remove("password"); | ||
|
|
||
| if (request.BodyParameters.TryGetValue("client_secret", out var secret) | ||
| && secret.Equals("default", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| request.BodyParameters.Remove("client_secret"); | ||
| } | ||
|
|
||
| // For the moment | ||
| request.RequestUri = new Uri(request.RequestUri + "?slice=first"); | ||
jmprieur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
| builder.WithAuthenticationExtension(extension); | ||
| } | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
| } | ||
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
4 changes: 4 additions & 0 deletions
4
src/Microsoft.Identity.Web.AgentIdentities/PublicAPI/InternalAPI.Unshipped.txt
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 |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| #nullable enable | ||
| Microsoft.Identity.Web.AgentIdentities.AgentUserIdentityMsalAddIn | ||
| Microsoft.Identity.Web.AgentIdentities.AgentUserIdentityMsalAddIn.AgentUserIdentityMsalAddIn() -> void | ||
| static Microsoft.Identity.Web.AgentIdentities.AgentUserIdentityMsalAddIn.OnBeforeUserFicForAgentUserIdentityAsync(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? options, System.Security.Claims.ClaimsPrincipal! user) -> System.Threading.Tasks.Task! | ||
| static Microsoft.Identity.Web.AgentIdentityExtension.ForAgentIdentity(this Microsoft.Identity.Abstractions.AcquireTokenOptions! options, string! agentApplicationId) -> Microsoft.Identity.Abstractions.AcquireTokenOptions! |
1 change: 1 addition & 0 deletions
1
src/Microsoft.Identity.Web.AgentIdentities/PublicAPI/PublicAPI.Unshipped.txt
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| #nullable enable | ||
| static Microsoft.Identity.Web.AgentIdentityExtension.WithAgentUserIdentity(this Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions! options, string! agentApplicationId, string! username) -> Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions! |
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
Oops, something went wrong.
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.