Ejemplo n.º 1
0
func (s *Storage) LoadAccess(code string) (*osin.AccessData, error) {
	var userData string
	var cid, prevAccessToken, authorizeCode string
	var result osin.AccessData
	row := s.db.QueryRow("SELECT client, authorize, previous, access_token, refresh_token, expires_in, scope, redirect_uri, created_at, extra FROM access WHERE access_token=$1 LIMIT 1", code)
	err := row.Scan(&cid, &authorizeCode, &prevAccessToken, &result.AccessToken, &result.RefreshToken, &result.ExpiresIn, &result.Scope, &result.RedirectUri, &result.CreatedAt, &userData)
	result.UserData = userData

	client, err := s.GetClient(cid)
	if err != nil {
		return nil, err
	}
	result.Client = client

	authorize, err := s.LoadAuthorize(authorizeCode)
	if err != nil {
		return nil, err
	}
	result.AuthorizeData = authorize

	if prevAccessToken != "" {
		prevAccess, err := s.LoadAccess(prevAccessToken)
		if err != nil {
			return nil, err
		}
		result.AccessData = prevAccess
	}

	return &result, err
}
Ejemplo n.º 2
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.º 3
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
}