token

package module
v0.0.0-...-4339a0c Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 5 Imported by: 1

README

Token

License

Installation

Use go get.

go get github.com/go-funcards/token

Then import token package into your own code.

import "github.com/go-funcards/token"

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config, generator jwt.Generator, storage Storage) *service

Types

type Config

type Config struct {
	TokenType string        `mapstructure:"token_type" yaml:"token_type" env:"TOKEN_TYPE" env-default:"Bearer"`
	TTL       time.Duration `mapstructure:"ttl" yaml:"ttl" env:"TTL" env-default:"8760h"`
}

type Service

type Service interface {
	SessByRefreshToken(ctx context.Context, refreshToken string) (Session, error)
	SessByUser(ctx context.Context, user jwt.User) (Session, error)
}

type Session

type Session struct {
	TokenType    string `json:"token_type"` // Bearer
	ExpiresIn    uint   `json:"expires_in"` // The lifetime in seconds of refresh token
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type Storage

type Storage interface {
	Set(ctx context.Context, refreshToken string, user jwt.User, expiration time.Duration) error
	Get(ctx context.Context, refreshToken string) (jwt.User, error)
	Del(ctx context.Context, refreshToken string)
}

Jump to

Keyboard shortcuts

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