oauth2

package
v0.0.0-...-dbb2ee5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEndpointWithProvider

func AssertEndpointWithProvider(t *testing.T, provider Provider, url string, method string, options ...RequestOption)

AssertEndpointWithProvider asserts that the given endpoint responds correctly with a token from the provided OAuth2 provider. It checks that requests:

  • without a token return response code 403,
  • with an invalid token return response code 401,
  • with a valid token return response code 200.

Types

type GetTokenOption

type GetTokenOption func(*GetTokenOptions)

func WithAudience

func WithAudience(audience string) GetTokenOption

func WithJWTTokenFormat

func WithJWTTokenFormat() GetTokenOption

func WithOpaqueTokenFormat

func WithOpaqueTokenFormat() GetTokenOption

func WithScope

func WithScope(scope string) GetTokenOption

type GetTokenOptions

type GetTokenOptions struct {
	Scopes    []string
	Format    string
	GrantType string
	Audiences []string
}

type Provider

type Provider interface {
	GetIssuerURL() string
	GetJwksURI() string

	GetToken(t *testing.T, options ...GetTokenOption) (string, error)
	MakeRequest(t *testing.T, method, url string, options ...RequestOption) (statusCode int, responseHeaders map[string][]string, responseBody []byte, err error)
}

type RequestOption

type RequestOption func(*RequestOptions)

func WithGetTokenOption

func WithGetTokenOption(opt GetTokenOption) RequestOption

func WithGetTokenOptions

func WithGetTokenOptions(opt ...GetTokenOption) RequestOption

func WithHeaders

func WithHeaders(headers map[string]string) RequestOption

func WithTokenFromParam

func WithTokenFromParam(param string) RequestOption

func WithTokenHeader

func WithTokenHeader(header string) RequestOption

func WithTokenOverride

func WithTokenOverride(token string) RequestOption

func WithTokenPrefix

func WithTokenPrefix(prefix string) RequestOption

func WithoutToken

func WithoutToken() RequestOption

type RequestOptions

type RequestOptions struct {
	GetTokenOptions []GetTokenOption
	TokenHeader     string
	TokenPrefix     string
	FromParam       string
	WithoutToken    bool
	TokenOverride   string
	WithHeaders     map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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