Ejemplo n.º 1
0
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 {
		return
	}

	// 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
}
Ejemplo n.º 2
0
Archivo: jwt.go Proyecto: thanzen/hydra
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
}