Skip to content

Commit 9331934

Browse files
kllysngjmprieur
andauthored
Bringing token exchange url commit into rel/v2 (#2774)
* Allow token exchange URL configuration (#2767) * initial commit adding configurable token exchange url * Apply suggestions from code review Co-authored-by: Jean-Marc Prieur <[email protected]> * use abstractions 5.2.0 * separate ctor overload * add msi fic support to changelog --------- Co-authored-by: Jean-Marc Prieur <[email protected]> * bring back abstractions 5.2.0! --------- Co-authored-by: Jean-Marc Prieur <[email protected]>
1 parent c99f631 commit 9331934

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<MicrosoftGraphVersion>4.36.0</MicrosoftGraphVersion>
8787
<MicrosoftGraphBetaVersion>4.57.0-preview</MicrosoftGraphBetaVersion>
8888
<MicrosoftExtensionsHttpVersion>3.1.3</MicrosoftExtensionsHttpVersion>
89-
<MicrosoftIdentityAbstractions>5.1.0</MicrosoftIdentityAbstractions>
89+
<MicrosoftIdentityAbstractions>5.2.0</MicrosoftIdentityAbstractions>
9090
</PropertyGroup>
9191

9292
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Pending Next Release
2+
=========
3+
- Update to Microsoft.Identity.Abstractions 5.2.0
4+
5+
### New features
6+
- Added support for Managed Identity Federated Identity Credential. See issue [2749](https://github.com/AzureAD/microsoft-identity-web/issues/2749) for details.
7+
18
2.17.5
29
=========
310
- Updated to MSAL 4.59.1.
@@ -12,7 +19,7 @@
1219
2.17.3
1320
=========
1421
- Updated to Microsoft.IdentityModel.* 7.5.0
15-
22+
1623
2.17.2
1724
=========
1825

src/Microsoft.Identity.Web.Certificate/SignedAssertionFromManagedIdentityCredentialLoader.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Net;
7-
using System.Text;
8-
using Azure.Identity;
94
using System.Threading;
10-
using Microsoft.Identity.Abstractions;
115
using System.Threading.Tasks;
6+
using Azure.Identity;
7+
using Microsoft.Identity.Abstractions;
128

139
namespace Microsoft.Identity.Web
1410
{
@@ -23,7 +19,7 @@ public async Task LoadIfNeededAsync(CredentialDescription credentialDescription,
2319
ManagedIdentityClientAssertion? managedIdentityClientAssertion = credentialDescription.CachedValue as ManagedIdentityClientAssertion;
2420
if (credentialDescription.CachedValue == null)
2521
{
26-
managedIdentityClientAssertion = new ManagedIdentityClientAssertion(credentialDescription.ManagedIdentityClientId);
22+
managedIdentityClientAssertion = new ManagedIdentityClientAssertion(credentialDescription.ManagedIdentityClientId, credentialDescription.TokenExchangeUrl);
2723
}
2824
try
2925
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace Microsoft.Identity.Web.Certificateless
5+
{
6+
internal class CertificatelessConstants
7+
{
8+
// Managed Identity Federated Identity Credential
9+
internal const string DefaultTokenExchangeUrl = "api://AzureADTokenExchange";
10+
}
11+
}

src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Azure.Core;
77
using Azure.Identity;
8+
using Microsoft.Identity.Web.Certificateless;
89

910
namespace Microsoft.Identity.Web
1011
{
@@ -14,6 +15,7 @@ namespace Microsoft.Identity.Web
1415
public class ManagedIdentityClientAssertion : ClientAssertionProviderBase
1516
{
1617
private readonly TokenCredential _credential;
18+
private readonly string _tokenExchangeUrl;
1719

1820
/// <summary>
1921
/// See https://aka.ms/ms-id-web/certificateless.
@@ -34,6 +36,17 @@ public ManagedIdentityClientAssertion(string? managedIdentityClientId)
3436
ExcludeVisualStudioCodeCredential = true,
3537
ExcludeVisualStudioCredential = true
3638
});
39+
_tokenExchangeUrl = CertificatelessConstants.DefaultTokenExchangeUrl;
40+
}
41+
42+
/// <summary>
43+
/// See https://aka.ms/ms-id-web/certificateless.
44+
/// </summary>
45+
/// <param name="managedIdentityClientId">Optional ClientId of the Managed Identity or Workload Identity</param>
46+
/// <param name="tokenExchangeUrl">Optional token exchange resource url. Default value is "api://AzureADTokenExchange/.default".</param>
47+
public ManagedIdentityClientAssertion(string? managedIdentityClientId, string? tokenExchangeUrl) : this (managedIdentityClientId)
48+
{
49+
_tokenExchangeUrl = tokenExchangeUrl ?? CertificatelessConstants.DefaultTokenExchangeUrl;
3750
}
3851

3952
/// <summary>
@@ -44,7 +57,7 @@ public ManagedIdentityClientAssertion(string? managedIdentityClientId)
4457
protected override async Task<ClientAssertion> GetClientAssertion(CancellationToken cancellationToken)
4558
{
4659
var result = await _credential.GetTokenAsync(
47-
new TokenRequestContext(["api://AzureADTokenExchange/.default"], null),
60+
new TokenRequestContext([_tokenExchangeUrl+"./default"], null),
4861
cancellationToken).ConfigureAwait(false);
4962
return new ClientAssertion(result.Token, result.ExpiresOn);
5063
}

0 commit comments

Comments
 (0)