using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Amazon.SellingPartnerApiSDK.AmazonSpApiSDK.Models.Token; using Amazon.SellingPartnerApiSDK.AmazonSpApiSDK.Runtime; using Amazon.SellingPartnerApiSDK.Misc; namespace Amazon.SellingPartnerApiSDK.Services { public static class TokenGeneration { public static async Task RefreshAccessTokenAsync(AmazonCredential credentials, CacheTokenData.TokenDataType tokenDataType = CacheTokenData.TokenDataType.Normal, CancellationToken cancellationToken = default) { var lwaCredentials = new LWAAuthorizationCredentials() { ClientId = credentials.ClientId, ClientSecret = credentials.ClientSecret, Endpoint = new Uri(Constants.AmazonTokenEndPoint), RefreshToken = credentials.RefreshToken, Scopes = null }; if (tokenDataType == CacheTokenData.TokenDataType.Grantless) lwaCredentials.Scopes = new List() { ScopeConstants.ScopeMigrationAPI, ScopeConstants.ScopeNotificationsAPI }; var client = new LWAClient(lwaCredentials, credentials.ProxyAddress); var accessToken = await client.GetAccessTokenAsync(cancellationToken); return accessToken; } } }