Documentation ¶
Overview ¶
Package token provides the ability for inserting Vela token resources into or extracting Vela token resources from the middleware chain for the API.
Usage:
import "github.com/go-vela/server/router/middleware/token"
Index ¶
- func Compose(c *gin.Context, u *library.User) (string, string, error)
- func CreateAccessToken(u *library.User, d time.Duration) (string, error)
- func CreateRefreshToken(u *library.User, d time.Duration) (string, int, error)
- func Parse(t string, db database.Service) (*library.User, error)
- func Refresh(c *gin.Context, refreshToken string) (string, error)
- func RetrieveAccessToken(r *http.Request) (accessToken string, err error)
- func RetrieveRefreshToken(r *http.Request) (string, error)
- type Claims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compose ¶
Compose generates an refresh and access token pair unique to the provided user and sets a secure cookie. It uses a secret hash, which is unique for every user. The hash signs the token to guarantee the signature is unique per token. The refresh token is returned to store with the user in the database.
func CreateAccessToken ¶ added in v0.7.0
CreateAccessToken creates a new access token for the given user and duration.
func CreateRefreshToken ¶ added in v0.7.0
CreateCreateRefreshToken creates a new refresh token for the given user and duration.
func Parse ¶
Parse scans the signed JWT token as a string and extracts the user login from the claims to be looked up in the database. This function will return an error for a few different reasons:
* the token signature doesn't match what is expected * the token signing method doesn't match what is expected * the token is invalid (potentially expired or improper).
func Refresh ¶ added in v0.7.0
Refresh returns a new access token, if the provided refreshToken is valid.
func RetrieveAccessToken ¶ added in v0.7.0
RetrieveAccessToken gets the passed in access token from the header in the request.