2021-07-24 15:46:34 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package oauth2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RegisterSource causes an OAuth2 configuration to be registered
|
|
|
|
func (source *Source) RegisterSource() error {
|
2021-08-06 06:41:08 +05:30
|
|
|
err := RegisterProviderWithGothic(source.loginSource.Name, source)
|
2021-07-24 15:46:34 +05:30
|
|
|
return wrapOpenIDConnectInitializeError(err, source.loginSource.Name, source)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnregisterSource causes an OAuth2 configuration to be unregistered
|
|
|
|
func (source *Source) UnregisterSource() error {
|
2021-08-06 06:41:08 +05:30
|
|
|
RemoveProviderFromGothic(source.loginSource.Name)
|
2021-07-24 15:46:34 +05:30
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapOpenIDConnectInitializeError is used to wrap the error but this cannot be done in modules/auth/oauth2
|
|
|
|
// inside oauth2: import cycle not allowed models -> modules/auth/oauth2 -> models
|
|
|
|
func wrapOpenIDConnectInitializeError(err error, providerName string, source *Source) error {
|
|
|
|
if err != nil && source.Provider == "openidConnect" {
|
|
|
|
err = models.ErrOpenIDConnectInitialize{ProviderName: providerName, OpenIDConnectAutoDiscoveryURL: source.OpenIDConnectAutoDiscoveryURL, Cause: err}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|