示例#1
0
        public static Task <PKCETokenResponse> RequestToken(PKCETokenRefreshRequest request, IAPIConnector apiConnector)
        {
            Ensure.ArgumentNotNull(request, nameof(request));
            Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector));

            var form = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("client_id", request.ClientId),
                new KeyValuePair <string, string>("grant_type", "refresh_token"),
                new KeyValuePair <string, string>("refresh_token", request.RefreshToken),
            };

            return(SendOAuthRequest <PKCETokenResponse>(apiConnector, form, null, null));
        }
        public async Task Apply(IRequest request, IAPIConnector apiConnector)
        {
            Ensure.ArgumentNotNull(request, nameof(request));

            if (InitialToken.IsExpired)
            {
                var tokenRequest   = new PKCETokenRefreshRequest(ClientId, InitialToken.RefreshToken);
                var refreshedToken = await OAuthClient.RequestToken(tokenRequest, apiConnector).ConfigureAwait(false);

                InitialToken.AccessToken  = refreshedToken.AccessToken;
                InitialToken.CreatedAt    = refreshedToken.CreatedAt;
                InitialToken.ExpiresIn    = refreshedToken.ExpiresIn;
                InitialToken.Scope        = refreshedToken.Scope;
                InitialToken.TokenType    = refreshedToken.TokenType;
                InitialToken.RefreshToken = refreshedToken.RefreshToken;

                TokenRefreshed?.Invoke(this, InitialToken);
            }

            request.Headers["Authorization"] = $"{InitialToken.TokenType} {InitialToken.AccessToken}";
        }
示例#3
0
 /// <summary>
 /// Refreshes a token using pkce flow
 /// </summary>
 /// <param name="request">The request-model which contains required and optional parameters.</param>
 /// <remarks>
 /// https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for-code-exchange-pkce
 /// </remarks>
 /// <returns></returns>1
 public Task <PKCETokenResponse> RequestToken(PKCETokenRefreshRequest request)
 {
     return(RequestToken(request, API));
 }