mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
* Make nullable warnings a per file opt-in * Remove unneeded compiler directives * Remove compiler directive for User Data
38 lines
1.6 KiB
C#
38 lines
1.6 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
#nullable disable
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Azure.Core;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Migration.Models
|
|
{
|
|
/// <summary>
|
|
/// Temp token creadentials to interact with ArmClient class.
|
|
/// The token passed to this class should be a newly request token, because this class doesn't renew the token.
|
|
/// Once MSAL is rolled out on ADS, we will implement a way to use the same ADS token cache configured by ADS.
|
|
/// </summary>
|
|
internal class StaticTokenCredential : TokenCredential
|
|
{
|
|
private readonly AccessToken _token;
|
|
|
|
/// <summary>
|
|
/// Build credentials using a token that will not change.
|
|
/// </summary>
|
|
/// <param name="accessToken">Newly created token that should last for the duration of the whole operation.</param>
|
|
public StaticTokenCredential(string accessToken) => _token = new AccessToken(
|
|
accessToken: accessToken,
|
|
expiresOn: DateTimeOffset.Now.AddHours(1)); //Default to an hour, the current duration of a newly create token.
|
|
|
|
public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
|
|
=> _token;
|
|
|
|
public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
|
|
=> new ValueTask<AccessToken>(_token);
|
|
}
|
|
}
|