Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch OAuth refresh token errors for generic provider #1196

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/shared/Core/GenericHostProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,26 @@ private async Task<ICredential> GetOAuthAccessToken(Uri remoteUri, string userNa
ICredential refreshToken = Context.CredentialStore.Get(refreshService, userName);
if (refreshToken != null)
{
var refreshResult = await client.GetTokenByRefreshTokenAsync(refreshToken.Password, CancellationToken.None);
try
{
var refreshResult = await client.GetTokenByRefreshTokenAsync(refreshToken.Password, CancellationToken.None);

// Store new refresh token if we have been given one
if (!string.IsNullOrWhiteSpace(refreshResult.RefreshToken))
{
Context.CredentialStore.AddOrUpdate(refreshService, refreshToken.Account, refreshToken.Password);
}
// Store new refresh token if we have been given one
if (!string.IsNullOrWhiteSpace(refreshResult.RefreshToken))
{
Context.CredentialStore.AddOrUpdate(refreshService, refreshToken.Account, refreshToken.Password);
}

// Return the new access token
return new GitCredential(oauthUser,refreshResult.AccessToken);
// Return the new access token
return new GitCredential(oauthUser,refreshResult.AccessToken);
}
catch (OAuth2Exception ex)
{
// Failed to use refresh token. It may have expired or been revoked.
// Fall through to an interactive OAuth flow.
Context.Trace.WriteLine("Failed to use refresh token.");
Context.Trace.WriteException(ex);
}
}

// Determine which interactive OAuth mode to use. Start by checking for mode preference in config
Expand Down