1
0
Fork 0
forked from forgejo/forgejo

oauth2 with remote Gitea - Fix #8093 (#8149)

This commit is contained in:
techknowlogick 2019-09-12 22:15:36 -04:00 committed by GitHub
parent cff0787759
commit 2837563147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 307 additions and 17 deletions

View file

@ -245,19 +245,6 @@ var GetProviderName = getProviderName
func getProviderName(req *http.Request) (string, error) {
// get all the used providers
providers := goth.GetProviders()
// loop over the used providers, if we already have a valid session for any provider (ie. user is already logged-in with a provider), then return that provider name
for _, provider := range providers {
p := provider.Name()
session, _ := Store.Get(req, p+SessionName)
value := session.Values[p]
if _, ok := value.(string); ok {
return p, nil
}
}
// try to get it from the url param "provider"
if p := req.URL.Query().Get("provider"); p != "" {
return p, nil
@ -278,6 +265,17 @@ func getProviderName(req *http.Request) (string, error) {
return p, nil
}
// As a fallback, loop over the used providers, if we already have a valid session for any provider (ie. user has already begun authentication with a provider), then return that provider name
providers := goth.GetProviders()
session, _ := Store.Get(req, SessionName)
for _, provider := range providers {
p := provider.Name()
value := session.Values[p]
if _, ok := value.(string); ok {
return p, nil
}
}
// if not found then return an empty string with the corresponding error
return "", errors.New("you must select a provider")
}