1
0
Fork 0
forked from forgejo/forgejo

Update markbates/goth (#10444)

- Fixes a JWT decoding issue in the OpenID provider
- Updates the GitHub provider to use the authorization header for authentication
- Updates the Twitch provider for Twitch's v5 API changes
- Adds the email and is_private_email fields to the Apple provider's GetUser implementation
- Modifies gothic to export a non-collidable context key for setting the Provider in a context.Context
- Adds new scopes to the Spotify provider
- Adds the IDToken from OpenID providers on the user struct
- Make Apple provider's SecretParams public
- Adds support for sign in with Apple, and drops support for Go versions 1.7 and 1.8
- Fixes the Slack provider's FetchURL logic to use the appropriate scope for the info it needs
Signed-off-by: Oscar LÃfwenhamn <oscar.lofwenhamn@cgi.com>
This commit is contained in:
oscar.lofwenhamn 2020-02-24 18:08:43 +01:00 committed by GitHub
parent c97433d07d
commit 0eeee9c721
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 18 deletions

View file

@ -10,6 +10,7 @@ package gothic
import (
"bytes"
"compress/gzip"
"context"
"crypto/rand"
"encoding/base64"
"errors"
@ -35,6 +36,11 @@ var defaultStore sessions.Store
var keySet = false
type key int
// ProviderParamKey can be used as a key in context when passing in a provider
const ProviderParamKey key = iota
func init() {
key := []byte(os.Getenv("SESSION_SECRET"))
keySet = len(key) != 0
@ -265,6 +271,11 @@ func getProviderName(req *http.Request) (string, error) {
return p, nil
}
// try to get it from the go-context's value of providerContextKey key
if p, ok := req.Context().Value(ProviderParamKey).(string); ok {
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)
@ -280,6 +291,11 @@ func getProviderName(req *http.Request) (string, error) {
return "", errors.New("you must select a provider")
}
// GetContextWithProvider returns a new request context containing the provider
func GetContextWithProvider(req *http.Request, provider string) *http.Request {
return req.WithContext(context.WithValue(req.Context(), ProviderParamKey, provider))
}
// StoreInSession stores a specified key/value pair in the session.
func StoreInSession(key string, value string, req *http.Request, res http.ResponseWriter) error {
session, _ := Store.New(req, SessionName)