mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-14 20:02:42 +00:00
39 lines
706 B
Go
39 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,
|
||
|
}
|
||
|
}
|