optest

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JwtAccessTokenType sets the access token to be a JWT.
	JwtAccessTokenType = iota
	// OpaqueAccessTokenType sets the access token to be opaque.
	OpaqueAccessTokenType
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenType added in v0.0.31

type AccessTokenType int

AccessTokenType defines the type of token to be used.

type Metadata

type Metadata struct {
	Issuer                 string   `json:"issuer"`
	AuthorizationEndpoint  string   `json:"authorization_endpoint"`
	TokenEndpoint          string   `json:"token_endpoint"`
	JwksUri                string   `json:"jwks_uri"`
	ResponseTypesSupported []string `json:"response_types_supported"`
	UserinfoEndpoint       string   `json:"userinfo_endpoint"`
}

Metadata contains the information exposed through `/.well-known/openid-configuration`.

type OPTest

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

OPTest is the struct used for the test OpenID Provider.

func New

func New(setters ...Option) (*OPTest, error)

New sets up a new test OpenID Provider.

func (*OPTest) Close

func (op *OPTest) Close()

Close shuts down the http server.

func (*OPTest) GetRouter

func (op *OPTest) GetRouter() *http.ServeMux

GetRouter returns the router to be used by a http server.

func (*OPTest) GetToken

func (op *OPTest) GetToken() (*TokenResponse, error)

GetToken returns a TokenResponse with an id_token and an access_token for the default test user.

func (*OPTest) GetTokenByUser added in v0.0.30

func (op *OPTest) GetTokenByUser(id string, nonce string) (*TokenResponse, error)

GetTokenByUser returns a TokenResponse with an id_token and an access_token for the specified user.

func (*OPTest) GetURL

func (op *OPTest) GetURL() string

GetURL returns the current URL of the http server.

func (*OPTest) RotateKeys

func (op *OPTest) RotateKeys() error

RotateKeys rotates the jwks keys.

func (*OPTest) Start

func (op *OPTest) Start()

Start starts the http server if AutoStart was disabled.

type OPTesting

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

OPTesting is a wrapper for the OPTest to be used in tests.

func NewTesting

func NewTesting(tb testing.TB, setters ...Option) *OPTesting

NewTesting sets up a new test OpenID Provider.

func (*OPTesting) Close

func (o *OPTesting) Close(tb testing.TB)

Close shuts down the http server.

func (*OPTesting) GetRouter

func (o *OPTesting) GetRouter(tb testing.TB) *http.ServeMux

GetRouter returns the router to be used by a http server.

func (*OPTesting) GetToken

func (o *OPTesting) GetToken(tb testing.TB) *TokenResponse

GetToken returns a TokenResponse with an id_token and an access_token for the default test user.

func (*OPTesting) GetTokenByUser added in v0.0.30

func (o *OPTesting) GetTokenByUser(tb testing.TB, userString string) *TokenResponse

GetTokenByUser returns a TokenResponse with an id_token and an access_token for the specified user.

func (*OPTesting) GetURL

func (o *OPTesting) GetURL(tb testing.TB) string

GetURL returns the current URL of the http server.

func (*OPTesting) RotateKeys

func (o *OPTesting) RotateKeys(tb testing.TB)

RotateKeys rotates the jwks keys.

func (*OPTesting) Start

func (o *OPTesting) Start(tb testing.TB)

Start starts the http server if AutoStart was disabled.

type Option

type Option func(*Options)

Option is used to configure functional options for OPTest.

func WithDefaultTestUser added in v0.0.30

func WithDefaultTestUser(opt string) Option

WithDefaultTestUser configures the default test user, needs to match one of the users provided in `WithTestUsers()`. Defaults to the addr of the http server.

func WithIssuer

func WithIssuer(opt string) Option

WithIssuer configures the issuer claim for tokens and addresses in metadata. Defaults to the addr of the http server.

func WithLoginPrompt added in v0.0.38

func WithLoginPrompt() Option

WithLoginPrompt enables login prompt if there are more than one Test User. Default is login prompt disabled.

func WithOpaqueAccessTokens added in v0.0.31

func WithOpaqueAccessTokens() Option

WithOpaqueAccessTokens enables opaque access tokens. Default is access tokens as JWT.

func WithTestUsers added in v0.0.30

func WithTestUsers(opt map[string]TestUser) Option

WithTestUsers configures the users that can be used to issue tokens. Defaults to a single test user named `test`.

func WithTokenExpiration

func WithTokenExpiration(opt time.Duration) Option

WithTokenExpiration configures the expiration for tokens. Default: 1 hour (3600 seconds).

func WithoutAutoStart

func WithoutAutoStart() Option

WithoutAutoStart disables the autostart of the http server. Default is AutoStart enabled.

type Options

type Options struct {
	Issuer             string
	DefaultTestUser    string
	TestUsers          map[string]TestUser
	TokenExpiration    time.Duration
	AutoStart          bool
	AccessTokenType    AccessTokenType
	LoginPromptEnabled bool
}

Options is the configuration object for OPTest.

type TestUser added in v0.0.30

type TestUser struct {
	Audience               string
	Subject                string
	Name                   string
	GivenName              string
	FamilyName             string
	Locale                 string
	Email                  string
	AccessTokenKeyType     string
	IdTokenKeyType         string
	ExtraIdTokenClaims     map[string]interface{}
	ExtraAccessTokenClaims map[string]interface{}
}

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	IdToken     string `json:"id_token"`
	Expiry      time.Time
}

TokenResponse contains the token endpoint response data.

func (*TokenResponse) SetAuthHeader

func (t *TokenResponse) SetAuthHeader(r *http.Request)

SetAuthHeader adds the access_token to the `Authorization` header of the request.

func (*TokenResponse) Valid

func (t *TokenResponse) Valid() bool

Valid returns true if the token exists and isn't expired.

Jump to

Keyboard shortcuts

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