authtest

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package authtest provides some simple JWT token testing functionality for use in Ensign SDK tests. This package is disconnected from the Quarterdeck server, so the tests must be kept up to date with expected Quarterdeck responses.

Index

Constants

View Source
const (
	Audience        = "http://127.0.0.1"
	RefreshAudience = "http://127.0.0.1/refresh"
	Issuer          = "http://127.0.0.1"
	AccessDuration  = 10 * time.Minute
	RefreshDuration = 20 * time.Minute
	RefreshOverlap  = -10 * time.Minute
)

Variables

This section is empty.

Functions

func Err

func Err(w http.ResponseWriter, status int, err error)

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	OrgID       string   `json:"org,omitempty"`
	ProjectID   string   `json:"project,omitempty"`
	Permissions []string `json:"permissions,omitempty"`
}

Claims implements Quarterdeck-like claims for use in testing the SDK client.

type Server

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

Server implements an endpoint to host JWKS public keys and also provides simple functionality to create access and refresh tokens that would be authenticated.

func NewServer

func NewServer() (s *Server, err error)

NewServer starts and returns a new authtest server. The caller should call Close when finished, to shut it down.

func (*Server) Authenticate

func (s *Server) Authenticate(w http.ResponseWriter, r *http.Request)

func (*Server) Close

func (s *Server) Close()

func (*Server) CreateAccessToken

func (s *Server) CreateAccessToken(claims *Claims) *jwt.Token

func (*Server) CreateRefreshToken

func (s *Server) CreateRefreshToken(accessToken *jwt.Token) *jwt.Token

func (*Server) CreateToken

func (s *Server) CreateToken(claims *Claims) *jwt.Token

func (*Server) CreateTokenPair

func (s *Server) CreateTokenPair(claims *Claims) (atks, rtks string, err error)

func (*Server) Refresh

func (s *Server) Refresh(w http.ResponseWriter, r *http.Request)

func (*Server) Register

func (s *Server) Register() (clientID, clientSecret string)

Register creates a clientID and clientSecret that can be used for authentication.

func (*Server) ResolveReference

func (s *Server) ResolveReference(u *url.URL) string

func (*Server) Sign

func (s *Server) Sign(token *jwt.Token) (tks string, err error)

func (*Server) Status

func (s *Server) Status(w http.ResponseWriter, r *http.Request)

func (*Server) URL

func (s *Server) URL() string

Jump to

Keyboard shortcuts

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