auth

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package auth defines the authentication layer of the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClaimsFromRequest

func GetClaimsFromRequest(r *http.Request) (claims *jwt.Claims, ok bool)

GetClaimsFromRequest is a helper function to fetch the JWT session token from an HTTP request.

Types

type Auth

type Auth struct {
	JWTSecret jwt.Secret
	// contains filtered or unexported fields
}

Auth is a service that provides HTTP handlers and middlewares used for authentication.

It uses a time-based nonce. The nonce is encrypted with the private key.

func NewAuth

func NewAuth(jwtSecret jwt.Secret, pk *ecdsa.PrivateKey) *Auth

NewAuth builds the Auth struct.

func (*Auth) CallBack

func (a *Auth) CallBack() http.HandlerFunc

CallBack is the handler called after login.

It:

  1. Fetches the signed message
  2. Validate and wrap the address in a JWT token
  3. Store the JWT token in a cookie for the browser.

func (*Auth) Challenge

func (a *Auth) Challenge(message string) string

Challenge returns a message with a nonce.

func (*Auth) Login

func (a *Auth) Login() http.HandlerFunc

Login is the handler called after login.

It sends a challenge to the authenticator (Metamask).

func (*Auth) Logout

func (a *Auth) Logout() http.HandlerFunc

Logout removes session cookies and redirect to home.

func (*Auth) Middleware

func (a *Auth) Middleware(next http.Handler) http.Handler

Middleware is an authentication guard for HTTP servers.

func (*Auth) Verify

func (a *Auth) Verify(address string, data []byte, sig []byte) error

Verify checks the signature and nonce.

This is a time-based nonce. In production, it is preferable to use a true nonce (random number) which is stored in a database.

Jump to

Keyboard shortcuts

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