jwt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: MIT Imports: 4 Imported by: 0

README

jwt

A complete jwt solution. NOT a library! You can only use it if your project structure allows you to use such jwt tokens!

This solution assumes that AccessToken contains only id represented by uint type, RefreshToken contains only password represented by string type. But it is not difficult to change it, just copy the code and change AccessClaims and RefreshClaims types, as well as function types.

To start working with jwt, it is necessary to specify values to the environment variables "JWT_REFRESH_KEY" and "JWT_ACCESS_KEY".

Use NewRefreshToken to create a new refresh token. Use NewAccessToken to create a new access token. Use ReturnAccessAndRefreshTokens to get access and refresh tokens.

This package has types "AccessToken" and "RefreshToken". These types have parse methods to return parsed values.

For example

accessToken, err := jwt.NewAccessToken(1)
id, err := accessToken.Parse()

Documentation

Index

Constants

View Source
const (
	AccessTokenLive  = time.Minute * 15
	RefreshTokenLive = time.Hour * 24 * 31
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessClaims

type AccessClaims struct {
	UserID uint `json:"user_id"`
}

type AccessToken

type AccessToken Token

func NewAccessToken

func NewAccessToken(id uint) (AccessToken, error)

func StringToAccessToken

func StringToAccessToken(token string) AccessToken

func (AccessToken) Parse

func (token AccessToken) Parse() (uint, error)

func (AccessToken) String

func (token AccessToken) String() string

type AllTokenResponse

type AllTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

func ReturnAccessAndRefreshTokens

func ReturnAccessAndRefreshTokens(id uint, pass string) (AllTokenResponse, error)

type RefreshClaims

type RefreshClaims struct {
	Password string `json:"password"`
}

type RefreshToken

type RefreshToken Token

func NewRefreshToken

func NewRefreshToken(passwordHash string) (RefreshToken, error)

func StringToRefreshToken

func StringToRefreshToken(token string) RefreshToken

func (RefreshToken) Parse

func (token RefreshToken) Parse() (string, error)

func (RefreshToken) String

func (token RefreshToken) String() string

type Token

type Token []byte

func StringToToken

func StringToToken(token string) Token

func (Token) String

func (token Token) String() string

Jump to

Keyboard shortcuts

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