diff --git a/cmd/drone-server/inject_client.go b/cmd/drone-server/inject_client.go index 8ab383eb..b3113556 100644 --- a/cmd/drone-server/inject_client.go +++ b/cmd/drone-server/inject_client.go @@ -117,10 +117,25 @@ 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, + Source: oauth2.ContextTokenSource(), + Base: defaultTransport(config.Gitea.SkipVerify), + }, + } + return client + } client.Client = &http.Client{ Transport: &oauth2.Transport{ - Scheme: oauth2.SchemeToken, - Source: oauth2.ContextTokenSource(), + 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), }, } diff --git a/cmd/drone-server/inject_login.go b/cmd/drone-server/inject_login.go index c3115fa3..caadae39 100644 --- a/cmd/drone-server/inject_login.go +++ b/cmd/drone-server/inject_login.go @@ -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 }