You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
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<TokenResponse> 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<string>()
|
|
{ ScopeConstants.ScopeMigrationAPI, ScopeConstants.ScopeNotificationsAPI };
|
|
|
|
var client = new LWAClient(lwaCredentials, credentials.ProxyAddress);
|
|
var accessToken = await client.GetAccessTokenAsync(cancellationToken);
|
|
|
|
return accessToken;
|
|
}
|
|
}
|
|
} |