2024-12-28 10:50:59 -05:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Oauth2Config struct {
|
2025-03-04 07:28:22 -05:00
|
|
|
ClientID string `koanf:"client_id" json:"client_id,omitempty"`
|
|
|
|
ClientSecret string `koanf:"client_secret" json:"client_secret,omitempty"`
|
|
|
|
Endpoint Oauth2Endpoint `koanf:"endpoint" json:"endpoint,omitempty"`
|
|
|
|
Scopes []string `koanf:"scopes" json:"scopes,omitempty"`
|
2024-12-28 10:50:59 -05:00
|
|
|
|
2025-03-04 07:28:22 -05:00
|
|
|
UserInfoURL string `koanf:"user_info_url" json:"user_info_url,omitempty"`
|
|
|
|
UserIDPath string `koanf:"user_id_path" json:"user_id_path,omitempty"`
|
2024-12-28 10:50:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type Oauth2Endpoint struct {
|
2025-03-04 07:28:22 -05:00
|
|
|
AuthURL string `koanf:"auth_url" json:"auth_url,omitempty"`
|
|
|
|
TokenURL string `koanf:"token_url" json:"token_url,omitempty"`
|
2024-12-28 10:50:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Oauth2Config) Setup(redirectURL string) *oauth2.Config {
|
|
|
|
return &oauth2.Config{
|
|
|
|
ClientID: c.ClientID,
|
|
|
|
ClientSecret: c.ClientSecret,
|
|
|
|
Endpoint: oauth2.Endpoint{
|
|
|
|
AuthURL: c.Endpoint.AuthURL,
|
|
|
|
TokenURL: c.Endpoint.TokenURL,
|
|
|
|
},
|
|
|
|
RedirectURL: redirectURL,
|
|
|
|
Scopes: c.Scopes,
|
|
|
|
}
|
|
|
|
}
|