diff options
Diffstat (limited to 'services/auth/source/oauth2')
-rw-r--r-- | services/auth/source/oauth2/source_register.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/services/auth/source/oauth2/source_register.go b/services/auth/source/oauth2/source_register.go index 24c61a9a56..71ba288bf4 100644 --- a/services/auth/source/oauth2/source_register.go +++ b/services/auth/source/oauth2/source_register.go @@ -5,7 +5,7 @@ package oauth2 import ( - "code.gitea.io/gitea/models" + "fmt" ) // RegisterSource causes an OAuth2 configuration to be registered @@ -20,11 +20,28 @@ func (source *Source) UnregisterSource() error { return nil } +// ErrOpenIDConnectInitialize represents a "OpenIDConnectInitialize" kind of error. +type ErrOpenIDConnectInitialize struct { + OpenIDConnectAutoDiscoveryURL string + ProviderName string + Cause error +} + +// IsErrOpenIDConnectInitialize checks if an error is a ExternalLoginUserAlreadyExist. +func IsErrOpenIDConnectInitialize(err error) bool { + _, ok := err.(ErrOpenIDConnectInitialize) + return ok +} + +func (err ErrOpenIDConnectInitialize) Error() string { + return fmt.Sprintf("Failed to initialize OpenID Connect Provider with name '%s' with url '%s': %v", err.ProviderName, err.OpenIDConnectAutoDiscoveryURL, err.Cause) +} + // 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} + err = ErrOpenIDConnectInitialize{ProviderName: providerName, OpenIDConnectAutoDiscoveryURL: source.OpenIDConnectAutoDiscoveryURL, Cause: err} } return err } |