Skip to content
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

Allow token exchange URL configuration #2767

Merged
merged 7 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<MicrosoftGraphVersion>4.36.0</MicrosoftGraphVersion>
<MicrosoftGraphBetaVersion>4.57.0-preview</MicrosoftGraphBetaVersion>
<MicrosoftExtensionsHttpVersion>3.1.3</MicrosoftExtensionsHttpVersion>
<MicrosoftIdentityAbstractions>5.1.0</MicrosoftIdentityAbstractions>
<MicrosoftIdentityAbstractions>5.2.0</MicrosoftIdentityAbstractions>
<NetNineRuntimeVersion> 9.0.0-preview.2.24128.5</NetNineRuntimeVersion>
<AspNetCoreNineRuntimeVersion> 9.0.0-preview.2.24128.4</AspNetCoreNineRuntimeVersion>
</PropertyGroup>
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Pending Next Release
=========
- Update to Microsoft.Identity.Abstractions 5.2.0
kellyyangsong marked this conversation as resolved.
Show resolved Hide resolved

### New features
- Added support for Managed Identity Federated Identity Credential. See issue [2749](https://github.com/AzureAD/microsoft-identity-web/issues/2749) for details.

2.17.2
=========

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Azure.Identity;
using System.Threading;
using Microsoft.Identity.Abstractions;
using System.Threading.Tasks;
using Azure.Identity;
using Microsoft.Identity.Abstractions;

namespace Microsoft.Identity.Web
{
Expand All @@ -23,7 +19,7 @@ public async Task LoadIfNeededAsync(CredentialDescription credentialDescription,
ManagedIdentityClientAssertion? managedIdentityClientAssertion = credentialDescription.CachedValue as ManagedIdentityClientAssertion;
kellyyangsong marked this conversation as resolved.
Show resolved Hide resolved
if (credentialDescription.CachedValue == null)
{
managedIdentityClientAssertion = new ManagedIdentityClientAssertion(credentialDescription.ManagedIdentityClientId);
managedIdentityClientAssertion = new ManagedIdentityClientAssertion(credentialDescription.ManagedIdentityClientId, credentialDescription.TokenExchangeUrl);
}
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Identity.Web.Certificateless
{
internal class CertificatelessConstants
{
// Managed Identity Federated Identity Credential
internal const string DefaultTokenExchangeUrl = "api://AzureADTokenExchange";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Microsoft.Identity.Web.Certificateless;

namespace Microsoft.Identity.Web
{
Expand All @@ -14,6 +15,7 @@ namespace Microsoft.Identity.Web
public class ManagedIdentityClientAssertion : ClientAssertionProviderBase
{
private readonly TokenCredential _credential;
private readonly string _tokenExchangeUrl;

/// <summary>
/// See https://aka.ms/ms-id-web/certificateless.
Expand All @@ -34,6 +36,17 @@ public ManagedIdentityClientAssertion(string? managedIdentityClientId)
ExcludeVisualStudioCodeCredential = true,
ExcludeVisualStudioCredential = true
});
_tokenExchangeUrl = CertificatelessConstants.DefaultTokenExchangeUrl;
}

/// <summary>
/// See https://aka.ms/ms-id-web/certificateless.
/// </summary>
/// <param name="managedIdentityClientId">Optional ClientId of the Managed Identity or Workload Identity</param>
/// <param name="tokenExchangeUrl">Optional token exchange resource url. Default value is "api://AzureADTokenExchange/.default".</param>
public ManagedIdentityClientAssertion(string? managedIdentityClientId, string? tokenExchangeUrl) : this (managedIdentityClientId)
{
_tokenExchangeUrl = tokenExchangeUrl ?? CertificatelessConstants.DefaultTokenExchangeUrl;
kellyyangsong marked this conversation as resolved.
Show resolved Hide resolved
}

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