-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blob: Add TokenCredential auth (#98)
- Loading branch information
Showing
5 changed files
with
98 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Azure.Core; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System; | ||
|
||
namespace Microsoft.MSBuildCache.AzureBlobStorage; | ||
|
||
internal sealed class StaticTokenCredential : TokenCredential | ||
{ | ||
private readonly string _accessToken; | ||
|
||
public StaticTokenCredential(string accessToken) | ||
{ | ||
_accessToken = accessToken; | ||
} | ||
|
||
public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
// The token is static and we don't know the expiry, so just say it's a day from now. | ||
=> new AccessToken(_accessToken, DateTimeOffset.Now.AddDays(1)); | ||
|
||
public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
=> new ValueTask<AccessToken>(GetToken(requestContext, cancellationToken)); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/AzureBlobStorage/TokenCredentialAzureStorageCredentials.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,19 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using Azure.Core; | ||
using BuildXL.Cache.ContentStore.Interfaces.Auth; | ||
|
||
namespace Microsoft.MSBuildCache.AzureBlobStorage; | ||
|
||
internal sealed class TokenCredentialAzureStorageCredentials : AzureStorageCredentialsBase | ||
{ | ||
public TokenCredentialAzureStorageCredentials(Uri blobUri, TokenCredential tokenCredential) | ||
: base(blobUri) | ||
{ | ||
Credentials = tokenCredential; | ||
} | ||
|
||
protected override TokenCredential Credentials { get; } | ||
} |