oauthtest

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package oauthtest provides shared test fixtures for OAuth 2.0 response decoding. It is intended for use by tests in pkg/oauth and by sibling grant packages (token exchange, JWT bearer, etc.) so they share a single canonical response-builder rather than each maintaining a parallel copy that can drift.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponseBuilder

type ErrorResponseBuilder struct {
	ErrorCode        string `json:"error,omitempty"`
	ErrorDescription string `json:"error_description,omitempty"`
	ErrorURI         string `json:"error_uri,omitempty"`
}

ErrorResponseBuilder composes a JSON-encoded OAuth 2.0 error response per RFC 6749 Section 5.2. Fluent setters populate only the listed fields — unset fields are omitted from the JSON output so callers can simulate minimal servers that return only the required error code.

func NewErrorResponse

func NewErrorResponse() *ErrorResponseBuilder

NewErrorResponse returns an empty builder. Tests call WithError at minimum to produce a valid RFC 6749 §5.2 body.

func (*ErrorResponseBuilder) Build

func (b *ErrorResponseBuilder) Build() []byte

Build marshals the builder to JSON. Panics on marshaling errors; the underlying types are simple and failure indicates a programming error in the test itself.

func (*ErrorResponseBuilder) WithDescription

func (b *ErrorResponseBuilder) WithDescription(description string) *ErrorResponseBuilder

WithDescription sets error_description.

func (*ErrorResponseBuilder) WithError

func (b *ErrorResponseBuilder) WithError(code string) *ErrorResponseBuilder

WithError sets the error code (RFC 6749 §5.2 required field).

func (*ErrorResponseBuilder) WithURI

WithURI sets error_uri.

type ResponseBuilder

type ResponseBuilder struct {
	AccessToken     string `json:"access_token,omitempty"`
	TokenType       string `json:"token_type,omitempty"`
	ExpiresIn       int    `json:"expires_in,omitempty"`
	RefreshToken    string `json:"refresh_token,omitempty"`
	IssuedTokenType string `json:"issued_token_type,omitempty"`
	Scope           string `json:"scope,omitempty"`
}

ResponseBuilder composes a JSON-encoded OAuth 2.0 token endpoint success response. Fluent setters leave unset fields as their zero value, matching the behavior of a minimal IdP reply. Build returns the marshaled JSON bytes ready to write into an httptest response.

func NewResponse

func NewResponse() *ResponseBuilder

NewResponse returns a builder pre-populated with a minimal valid RFC 8693 success response (access token, Bearer type, access-token URN for issued type). Tests override any field they care about via the With* setters.

func (*ResponseBuilder) Build

func (b *ResponseBuilder) Build() []byte

Build marshals the builder to JSON. Panics on marshaling errors; the underlying types are simple and failure indicates a programming error in the test itself.

func (*ResponseBuilder) WithAccessToken

func (b *ResponseBuilder) WithAccessToken(token string) *ResponseBuilder

WithAccessToken overrides the access_token field (including the empty string, which lets tests exercise RFC 6749 §5.1 validation).

func (*ResponseBuilder) WithExpiresIn

func (b *ResponseBuilder) WithExpiresIn(seconds int) *ResponseBuilder

WithExpiresIn sets the expires_in field. Zero suppresses the field (omitempty) so callers can assert the no-expiry path.

func (*ResponseBuilder) WithIssuedTokenType

func (b *ResponseBuilder) WithIssuedTokenType(tokenType string) *ResponseBuilder

WithIssuedTokenType sets the RFC 8693 issued_token_type field.

func (*ResponseBuilder) WithRefreshToken

func (b *ResponseBuilder) WithRefreshToken(token string) *ResponseBuilder

WithRefreshToken sets the refresh_token field.

func (*ResponseBuilder) WithScope

func (b *ResponseBuilder) WithScope(scope string) *ResponseBuilder

WithScope sets the scope field (space-separated).

func (*ResponseBuilder) WithTokenType

func (b *ResponseBuilder) WithTokenType(tokenType string) *ResponseBuilder

WithTokenType overrides the token_type field.

Jump to

Keyboard shortcuts

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