public async Task Refresh()
        {
            if (RefreshToken == null)
            {
                throw new Exception("CurrentCredentials does not have a refresh token");
            }

            TokenLifecycleManager tlcm          = new TokenLifecycleManager();
            TokenResponse         tokenResponse = await tlcm.RefreshTokenAsync(AuthState.CreateTokenRefreshRequest()).ConfigureAwait(false);

            AuthState.Update(tokenResponse, null);
        }
Exemplo n.º 2
0
        public async static Task <TokenResponse> RefreshTokenAsync(this TokenLifecycleManager tlcm, TokenRequest tokenRequest)
        {
            try
            {
                var json = await tlcm.RefreshAsync(tokenRequest.Configuration.TokenEndpoint.ToString(), tokenRequest.ClientId, tokenRequest.RefreshToken).ConfigureAwait(false);

                return(new TokenResponse.Builder(tokenRequest).FromResponseJson(new JSONObject(json.ToString())).Build());
            }
            catch (AuthzException ae)
            {
                throw ae;
            }
            catch (Exception je)
            {
                throw AuthzException.fromTemplate(
                          AuthzException.GeneralErrors.JSON_DESERIALIZATION_ERROR, je);
            }
        }
        /// <summary>
        /// Performs the token refresh request returning a TokenResponse object.
        /// </summary>
        /// <returns>The token response (async)</returns>
        /// <param name="tlcm">The token lifecycle manager class.</param>
        /// <param name="tokenRequest">The request to be executed.</param>
        public async static Task <TokenResponse> RefreshTokenAsync(this TokenLifecycleManager tlcm, TokenRequest tokenRequest)
        {
            try
            {
                var json = await tlcm.RefreshAsync(tokenRequest.Configuration.TokenEndpoint.ToString(), tokenRequest.ClientId, tokenRequest.RefreshToken).ConfigureAwait(false);

                var parameters = new NSDictionary <NSString, NSCopying>(
                    new NSString[] { new NSString("access_token"), new NSString("id_token"), new NSString("expires_in"), new NSString("token_type") },
                    new NSCopying[] { new CopyableNSString(json["access_token"]), new CopyableNSString(json["id_token"]), new CopyableNSNumber(json["expires_in"]), new CopyableNSString(json["token_type"]) });

                return(new TokenResponse(tokenRequest, parameters));
            }
            catch (AuthzException ae)
            {
                throw ae;
            }
            catch (Exception je)
            {
                throw AuthzException.fromTemplate(
                          AuthzException.GeneralErrors.JSON_DESERIALIZATION_ERROR, je);
            }
        }