testissuer

package
v0.0.0-...-587d70a Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeCode         = "code"
	TypeAccessToken  = "access_token"
	TypeRefreshToken = "refresh_token"
)
View Source
const UserLoginCookie = "oprox_test_issuer_user"

UserLoginCookie specifies the user you want to login with that you dont have to specify the user manually in a test. Also see the Issuer.Login method.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthTokenInfo

type AuthTokenInfo struct {
	Type     string   `json:"type"`
	ClientID string   `json:"client_id"`
	Nonce    string   `json:"nonce"`
	Scope    []string `json:"scope"`
	User     string   `json:"user"`

	// Claims add additional claims or overwrite existing claims. This
	// has to be of type map[string]any or struct.
	Claims any `json:"extra"`
}

AuthTokenInfo is used to keep state between calls

type Config

type Config struct {
	Logger *slog.Logger

	IssuerURL string

	TokenLifetime    time.Duration
	GetUserClaims    UserClaimFunc
	AccessTokenIsJWT bool
}

Config for the Issuer

func NewDefaultConfig

func NewDefaultConfig() *Config

type Issuer

type Issuer struct {
	*Config

	Signer jose.Signer

	ServeMux *http.ServeMux
	// contains filtered or unexported fields
}

Issuer is a test implementation for an OIDC/OAuth2 IDP.

func New

func New(config *Config) (*Issuer, error)

New creates a new test issuer

func (*Issuer) Authz

func (i *Issuer) Authz(w http.ResponseWriter, r *http.Request)

func (*Issuer) GetToken

func (i *Issuer) GetToken(authInfo *AuthTokenInfo) (string, error)

func (*Issuer) JWKS

func (i *Issuer) JWKS(w http.ResponseWriter, r *http.Request)

func (*Issuer) Login

func (i *Issuer) Login(user string, c *http.Client) error

func (*Issuer) MustGetToken

func (i *Issuer) MustGetToken(authInfo *AuthTokenInfo) string

func (*Issuer) OpenIDDiscovery

func (i *Issuer) OpenIDDiscovery(w http.ResponseWriter, r *http.Request)

func (*Issuer) ServeHTTP

func (i *Issuer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Issuer) Token

func (i *Issuer) Token(w http.ResponseWriter, r *http.Request)

type Server

type Server struct {
	*Issuer
	*httptest.Server
}

func NewServer

func NewServer(config *Config) (*Server, error)

NewServer starts a httptest.Server and configures an issuer accordingly. When running NewServer you don't have to supply an IssuerURL in the config becuase it gets set based on the random URL where the httptest.Server started.

type UserClaimFunc

type UserClaimFunc func(user string) map[string]any

UserClaimFunc returns extra claims for a particular user.

func DefaultUserClaims

func DefaultUserClaims() UserClaimFunc

func StaticUserClaims

func StaticUserClaims(userMap map[string]map[string]any) UserClaimFunc

Jump to

Keyboard shortcuts

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