aboutsummaryrefslogtreecommitdiffstats
path: root/services/auth/source/oauth2
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-11 01:51:09 +0800
committerGitHub <noreply@github.com>2021-11-11 01:51:09 +0800
commit0e189eecaaedc4e2c6ee13882c7b76645af50ccd (patch)
tree80a594464133202dafafe3e1cb2efbcc861fa6cd /services/auth/source/oauth2
parent43bbc5478370cbfe3ab1eed730ea002ccec74708 (diff)
downloadgitea-0e189eecaaedc4e2c6ee13882c7b76645af50ccd.tar.gz
gitea-0e189eecaaedc4e2c6ee13882c7b76645af50ccd.zip
Move oauth2 error to oauth2 service package (#17603)
Diffstat (limited to 'services/auth/source/oauth2')
-rw-r--r--services/auth/source/oauth2/source_register.go21
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
}