Merge pull request #2684 from techknowlogick/techknowlogick-patch-1

Refresh Gitea Oauth2 token
This commit is contained in:
Brad Rydzewski 2019-04-22 23:31:27 -07:00 committed by GitHub
commit 526ae811fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View file

@ -117,6 +117,7 @@ func provideGiteaClient(config config.Config) *scm.Client {
if config.Gitea.Debug {
client.DumpResponse = httputil.DumpResponse
}
if config.Gitea.ClientID == "" {
client.Client = &http.Client{
Transport: &oauth2.Transport{
Scheme: oauth2.SchemeToken,
@ -126,6 +127,20 @@ func provideGiteaClient(config config.Config) *scm.Client {
}
return client
}
client.Client = &http.Client{
Transport: &oauth2.Transport{
Scheme: oauth2.SchemeBearer,
Source: &oauth2.Refresher{
ClientID: config.Gitea.ClientID,
ClientSecret: config.Gitea.ClientSecret,
Endpoint: config.Gitea.Server + "/login/oauth/access_token",
Source: oauth2.ContextTokenSource(),
},
Base: defaultTransport(config.Gitea.SkipVerify),
},
}
return client
}
// provideGitlabClient is a Wire provider function that returns
// a GitLab client based on the environment configuration.

View file

@ -162,15 +162,23 @@ func provideStashLogin(config config.Config) login.Middleware {
}
// provideRefresher is a Wire provider function that returns
// an oauth token refresher for Bitbucket.
// an oauth token refresher for Bitbucket and Gitea
func provideRefresher(config config.Config) *oauth2.Refresher {
if config.Bitbucket.ClientID != "" {
switch {
case config.Bitbucket.ClientID != "":
return &oauth2.Refresher{
ClientID: config.Bitbucket.ClientID,
ClientSecret: config.Bitbucket.ClientSecret,
Endpoint: "https://bitbucket.org/site/oauth2/access_token",
Source: oauth2.ContextTokenSource(),
}
case config.Gitea.ClientID != "":
return &oauth2.Refresher{
ClientID: config.Gitea.ClientID,
ClientSecret: config.Gitea.ClientSecret,
Endpoint: config.Gitea.Server + "/login/oauth/access_token",
Source: oauth2.ContextTokenSource(),
}
}
return nil
}