token

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compose

func Compose(c *gin.Context, u *library.User) (string, string, error)

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

func CreateAccessToken(u *library.User, d time.Duration) (string, error)

CreateAccessToken creates a new access token for the given user and duration.

func CreateRefreshToken added in v0.7.0

func CreateRefreshToken(u *library.User, d time.Duration) (string, int, error)

CreateCreateRefreshToken creates a new refresh token for the given user and duration.

func Parse

func Parse(t string, db database.Service) (*library.User, error)

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

func Refresh(c *gin.Context, refreshToken string) (string, error)

Refresh returns a new access token, if the provided refreshToken is valid.

func RetrieveAccessToken added in v0.7.0

func RetrieveAccessToken(r *http.Request) (accessToken string, err error)

RetrieveAccessToken gets the passed in access token from the header in the request.

func RetrieveRefreshToken added in v0.7.0

func RetrieveRefreshToken(r *http.Request) (string, error)

RetrieveRefreshToken gets the refresh token sent along with the request as a cookie.

Types

type Claims added in v0.7.0

type Claims struct {
	IsAdmin  bool `json:"is_admin"`
	IsActive bool `json:"is_active"`
	jwt.StandardClaims
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL