Merge pull request #2684 from techknowlogick/techknowlogick-patch-1
Refresh Gitea Oauth2 token
This commit is contained in:
commit
526ae811fd
2 changed files with 27 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue