Skip to content

Commit

Permalink
Drop Azure.Identity and use just MSAL here.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgavrilMS committed Jun 14, 2024
1 parent 97244dc commit 80af527
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Azure.Core;

Check failure on line 6 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / IdWeb GitHub Action Test

The type or namespace name 'Azure' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / Analyse

The type or namespace name 'Azure' could not be found (are you missing a using directive or an assembly reference?)
using Azure.Identity;

Check failure on line 7 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / IdWeb GitHub Action Test

The type or namespace name 'Azure' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 7 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / Analyse

The type or namespace name 'Azure' could not be found (are you missing a using directive or an assembly reference?)
using Microsoft.Identity.Client;

Check failure on line 8 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / IdWeb GitHub Action Test

The type or namespace name 'Client' does not exist in the namespace 'Microsoft.Identity' (are you missing an assembly reference?)

Check failure on line 8 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / Analyse

The type or namespace name 'Client' does not exist in the namespace 'Microsoft.Identity' (are you missing an assembly reference?)
using Microsoft.Identity.Client.AppConfig;

Check failure on line 9 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / IdWeb GitHub Action Test

The type or namespace name 'Client' does not exist in the namespace 'Microsoft.Identity' (are you missing an assembly reference?)

Check failure on line 9 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / Analyse

The type or namespace name 'Client' does not exist in the namespace 'Microsoft.Identity' (are you missing an assembly reference?)
using Microsoft.Identity.Web.Certificateless;

namespace Microsoft.Identity.Web
Expand All @@ -15,7 +16,7 @@ namespace Microsoft.Identity.Web
/// </summary>
public class ManagedIdentityClientAssertion : ClientAssertionProviderBase
{
private readonly TokenCredential _credential;
IManagedIdentityApplication _managedIdentityApplication;

Check failure on line 19 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / IdWeb GitHub Action Test

The type or namespace name 'IManagedIdentityApplication' could not be found (are you missing a using directive or an assembly reference?)
private readonly string _tokenExchangeUrl;

/// <summary>
Expand All @@ -24,15 +25,23 @@ public class ManagedIdentityClientAssertion : ClientAssertionProviderBase
/// <param name="managedIdentityClientId">Optional ClientId of the Managed Identity</param>
public ManagedIdentityClientAssertion(string? managedIdentityClientId)
{
_credential = new ManagedIdentityCredential(managedIdentityClientId);
ManagedIdentityId id = ManagedIdentityId.SystemAssigned;
if (!string.IsNullOrEmpty(managedIdentityClientId))
{
id = ManagedIdentityId.WithUserAssignedClientId(managedIdentityClientId);
}

_managedIdentityApplication = ManagedIdentityApplicationBuilder.Create(id).Build();


_tokenExchangeUrl = CertificatelessConstants.DefaultTokenExchangeUrl;
}

/// <summary>
/// See https://aka.ms/ms-id-web/certificateless.
/// </summary>
/// <param name="managedIdentityClientId">Optional ClientId of the Managed Identity</param>
/// <param name="tokenExchangeUrl">Optional audience of the token to be requested from Managed Identity. Default value is "api://AzureADTokenExchange/.default". This value is different on other clouds.</param>
/// <param name="tokenExchangeUrl">Optional audience of the token to be requested from Managed Identity. Default value is "api://AzureADTokenExchange". This value is different on other clouds.</param>
public ManagedIdentityClientAssertion(string? managedIdentityClientId, string? tokenExchangeUrl) : this (managedIdentityClientId)
{
_tokenExchangeUrl = tokenExchangeUrl ?? CertificatelessConstants.DefaultTokenExchangeUrl;
Expand All @@ -45,11 +54,12 @@ public ManagedIdentityClientAssertion(string? managedIdentityClientId, string? t
/// <returns>The signed assertion.</returns>
protected override async Task<ClientAssertion> GetClientAssertionAsync(AssertionRequestOptions? assertionRequestOptions)

Check failure on line 55 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / IdWeb GitHub Action Test

The type or namespace name 'AssertionRequestOptions' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 55 in src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

View workflow job for this annotation

GitHub Actions / Analyse

The type or namespace name 'AssertionRequestOptions' could not be found (are you missing a using directive or an assembly reference?)
{
var result = await _credential.GetTokenAsync(
new TokenRequestContext([_tokenExchangeUrl], null),
assertionRequestOptions?.CancellationToken ?? default).ConfigureAwait(false);
var result = await _managedIdentityApplication
.AcquireTokenForManagedIdentity(_tokenExchangeUrl)
.ExecuteAsync(assertionRequestOptions?.CancellationToken ?? CancellationToken.None)
.ConfigureAwait(false);

return new ClientAssertion(result.Token, result.ExpiresOn);
return new ClientAssertion(result.AccessToken, result.ExpiresOn);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="$(AzureIdentityVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWebVersion)" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens " Version="$(IdentityModelVersion)" />
Expand Down

0 comments on commit 80af527

Please sign in to comment.