Added OAuth2 token refresher for Gitlab (#3215)

This commit is contained in:
Endymion Wight 2022-06-14 21:46:35 +12:00 committed by GitHub
parent f7a3c375a2
commit b6053394ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -180,7 +180,13 @@ func provideGitlabClient(config config.Config) *scm.Client {
} }
client.Client = &http.Client{ client.Client = &http.Client{
Transport: &oauth2.Transport{ Transport: &oauth2.Transport{
Source: oauth2.ContextTokenSource(), Scheme: oauth2.SchemeBearer,
Source: &oauth2.Refresher{
ClientID: config.GitLab.ClientID,
ClientSecret: config.GitLab.ClientSecret,
Endpoint: strings.TrimSuffix(config.GitLab.Server, "/") + "/oauth/token",
Source: oauth2.ContextTokenSource(),
},
Base: defaultTransport(config.GitLab.SkipVerify), Base: defaultTransport(config.GitLab.SkipVerify),
}, },
} }

View file

@ -197,6 +197,14 @@ func provideRefresher(config config.Config) *oauth2.Refresher {
Source: oauth2.ContextTokenSource(), Source: oauth2.ContextTokenSource(),
Client: defaultClient(config.Gitea.SkipVerify), Client: defaultClient(config.Gitea.SkipVerify),
} }
case config.GitLab.ClientID != "":
return &oauth2.Refresher{
ClientID: config.GitLab.ClientID,
ClientSecret: config.GitLab.ClientSecret,
Endpoint: strings.TrimSuffix(config.GitLab.Server, "/") + "/oauth/token",
Source: oauth2.ContextTokenSource(),
Client: defaultClient(config.GitLab.SkipVerify),
}
case config.Gitee.ClientID != "": case config.Gitee.ClientID != "":
return &oauth2.Refresher{ return &oauth2.Refresher{
ClientID: config.Gitee.ClientID, ClientID: config.Gitee.ClientID,