oauthtest

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package oauthtest provides an in-memory OAuth 2.1 authorization server for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	*httptest.Server

	Codes       map[string]string // code -> expected code_verifier
	Refresh     map[string]bool   // live refresh tokens
	Revoked     []string
	DevicePolls int32
	// DeviceAnswers is consumed in order by device token polls: "authorization_pending", "slow_down", "access_denied" or "ok"
	DeviceAnswers []string
	TokenCalls    int32
	NoOAuth       bool // discovery answers 404
	// AcceptAnyVerifier accepts a registered code with any non-empty code_verifier (the verifier is generated by the code under test).
	AcceptAnyVerifier bool
	// NoRevocation omits revocation_endpoint from the discovery document.
	NoRevocation bool
	// TokenStatus, when non-zero, makes the token endpoint answer this status with temporarily_unavailable.
	TokenStatus int
	// KeepRefresh makes refresh grants answer without a refresh_token and keep the presented one live (no rotation).
	KeepRefresh bool
	// contains filtered or unexported fields
}

Server is a fake Webda OAuth server: discovery, token (code, refresh with rotation, device), revoke, device_authorization.

func New

func New() *Server

New starts a fake server; callers must Close it.

func (*Server) CurrentAccessToken

func (s *Server) CurrentAccessToken() string

CurrentAccessToken returns the last access token issued ("" before any).

func (*Server) Handle

func (s *Server) Handle(pattern string, h http.Handler)

Handle registers an extra handler (for example a protected API route) on the fake server.

Jump to

Keyboard shortcuts

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