-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented client certificate auth, closes #16, version bump
- Loading branch information
1 parent
561f597
commit a1e45c4
Showing
8 changed files
with
213 additions
and
6 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
64 changes: 64 additions & 0 deletions
64
source/AzAuth.Core/TokenManagerAuthMethods/TokenManager.ClientCertificate.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,64 @@ | ||
using Azure.Core; | ||
using Azure.Identity; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace PipeHow.AzAuth; | ||
|
||
internal static partial class TokenManager | ||
{ | ||
/// <summary> | ||
/// Gets token with a client certificate. | ||
/// </summary> | ||
internal static AzToken GetTokenClientCertificate(string resource, string[] scopes, string? claims, string clientId, string tenantId, X509Certificate2 clientCertificate, CancellationToken cancellationToken) => | ||
taskFactory.Run(() => GetTokenClientCertificateAsync(resource, scopes, claims, clientId, tenantId, clientCertificate, cancellationToken)); | ||
|
||
/// <summary> | ||
/// Gets token with a client certificate from a file path. | ||
/// </summary> | ||
internal static AzToken GetTokenClientCertificate(string resource, string[] scopes, string? claims, string clientId, string tenantId, string clientCertificatePath, CancellationToken cancellationToken) => | ||
taskFactory.Run(() => GetTokenClientCertificateAsync(resource, scopes, claims, clientId, tenantId, clientCertificatePath, cancellationToken)); | ||
|
||
/// <summary> | ||
/// Gets token with a client certificate. | ||
/// </summary> | ||
internal static async Task<AzToken> GetTokenClientCertificateAsync( | ||
string resource, | ||
string[] scopes, | ||
string? claims, | ||
string clientId, | ||
string tenantId, | ||
X509Certificate2 clientCertificate, | ||
CancellationToken cancellationToken) | ||
{ | ||
var fullScopes = scopes.Select(s => $"{resource.TrimEnd('/')}/{s}").ToArray(); | ||
var tokenRequestContext = new TokenRequestContext(fullScopes, null, claims, tenantId); | ||
|
||
credential = new ClientCertificateCredential(tenantId, clientId, clientCertificate); | ||
|
||
previousClientId = clientId; | ||
|
||
return await GetTokenAsync(tokenRequestContext, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Gets token with a client certificate from a file path. | ||
/// </summary> | ||
internal static async Task<AzToken> GetTokenClientCertificateAsync( | ||
string resource, | ||
string[] scopes, | ||
string? claims, | ||
string clientId, | ||
string tenantId, | ||
string clientCertificatePath, | ||
CancellationToken cancellationToken) | ||
{ | ||
var fullScopes = scopes.Select(s => $"{resource.TrimEnd('/')}/{s}").ToArray(); | ||
var tokenRequestContext = new TokenRequestContext(fullScopes, null, claims, tenantId); | ||
|
||
credential = new ClientCertificateCredential(tenantId, clientId, clientCertificatePath); | ||
|
||
previousClientId = clientId; | ||
|
||
return await GetTokenAsync(tokenRequestContext, 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
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.