gitea-github-proxy/api/oauth.go

35 lines
811 B
Go

package api
import (
"fmt"
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
"go.uber.org/zap"
"golang.org/x/oauth2"
)
type oauth struct {
cfg *config.Config
logger *zap.Logger
}
func newOauth(cfg *config.Config, logger *zap.Logger) *oauth {
return &oauth{cfg: cfg, logger: logger}
}
func (o oauth) config() *oauth2.Config {
return &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),
},
}
}
func (o oauth) authUrl() string {
return o.config().AuthCodeURL("state")
}