mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-14 03:42:40 +00:00
38 lines
706 B
Go
38 lines
706 B
Go
package oauth
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/markbates/goth"
|
|
"github.com/markbates/goth/providers/openidConnect"
|
|
"github.com/thomiceli/opengist/internal/config"
|
|
)
|
|
|
|
type OIDCProvider struct {
|
|
Provider
|
|
URL string
|
|
}
|
|
|
|
func (p *OIDCProvider) RegisterProvider() error {
|
|
oidcProvider, err := openidConnect.New(
|
|
config.C.OIDCClientKey,
|
|
config.C.OIDCSecret,
|
|
urlJoin(p.URL, "/oauth/openid-connect/callback"),
|
|
config.C.OIDCDiscoveryUrl,
|
|
"openid",
|
|
"email",
|
|
"profile",
|
|
)
|
|
|
|
if err != nil {
|
|
return errors.New("Cannot create OIDC provider: " + err.Error())
|
|
}
|
|
|
|
goth.UseProviders(oidcProvider)
|
|
return nil
|
|
}
|
|
|
|
func NewOIDCProvider(url string) *OIDCProvider {
|
|
return &OIDCProvider{
|
|
URL: url,
|
|
}
|
|
}
|