This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2020-09-30 09:49:06 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Claims struct {
|
|
|
|
Proxy struct {
|
2020-10-29 21:09:53 +00:00
|
|
|
UserAttributes map[string]interface{} `json:"user_attributes"`
|
2020-12-05 21:08:42 +00:00
|
|
|
} `json:"ak_proxy"`
|
2020-09-30 09:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Claims) FromIDToken(idToken string) error {
|
|
|
|
// id_token is a base64 encode ID token payload
|
|
|
|
// https://developers.google.com/accounts/docs/OAuth2Login#obtainuserinfo
|
|
|
|
jwt := strings.Split(idToken, ".")
|
|
|
|
jwtData := strings.TrimSuffix(jwt[1], "=")
|
|
|
|
b, err := base64.RawURLEncoding.DecodeString(jwtData)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(b, c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|