Пример #1
0
        public static Task <AuthorizationCodeRefreshResponse> RequestToken(
            AuthorizationCodeRefreshRequest request, IAPIConnector apiConnector
            )
        {
            Ensure.ArgumentNotNull(request, nameof(request));
            Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector));

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

            return(SendOAuthRequest <AuthorizationCodeRefreshResponse>(apiConnector, form, request.ClientId, request.ClientSecret));
        }
Пример #2
0
        public async Task Apply(IRequest request, IAPIConnector apiConnector)
        {
            Ensure.ArgumentNotNull(request, nameof(request));

            if (InitialToken.IsExpired)
            {
                var tokenRequest   = new AuthorizationCodeRefreshRequest(ClientId, ClientSecret, 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;

                TokenRefreshed?.Invoke(this, InitialToken);
            }

            request.Headers["Authorization"] = $"{InitialToken.TokenType} {InitialToken.AccessToken}";
        }
Пример #3
0
 /// <summary>
 /// Refresh an already received token via Authorization Code Auth
 /// </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
 /// </remarks>
 /// <returns></returns>
 public Task <AuthorizationCodeRefreshResponse> RequestToken(AuthorizationCodeRefreshRequest request)
 {
     return(RequestToken(request, API));
 }