github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/token.go (about)

     1  package v2action
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/SermoDigital/jose/jws"
     7  	"github.com/SermoDigital/jose/jwt"
     8  )
     9  
    10  func (actor Actor) RefreshAccessToken(refreshToken string) (string, error) {
    11  
    12  	tokens, err := actor.UAAClient.RefreshAccessToken(refreshToken)
    13  	if err != nil {
    14  		return "", err
    15  	}
    16  
    17  	actor.Config.SetAccessToken(tokens.AuthorizationToken())
    18  	actor.Config.SetRefreshToken(tokens.RefreshToken)
    19  
    20  	return tokens.AuthorizationToken(), nil
    21  }
    22  
    23  func (actor Actor) ParseAccessToken(accessToken string) (jwt.JWT, error) {
    24  	tokenStr := strings.TrimPrefix(accessToken, "bearer ")
    25  	return jws.ParseJWT([]byte(tokenStr))
    26  }