feat: Add no_refresh option to Git auth configs (#5097)

This allows organizations to disable refreshing Git tokens
and instead prompt for authentication again.
This commit is contained in:
Kyle Carberry
2022-11-15 21:06:13 +00:00
committed by GitHub
parent 2a46702fc5
commit fc0a493b72
5 changed files with 86 additions and 0 deletions
+9
View File
@@ -1154,6 +1154,15 @@ func (api *API) workspaceAgentsGitAuth(rw http.ResponseWriter, r *http.Request)
return
}
// If the token is expired and refresh is disabled, we prompt
// the user to authenticate again.
if gitAuthConfig.NoRefresh && gitAuthLink.OAuthExpiry.Before(database.Now()) {
httpapi.Write(ctx, rw, http.StatusOK, codersdk.WorkspaceAgentGitAuthResponse{
URL: redirectURL.String(),
})
return
}
token, err := gitAuthConfig.TokenSource(ctx, &oauth2.Token{
AccessToken: gitAuthLink.OAuthAccessToken,
RefreshToken: gitAuthLink.OAuthRefreshToken,