-
Notifications
You must be signed in to change notification settings - Fork 235
Add support for Agent Identities. (#3396) #3402
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 all commits
Commits
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
79 changes: 79 additions & 0 deletions
79
src/Microsoft.Identity.Web.AgentIdentities/AgentIdentitiesExtension.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,79 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Identity.Abstractions; | ||
|
||
namespace Microsoft.Identity.Web | ||
{ | ||
/// <summary> | ||
/// Extensions methods to enable agent identities in Microsoft.Identity.Web. | ||
/// </summary> | ||
public static class AgentIdentityExtension | ||
{ | ||
/// <summary> | ||
/// Enable support for agent identities. | ||
/// </summary> | ||
/// <param name="services">Service collection</param> | ||
/// <returns>The service collection for chaining.</returns> | ||
public static IServiceCollection AddAgentIdentities(this IServiceCollection services) | ||
{ | ||
Throws.IfNull(services); | ||
|
||
// Register the OidcFic services for agent applications to work. | ||
services.AddOidcFic(); | ||
|
||
return services; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Updates the options to acquire a token for the agent identity. | ||
/// </summary> | ||
/// <param name="options">Authorization header provider options.</param> | ||
/// <param name="agentApplicationId">The agent identity GUID.</param> | ||
/// <returns>The updated authorization header provider options.</returns> | ||
public static AuthorizationHeaderProviderOptions WithAgentIdentity(this AuthorizationHeaderProviderOptions options, string agentApplicationId) | ||
{ | ||
// It's possible to start with no options, so we initialize it if it's null. | ||
if (options == null) | ||
options = new AuthorizationHeaderProviderOptions(); | ||
|
||
// AcquireTokenOptions holds the information needed to acquire a token for the Agent Identity | ||
options.AcquireTokenOptions ??= new AcquireTokenOptions(); | ||
options.AcquireTokenOptions.ForAgentIdentity(agentApplicationId); | ||
|
||
return options; | ||
} | ||
|
||
// TODO:make public? | ||
private static AcquireTokenOptions ForAgentIdentity(this AcquireTokenOptions options, string agentApplicationId) | ||
{ | ||
options.ExtraParameters ??= new Dictionary<string, object>(); | ||
|
||
// Until it makes it way through Abstractions | ||
options.ExtraParameters["fmiPathForClientAssertion"] = agentApplicationId; | ||
|
||
// TODO: do we want to expose a mechanism to override the MicrosoftIdentityOptions instead of leveraging | ||
// the default configuration section / named options?. | ||
options.ExtraParameters["MicrosoftIdentityOptions"] = new MicrosoftEntraApplicationOptions | ||
{ | ||
ClientId = agentApplicationId, // Agent identity Client ID. | ||
ClientCredentials = [ new CredentialDescription() { | ||
SourceType = CredentialSource.CustomSignedAssertion, | ||
CustomSignedAssertionProviderName = "OidcIdpSignedAssertion", | ||
CustomSignedAssertionProviderData = new Dictionary<string, object> { | ||
{ "ConfigurationSection", "AzureAd" }, // Use the default configuration section name | ||
{ "RequiresSignedAssertionFmiPath", true }, // The OidcIdpSignedAssertionProvider will require the fmiPath to be provided in the assertionRequestOptions. | ||
} | ||
}] | ||
}; | ||
return options; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Microsoft.Identity.Web.AgentIdentities/Microsoft.Identity.Web.AgentIdentities.csproj
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,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
|
||
<Title>Microsoft Identity Web Agentic Identity support</Title> | ||
<Product>Microsoft Identity Web for Agent Identities</Product> | ||
<Description>Helper methods for Agent applications to act as the agent identities.</Description> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
|
||
<!-- The package is new in 3.10.0.--> | ||
<PackageValidationBaselineVersion>3.10.0</PackageValidationBaselineVersion> | ||
<EnablePackageValidation>false</EnablePackageValidation> | ||
jmprieur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" /> | ||
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" /> | ||
<AdditionalFiles Include="PublicAPI\InternalAPI.Shipped.txt" /> | ||
<AdditionalFiles Include="PublicAPI\InternalAPI.Unshipped.txt" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.Identity.Web.Diagnostics\Microsoft.Identity.Web.Diagnostics.csproj" /> | ||
<ProjectReference Include="..\Microsoft.Identity.Web.OidcFIC\Microsoft.Identity.Web.OidcFIC.csproj" /> | ||
<ProjectReference Include="..\Microsoft.Identity.Web.TokenAcquisition\Microsoft.Identity.Web.TokenAcquisition.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
src/Microsoft.Identity.Web.AgentIdentities/PublicAPI/InternalAPI.Shipped.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
1 change: 1 addition & 0 deletions
1
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
1 change: 1 addition & 0 deletions
1
src/Microsoft.Identity.Web.AgentIdentities/PublicAPI/PublicAPI.Shipped.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
4 changes: 4 additions & 0 deletions
4
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#nullable enable | ||
Microsoft.Identity.Web.AgentIdentityExtension | ||
static Microsoft.Identity.Web.AgentIdentityExtension.AddAgentIdentities(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! | ||
static Microsoft.Identity.Web.AgentIdentityExtension.WithAgentIdentity(this Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions! options, string! agentApplicationId) -> 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
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.