jwt

package
v0.0.0-...-2db41fb Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package jwt provides functionality for JWT authentication

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidToken = errors.New(`invalid token`)

Functions

This section is empty.

Types

type Authorizer

type Authorizer struct {
	Store      storage.Storage
	SigningKey []byte
}

Authorizer structure for verifying the user and issuing the authorization token

func (*Authorizer) SignIn

func (a *Authorizer) SignIn(ctx context.Context, user *models.User) (string, error)

SignIn - checks if such a user exists in the database and generates a token

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Username string `json:"username"`
}

Claims used for working with golang-jwt to sign the token and verify it

type DefaultParser

type DefaultParser struct{}

DefaultParser default parser for jwt tokens

func (*DefaultParser) ParseToken

func (p *DefaultParser) ParseToken(accessToken string, signingKey []byte) (string, error)

ParseToken - checks if the token is valid, if yes returns the login of this user

type Parser

type Parser interface {
	ParseToken(accessToken string, signingKey []byte) (string, error)
}

Parser interface, which we use to verify the correctness of the jwt token. It is needed for testing authorization through gomock

Jump to

Keyboard shortcuts

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