// // 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.Migration.Models { /// /// 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. /// internal class StaticTokenCredential : TokenCredential { private readonly AccessToken _token; /// /// Build credentials using a token that will not change. /// /// Newly created token that should last for the duration of the whole operation. 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 GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) => new ValueTask(_token); } }