refactor: make config stateful
This commit is contained in:
parent
bbe7e8e053
commit
8dd6e83fae
27
api/oauth.go
27
api/oauth.go
|
@ -18,6 +18,7 @@ type Oauth struct {
|
|||
token *oauth2.Token
|
||||
refresher oauth2.TokenSource
|
||||
keepAliveRunning bool
|
||||
oauthCfg *oauth2.Config
|
||||
}
|
||||
|
||||
func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
|
||||
|
@ -35,21 +36,23 @@ func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
|
|||
}
|
||||
|
||||
func (o Oauth) config() *oauth2.Config {
|
||||
cfg := &oauth2.Config{
|
||||
ClientID: o.cfg.Oauth.ClientId,
|
||||
ClientSecret: o.cfg.Oauth.ClientSecret,
|
||||
Scopes: []string{"admin"},
|
||||
RedirectURL: fmt.Sprintf("https://%s/setup/callback", o.cfg.Domain),
|
||||
Endpoint: oauth2.Endpoint{
|
||||
TokenURL: fmt.Sprintf("%s/login/Oauth/access_token", o.cfg.GiteaUrl),
|
||||
AuthURL: fmt.Sprintf("%s/login/Oauth/authorize", o.cfg.GiteaUrl),
|
||||
},
|
||||
}
|
||||
if o.oauthCfg == nil {
|
||||
o.oauthCfg = &oauth2.Config{
|
||||
ClientID: o.cfg.Oauth.ClientId,
|
||||
ClientSecret: o.cfg.Oauth.ClientSecret,
|
||||
Scopes: []string{"admin"},
|
||||
RedirectURL: fmt.Sprintf("https://%s/setup/callback", o.cfg.Domain),
|
||||
Endpoint: oauth2.Endpoint{
|
||||
TokenURL: fmt.Sprintf("%s/login/Oauth/access_token", o.cfg.GiteaUrl),
|
||||
AuthURL: fmt.Sprintf("%s/login/Oauth/authorize", o.cfg.GiteaUrl),
|
||||
},
|
||||
}
|
||||
|
||||
o.loadToken(cfg)
|
||||
}
|
||||
o.loadToken(o.oauthCfg)
|
||||
o.keepAlive()
|
||||
|
||||
return cfg
|
||||
return o.oauthCfg
|
||||
}
|
||||
|
||||
func (o Oauth) authUrl() string {
|
||||
|
|
Loading…
Reference in New Issue