jwtAuth

package module
v0.0.0-...-b758e09 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 4 Imported by: 0

README

JWT

JWT is useful for authorizing resources or content of particular applications. Once the user is logged in, each subsequent request will include the JWT access token, allowing the user to access routes, services, and resources that are permitted with that token.

Read JWT Introduction for more information.

Read a detailed article on JWT authentication and its working.

Generating secret keys

  • For generating tokens, we need a separate secret key for both tokens (or the same key can also be used for both tokens).
  • You can generate it with HSA 256 OR RS256 encryption. It should at least be 32 characters long, but longer is better.
  • Follow How to generate secret keys for JWT? to create secret keys

Example

Find a working example of JWT-reusable at JWT-Example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateAccessToken

func GenerateAccessToken(accessKey string, customClaims map[string]interface{}, lifeSpan int) (string, error)

func GenerateRefreshToken

func GenerateRefreshToken(refreshKey string, customClaims map[string]interface{}, lifeSpan int) (string, error)

func ValidateAccessTokenWithData

func ValidateAccessTokenWithData(token string, key string) (map[string]interface{}, error)

* Validate given token using given key

token: Access Token you want to validate key: Secret access key *

func ValidateRefreshToken

func ValidateRefreshToken(token string, key string) (bool, error)

Types

type JWTData

type JWTData struct {
	jwt.StandardClaims
	CustomClaims map[string]interface{} `json:"custom,omitempty"`
}

Jump to

Keyboard shortcuts

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