Skip to content

RefreshToken will delete token if exception is encountered in AuthorizationCodeFlow. #881

Closed
@wbrussell

Description

@wbrussell

If an exception is caught during "RefreshTokenAsync", the token file is deleted! This will force unneeded re-authorization on the client. In my case, the client is actually a long-running windows service so this disrupts this process and requires a human re-connect it.

Is there a reason that this is done?

https://github.com/google/google-api-dotnet-client/blob/a5288c4493a12791b46f7142efacb83c4fcacf58/Src/Support/GoogleApis.Auth/OAuth2/Flows/AuthorizationCodeFlow.cs

` ///

Retrieve a new token from the server using the specified request.
/// User identifier.
/// Token request.
/// Cancellation token to cancel operation.
/// Token response with the new access token.
[VisibleForTestOnly]
public async Task FetchTokenAsync(string userId, TokenRequest request,
CancellationToken taskCancellationToken)
{
// Add client id and client secret to requests.
request.ClientId = ClientSecrets.ClientId;
request.ClientSecret = ClientSecrets.ClientSecret;

        TokenResponseException tokenException = null;
        try
        {
            var tokenResponse = await request.ExecuteAsync
                (httpClient, TokenServerUrl, taskCancellationToken, Clock).ConfigureAwait(false);
            return tokenResponse;
        }
        catch (TokenResponseException ex)
        {
            // In case there is an exception during getting the token, we delete any user's token information from 
            // the data store.
            tokenException = ex;
        }
        await DeleteTokenAsync(userId, taskCancellationToken).ConfigureAwait(false);
        throw tokenException;
    }`

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions