auth

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleModerator      = "moderator"
	RolePublisher      = "publisher"
	RoleRegisteredUser = "user"
)

User roles

View Source
const (
	// SigningAlgorithm specifies the default JWT signing algorithm (RS256)
	SigningAlgorithm = "RS256"
)

Variables

View Source
var ErrVerifyAPIUnavailable = fmt.Errorf("auth API is unavailable")

ErrVerifyAPIUnavailable is returned when the auth API is unavailable

Functions

func ExtractToken

func ExtractToken(authHeader string) string

ExtractToken extracts Bearer token from Authorization header

Types

type APIClient

type APIClient interface {
	VerifyToken(ctx context.Context, token string) (bool, error)
}

APIClient auth client api interface

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserRole             string `json:"user_role,omitempty"`
	Username             string `json:"username,omitempty"`
	Name                 string `json:"name,omitempty"`
	VerificationRequired bool   `json:"vrf_required"`
}

Claims represents jwt claims

func (*Claims) UserID

func (c *Claims) UserID() string

UserID return user id from claims

type Client

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

Client represents auth client

func New

func New(log *zap.Logger, authAPIClient APIClient) (*Client, error)

New constructs Auth instance

func (*Client) ParseToken

func (c *Client) ParseToken(tokenStr string) (*Claims, error)

ParseToken returns token as a set of claims. No verification is done here, use Verify for that

func (*Client) Verify

func (c *Client) Verify(ctx context.Context, tokenStr string) error

Verify calls Verify API method and returns error if token is invalid. If verify API is unavailable ErrVerifyAPIUnavailable is returned

Directories

Path Synopsis
Package auth_mock is a generated GoMock package.
Package auth_mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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