Skip to content

Commit 8f6ca16

Browse files
jmprieurjennyf19
andauthored
Add support for Agent Identities. (#3396) (#3402)
* Add support for Agent Identities. (#3396) * Adding the Microsoft.Idenitty.Web.AgentIdentities package * Improving the unit tests for OidcFic for the SignedAssertionFmiPath * Fix flay test Co-authored-by: jennyf19 <[email protected]> * Addressing PR feedback * Fixing the build action (the test are not needed for all frameworks) * Update Directory.Build.props --------- Co-authored-by: jennyf19 <[email protected]>
1 parent a4e3864 commit 8f6ca16

28 files changed

+409
-30
lines changed

.github/workflows/dotnetcore.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ jobs:
4343
run: msbuild Microsoft.Identity.Web.sln -r -t:build -verbosity:m -property:Configuration=Release
4444

4545
- name: Test with .NET 8.0.x
46-
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net8.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --collect "Xplat Code Coverage" --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
46+
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net8.0 -v m -p:FROM_GITHUB_ACTION=true --configuration Release --collect "Xplat Code Coverage" --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
4747

4848
- name: Test with .NET 9.0.x
49-
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net9.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --collect "Xplat Code Coverage" --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
49+
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net9.0 -v m -p:FROM_GITHUB_ACTION=true --configuration Release --collect "Xplat Code Coverage" --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
5050

5151
- name: Test with .NET 6.0.x
52-
run: dotnet test Microsoft.Identity.Web.sln -f net6.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
52+
run: dotnet test Microsoft.Identity.Web.sln -f net6.0 -v m -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)&(FullyQualifiedName!~AgentApplicationsTests)"
5353

5454
- name: Create code coverage report
5555
run: |
@@ -77,10 +77,7 @@ jobs:
7777
# })
7878

7979
- name: Test with .NET 462
80-
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net462 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)"
80+
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net462 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~AgentApplicationsTests)"
8181

8282
- name: Test with .NET 472
83-
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net472 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)"
84-
85-
- name: Test with .NET Standard 2.0
86-
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f netstandard2.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)"
83+
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net472 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~AgentApplicationsTests)"

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<!--This should be passed from the VSTS build-->
44
<!-- This needs to be greater than or equal to the validation baseline version -->
5-
<MicrosoftIdentityWebVersion Condition="'$(MicrosoftIdentityWebVersion)' == ''">3.9.4</MicrosoftIdentityWebVersion>
5+
<MicrosoftIdentityWebVersion Condition="'$(MicrosoftIdentityWebVersion)' == ''">3.10.0</MicrosoftIdentityWebVersion>
66
<!--This will generate AssemblyVersion, AssemblyFileVersion and AssemblyInformationVersion-->
77
<Version>$(MicrosoftIdentityWebVersion)</Version>
88

Microsoft.Identity.Web.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Identity.Web.Oidc
164164
EndProject
165165
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Identity.Web.UI.Test", "tests\Microsoft.Identity.Web.UI.Test\Microsoft.Identity.Web.UI.Test.csproj", "{CF31F33A-E5F5-DB57-4FEF-81BDAFD497C8}"
166166
EndProject
167+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgentApplicationsTests", "tests\E2E Tests\AgentApplications\AgentApplicationsTests.csproj", "{DD56CDF7-E6B3-4304-B8DF-3AC610C35623}"
168+
EndProject
169+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Identity.Web.AgentIdentities", "src\Microsoft.Identity.Web.AgentIdentities\Microsoft.Identity.Web.AgentIdentities.csproj", "{C14780ED-5756-2A09-C6A7-5DDA433D1E86}"
170+
EndProject
167171
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "daemon-app-msi", "tests\DevApps\daemon-app\daemon-app-msi\daemon-app-msi.csproj", "{A8181404-23E0-D38B-454C-D16ECDB18B9F}"
168172
EndProject
169173
Global
@@ -389,6 +393,14 @@ Global
389393
{CF31F33A-E5F5-DB57-4FEF-81BDAFD497C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
390394
{CF31F33A-E5F5-DB57-4FEF-81BDAFD497C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
391395
{CF31F33A-E5F5-DB57-4FEF-81BDAFD497C8}.Release|Any CPU.Build.0 = Release|Any CPU
396+
{DD56CDF7-E6B3-4304-B8DF-3AC610C35623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
397+
{DD56CDF7-E6B3-4304-B8DF-3AC610C35623}.Debug|Any CPU.Build.0 = Debug|Any CPU
398+
{DD56CDF7-E6B3-4304-B8DF-3AC610C35623}.Release|Any CPU.ActiveCfg = Release|Any CPU
399+
{DD56CDF7-E6B3-4304-B8DF-3AC610C35623}.Release|Any CPU.Build.0 = Release|Any CPU
400+
{C14780ED-5756-2A09-C6A7-5DDA433D1E86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
401+
{C14780ED-5756-2A09-C6A7-5DDA433D1E86}.Debug|Any CPU.Build.0 = Debug|Any CPU
402+
{C14780ED-5756-2A09-C6A7-5DDA433D1E86}.Release|Any CPU.ActiveCfg = Release|Any CPU
403+
{C14780ED-5756-2A09-C6A7-5DDA433D1E86}.Release|Any CPU.Build.0 = Release|Any CPU
392404
{A8181404-23E0-D38B-454C-D16ECDB18B9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
393405
{A8181404-23E0-D38B-454C-D16ECDB18B9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
394406
{A8181404-23E0-D38B-454C-D16ECDB18B9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -467,6 +479,8 @@ Global
467479
{E927D215-A96C-626C-9A1A-CF99876FE7B4} = {45B20A78-91F8-4DD2-B9AD-F12D3A93536C}
468480
{8DA7A2C6-00D4-4CF1-8145-448D7B7B4E5A} = {1DDE1AAC-5AE6-4725-94B6-A26C58D3423F}
469481
{CF31F33A-E5F5-DB57-4FEF-81BDAFD497C8} = {B4E72F1C-603F-437C-AAA1-153A604CD34A}
482+
{DD56CDF7-E6B3-4304-B8DF-3AC610C35623} = {45B20A78-91F8-4DD2-B9AD-F12D3A93536C}
483+
{C14780ED-5756-2A09-C6A7-5DDA433D1E86} = {1DDE1AAC-5AE6-4725-94B6-A26C58D3423F}
470484
{A8181404-23E0-D38B-454C-D16ECDB18B9F} = {E37CDBC1-18F6-4C06-A3EE-532C9106721F}
471485
EndGlobalSection
472486
GlobalSection(ExtensibilityGlobals) = postSolution
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Identity.Abstractions;
11+
12+
namespace Microsoft.Identity.Web
13+
{
14+
/// <summary>
15+
/// Extensions methods to enable agent identities in Microsoft.Identity.Web.
16+
/// </summary>
17+
public static class AgentIdentityExtension
18+
{
19+
/// <summary>
20+
/// Enable support for agent identities.
21+
/// </summary>
22+
/// <param name="services">Service collection</param>
23+
/// <returns>The service collection for chaining.</returns>
24+
public static IServiceCollection AddAgentIdentities(this IServiceCollection services)
25+
{
26+
Throws.IfNull(services);
27+
28+
// Register the OidcFic services for agent applications to work.
29+
services.AddOidcFic();
30+
31+
return services;
32+
}
33+
34+
35+
/// <summary>
36+
/// Updates the options to acquire a token for the agent identity.
37+
/// </summary>
38+
/// <param name="options">Authorization header provider options.</param>
39+
/// <param name="agentApplicationId">The agent identity GUID.</param>
40+
/// <returns>The updated authorization header provider options.</returns>
41+
public static AuthorizationHeaderProviderOptions WithAgentIdentity(this AuthorizationHeaderProviderOptions options, string agentApplicationId)
42+
{
43+
// It's possible to start with no options, so we initialize it if it's null.
44+
if (options == null)
45+
options = new AuthorizationHeaderProviderOptions();
46+
47+
// AcquireTokenOptions holds the information needed to acquire a token for the Agent Identity
48+
options.AcquireTokenOptions ??= new AcquireTokenOptions();
49+
options.AcquireTokenOptions.ForAgentIdentity(agentApplicationId);
50+
51+
return options;
52+
}
53+
54+
// TODO:make public?
55+
private static AcquireTokenOptions ForAgentIdentity(this AcquireTokenOptions options, string agentApplicationId)
56+
{
57+
options.ExtraParameters ??= new Dictionary<string, object>();
58+
59+
// Until it makes it way through Abstractions
60+
options.ExtraParameters["fmiPathForClientAssertion"] = agentApplicationId;
61+
62+
// TODO: do we want to expose a mechanism to override the MicrosoftIdentityOptions instead of leveraging
63+
// the default configuration section / named options?.
64+
options.ExtraParameters["MicrosoftIdentityOptions"] = new MicrosoftEntraApplicationOptions
65+
{
66+
ClientId = agentApplicationId, // Agent identity Client ID.
67+
ClientCredentials = [ new CredentialDescription() {
68+
SourceType = CredentialSource.CustomSignedAssertion,
69+
CustomSignedAssertionProviderName = "OidcIdpSignedAssertion",
70+
CustomSignedAssertionProviderData = new Dictionary<string, object> {
71+
{ "ConfigurationSection", "AzureAd" }, // Use the default configuration section name
72+
{ "RequiresSignedAssertionFmiPath", true }, // The OidcIdpSignedAssertionProvider will require the fmiPath to be provided in the assertionRequestOptions.
73+
}
74+
}]
75+
};
76+
return options;
77+
}
78+
}
79+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
4+
<Title>Microsoft Identity Web Agentic Identity support</Title>
5+
<Product>Microsoft Identity Web for Agent Identities</Product>
6+
<Description>Helper methods for Agent applications to act as the agent identities.</Description>
7+
<PackageReadmeFile>README.md</PackageReadmeFile>
8+
9+
<!-- The package is new in 3.10.0.-->
10+
<PackageValidationBaselineVersion>3.10.0</PackageValidationBaselineVersion>
11+
<EnablePackageValidation>false</EnablePackageValidation>
12+
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<None Include="..\..\README.md">
17+
<Pack>True</Pack>
18+
<PackagePath>\</PackagePath>
19+
</None>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" />
24+
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" />
25+
<AdditionalFiles Include="PublicAPI\InternalAPI.Shipped.txt" />
26+
<AdditionalFiles Include="PublicAPI\InternalAPI.Unshipped.txt" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\Microsoft.Identity.Web.Diagnostics\Microsoft.Identity.Web.Diagnostics.csproj" />
31+
<ProjectReference Include="..\Microsoft.Identity.Web.OidcFIC\Microsoft.Identity.Web.OidcFIC.csproj" />
32+
<ProjectReference Include="..\Microsoft.Identity.Web.TokenAcquisition\Microsoft.Identity.Web.TokenAcquisition.csproj" />
33+
</ItemGroup>
34+
35+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#nullable enable
2+
Microsoft.Identity.Web.AgentIdentityExtension
3+
static Microsoft.Identity.Web.AgentIdentityExtension.AddAgentIdentities(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
4+
static Microsoft.Identity.Web.AgentIdentityExtension.WithAgentIdentity(this Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions! options, string! agentApplicationId) -> Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions!

src/Microsoft.Identity.Web.Diagnostics/Properties/InternalsVisibleTo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// Allow this assembly to be serviced when run on desktop CLR
77
[assembly: InternalsVisibleTo("Microsoft.Identity.Web, PublicKey=00240000048000009400000006020000002400005253413100040000010001002D96616729B54F6D013D71559A017F50AA4861487226C523959D1579B93F3FDF71C08B980FD3130062B03D3DE115C4B84E7AC46AEF5E192A40E7457D5F3A08F66CEAB71143807F2C3CB0DA5E23B38F0559769978406F6E5D30CEADD7985FC73A5A609A8B74A1DF0A29399074A003A226C943D480FEC96DBEC7106A87896539AD")]
8+
[assembly: InternalsVisibleTo("Microsoft.Identity.Web.AgentIdentities, PublicKey=00240000048000009400000006020000002400005253413100040000010001002D96616729B54F6D013D71559A017F50AA4861487226C523959D1579B93F3FDF71C08B980FD3130062B03D3DE115C4B84E7AC46AEF5E192A40E7457D5F3A08F66CEAB71143807F2C3CB0DA5E23B38F0559769978406F6E5D30CEADD7985FC73A5A609A8B74A1DF0A29399074A003A226C943D480FEC96DBEC7106A87896539AD")]
89
[assembly: InternalsVisibleTo("Microsoft.Identity.Web.Certificate, PublicKey=00240000048000009400000006020000002400005253413100040000010001002D96616729B54F6D013D71559A017F50AA4861487226C523959D1579B93F3FDF71C08B980FD3130062B03D3DE115C4B84E7AC46AEF5E192A40E7457D5F3A08F66CEAB71143807F2C3CB0DA5E23B38F0559769978406F6E5D30CEADD7985FC73A5A609A8B74A1DF0A29399074A003A226C943D480FEC96DBEC7106A87896539AD")]
910
[assembly: InternalsVisibleTo("Microsoft.Identity.Web.CertificateLess, PublicKey=00240000048000009400000006020000002400005253413100040000010001002D96616729B54F6D013D71559A017F50AA4861487226C523959D1579B93F3FDF71C08B980FD3130062B03D3DE115C4B84E7AC46AEF5E192A40E7457D5F3A08F66CEAB71143807F2C3CB0DA5E23B38F0559769978406F6E5D30CEADD7985FC73A5A609A8B74A1DF0A29399074A003A226C943D480FEC96DBEC7106A87896539AD")]
1011
[assembly: InternalsVisibleTo("Microsoft.Identity.Web.DownstreamApi, PublicKey=00240000048000009400000006020000002400005253413100040000010001002D96616729B54F6D013D71559A017F50AA4861487226C523959D1579B93F3FDF71C08B980FD3130062B03D3DE115C4B84E7AC46AEF5E192A40E7457D5F3A08F66CEAB71143807F2C3CB0DA5E23B38F0559769978406F6E5D30CEADD7985FC73A5A609A8B74A1DF0A29399074A003A226C943D480FEC96DBEC7106A87896539AD")]

0 commit comments

Comments
 (0)