-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial MSI credential implementation (#6464)
* initial MSI credential implementation * removing uneeded TokenResponse class * adding mock msi credential tests * adding mock transport msi credential test * updating System.Text.Json package reference accross all projects * removing comments from errantly commented asserts * upgrading System.Threading.Tasks.Extensions to match version in Azure.Core * fixing datetime / datetime offset discrepency in SecretsTests.cs
- Loading branch information
Showing
20 changed files
with
469 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
33 changes: 33 additions & 0 deletions
33
sdk/identity/Azure.Identity/src/ManagedIdentityCredential.cs
This file contains 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,33 @@ | ||
// 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; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Identity | ||
{ | ||
public class ManagedIdentityCredential : AzureCredential | ||
{ | ||
private string _clientId; | ||
|
||
public ManagedIdentityCredential(string clientId = null, IdentityClientOptions options = null) | ||
: base(options) | ||
{ | ||
_clientId = clientId; | ||
} | ||
|
||
protected override async Task<AccessToken> GetTokenCoreAsync(string[] scopes, CancellationToken cancellationToken = default) | ||
{ | ||
return await this.Client.AuthenticateManagedIdentityAsync(scopes, _clientId, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
protected override AccessToken GetTokenCore(string[] scopes, CancellationToken cancellationToken = default) | ||
{ | ||
return this.Client.AuthenticateManagedIdentity(scopes, _clientId, cancellationToken); | ||
} | ||
} | ||
} |
This file contains 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 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,37 @@ | ||
// 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; | ||
|
||
namespace Azure.Identity | ||
{ | ||
internal static class ScopeUtilities | ||
{ | ||
private const string DefaultSuffix = "/.defualt"; | ||
|
||
|
||
public static string ScopesToResource(string[] scopes) | ||
{ | ||
if (scopes == null) throw new ArgumentNullException(nameof(scopes)); | ||
|
||
if (scopes.Length != 1) throw new ArgumentException("To convert to a resource string the specified array must be exactly length 1", nameof(scopes)); | ||
|
||
if (!scopes[0].EndsWith(DefaultSuffix)) | ||
{ | ||
return scopes[0]; | ||
} | ||
|
||
return scopes[0].Remove(scopes[0].LastIndexOf(DefaultSuffix)); | ||
} | ||
|
||
public static string[] ResourceToScopes(string resource) | ||
{ | ||
return new string[] { resource + "/.default" }; | ||
} | ||
|
||
} | ||
} |
This file contains 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 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 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.