diff options
author | zeripath <art27@cantab.net> | 2023-03-10 06:14:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 01:14:43 -0500 |
commit | dad057b6393548ad389ead07c2cce5b3ac2811e0 (patch) | |
tree | 9c2428b187001d7ad5460e9913eb2cae1124182d /cmd | |
parent | f92e0a4018ca65936c95ac119c57d4b9ab62bc2d (diff) | |
download | gitea-dad057b6393548ad389ead07c2cce5b3ac2811e0.tar.gz gitea-dad057b6393548ad389ead07c2cce5b3ac2811e0.zip |
Handle OpenID discovery URL errors a little nicer when creating/editing sources (#23397)
When there is an error creating a new openIDConnect authentication
source try to handle the error a little better.
Close #23283
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/admin.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/admin.go b/cmd/admin.go index b913b817bd..f9fb1b6c68 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -7,6 +7,7 @@ package cmd import ( "errors" "fmt" + "net/url" "os" "strings" "text/tabwriter" @@ -469,11 +470,19 @@ func runAddOauth(c *cli.Context) error { return err } + config := parseOAuth2Config(c) + if config.Provider == "openidConnect" { + discoveryURL, err := url.Parse(config.OpenIDConnectAutoDiscoveryURL) + if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") { + return fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", config.OpenIDConnectAutoDiscoveryURL) + } + } + return auth_model.CreateSource(&auth_model.Source{ Type: auth_model.OAuth2, Name: c.String("name"), IsActive: true, - Cfg: parseOAuth2Config(c), + Cfg: config, }) } |