func (c *AccessTokenGenJWT) GenerateAccessToken(data *osin.AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) { // generate JWT access token token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{ "cid": data.Client.GetId(), "exp": data.ExpireAt().Unix(), }) accesstoken, err = token.SignedString(c.PrivateKey) if err != nil { return "", "", err } if !generaterefresh { return } // generate JWT refresh token token = jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{ "cid": data.Client.GetId(), }) refreshtoken, err = token.SignedString(c.PrivateKey) if err != nil { return "", "", err } return }
func (c *AccessTokenGenJWT) GenerateAccessToken(data *osin.AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) { // generate JWT access token token := jwt.New(jwt.GetSigningMethod("RS256")) token.Claims["cid"] = data.Client.GetId() token.Claims["exp"] = data.ExpireAt().Unix() accesstoken, err = token.SignedString(c.PrivateKey) if err != nil { return "", "", err } if generaterefresh { // generate JWT access token token = jwt.New(jwt.GetSigningMethod("RS256")) token.Claims["cid"] = data.Client.GetId() token.Claims["at"] = accesstoken token.Claims["exp"] = data.ExpireAt().Unix() refreshtoken, err = token.SignedString(c.PrivateKey) if err != nil { return "", "", err } } return }
func (j *JWT) GenerateAccessToken(data *osin.AccessData, generateRefresh bool) (accessToken string, refreshToken string, err error) { claims, ok := data.UserData.(ClaimsCarrier) if !ok { return "", "", errors.Errorf("Could not assert claims to ClaimsCarrier: %v", claims) } claims["exp"] = data.ExpireAt() if accessToken, err = j.SignToken(claims, map[string]interface{}{}); err != nil { return "", "", err } else if !generateRefresh { return } if refreshToken, err = j.SignToken(claims, map[string]interface{}{}); err != nil { return "", "", err } return }