use base64.RawURLEncoding.DecodeString() in place of a bespoke function

This commit is contained in:
Colin Arnott 2017-07-13 18:29:58 +00:00
parent 3c51c914ac
commit 8d6e16bf22
No known key found for this signature in database
GPG Key ID: 0447A663F7F3E236

View File

@ -67,7 +67,7 @@ func emailFromIdToken(idToken string) (string, error) {
// id_token is a base64 encode ID token payload // id_token is a base64 encode ID token payload
// https://developers.google.com/accounts/docs/OAuth2Login#obtainuserinfo // https://developers.google.com/accounts/docs/OAuth2Login#obtainuserinfo
jwt := strings.Split(idToken, ".") jwt := strings.Split(idToken, ".")
b, err := jwtDecodeSegment(jwt[1]) b, err := base64.RawURLEncoding.DecodeString(jwt[1])
if err != nil { if err != nil {
return "", err return "", err
} }
@ -89,14 +89,6 @@ func emailFromIdToken(idToken string) (string, error) {
return email.Email, nil return email.Email, nil
} }
func jwtDecodeSegment(seg string) ([]byte, error) {
if l := len(seg) % 4; l > 0 {
seg += strings.Repeat("=", 4-l)
}
return base64.URLEncoding.DecodeString(seg)
}
func (p *GoogleProvider) Redeem(redirectURL, code string) (s *SessionState, err error) { func (p *GoogleProvider) Redeem(redirectURL, code string) (s *SessionState, err error) {
if code == "" { if code == "" {
err = errors.New("missing code") err = errors.New("missing code")