adapter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 8 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package to request and verify jwt token

Index

Constants

View Source
const (
	// Name of header where jwt token is stored
	AuthorizationHeaderName = "Authorization"
	// Name of header where refresh token is stored
	RefreshTokenHeaderName = "refresh_token"
	// Key to set claim in context
	ClaimName = "claim"
	// Environment variable to point to url for the auth service
	EnvAuthUrl = "AUTHI_URL"

	// Url of root path for authi
	AuthiRootPath = "/user"
	//Path to login api
	AuthiLoginPath = "/login"
	//Path to refresh api
	AuthiRefreshPath = "/refresh"

	//Content type for AuthenticateDTO
	ContentTyp = "application/json; charset=utf-8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdapterMock added in v0.3.0

type AdapterMock struct {
	RefreshTokenRecordArray   []*RefreshTokenRecord
	RefreshTokenResponseArray []*TokenResponse

	GetTokenRecordArray   []*GetTokenRecord
	GetTokenResponseArray []*TokenResponse
}

func (*AdapterMock) GetToken added in v0.3.0

func (mock *AdapterMock) GetToken(userId string, password string) (*TokenResponseDTO, error)

func (*AdapterMock) RefreshToken added in v0.3.0

func (mock *AdapterMock) RefreshToken(userId string, token string, refreshToken string) (*TokenResponseDTO, error)

type AuthAdapter

type AuthAdapter interface {
	RefreshToken(userId string, token string, refreshToken string) (*TokenResponseDTO, error)
	GetToken(userId string, password string) (*TokenResponseDTO, error)
}

Interface for authentication

func NewAuthiAdapter

func NewAuthiAdapter(correlationId string) AuthAdapter

Initialize auth adapter with public key and url to authi service. Therefor the environment variable AUTH_URL have to be set

type AuthenticateDTO

type AuthenticateDTO struct {
	Password string `json:"password" validate:"required"`
}

Request object for authentication

type AuthiAdapter

type AuthiAdapter struct {
	// contains filtered or unexported fields
}

Implementation of auth adapter to login and refresh token of user

func (*AuthiAdapter) GetToken

func (authAdapter *AuthiAdapter) GetToken(userId string, password string) (*TokenResponseDTO, error)

Login to get token

func (*AuthiAdapter) RefreshToken

func (authAdapter *AuthiAdapter) RefreshToken(userId string, token string, refreshToken string) (*TokenResponseDTO, error)

Get new token with refresh token from authi service

type Claims

type Claims struct {
	UserId uuid.UUID `json:"user_id"`
	jwt.StandardClaims
}

Claim with data from the token

type GetTokenRecord added in v0.3.0

type GetTokenRecord struct {
	UserId   string
	Password string
}

type RefreshTokenRecord added in v0.3.0

type RefreshTokenRecord struct {
	UserId       string
	Token        string
	RefreshToken string
}

type TokenResponse added in v0.3.0

type TokenResponse struct {
	TokenResponseDTO *TokenResponseDTO
	Err              error
}

type TokenResponseDTO

type TokenResponseDTO struct {
	AccessToken      string `json:"access_token"`
	ExpiresIn        int    `json:"expires_in"`
	RefreshToken     string `json:"refresh_token"`
	RefreshExpiresIn int    `json:"refresh_expires_in"`
}

Response with token data

Jump to

Keyboard shortcuts

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