Help us shape the future of Go! Take the 2026 Go Developer Survey

testoauth

package
v1.8.1 Latest Latest
Warning

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

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

Documentation

Overview

Package testoauth is a fake OAuth 2.0 authorization and token server for tests, with a stand-in for the user's browser.

Index

Constants

View Source
const (
	ClientID        = "godwit-test"
	DynamicClientID = "godwit-test-dynamic"
	IssuedClientID  = "godwit-test-issued"
)

ClientID is the only client the server knows unless Dynamic(true).

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	URL    string
	Status int
	Body   string
}

Callback is the browser's visit to the app's loopback redirect.

func Get

func Get(t *testing.T, u string) Callback

Get visits a loopback URL as the browser would.

type Server

type Server struct {
	AuthURL, DeviceURL, TokenURL string
	// contains filtered or unexported fields
}

Server issues codes, tokens and unsigned id_tokens. Refresh tokens do not rotate unless RotateRefresh(true).

func Start

func Start(t *testing.T) *Server

Start runs a Server until the test ends.

func (*Server) Approve added in v1.1.0

func (s *Server) Approve(email string)

Approve makes the device-code flow succeed as email on its next poll.

func (*Server) Browse

func (s *Server) Browse(t *testing.T, authURL, email string) Callback

Browse plays the user's browser: it opens authURL, signs in as email and follows the server's redirect to the loopback address.

func (*Server) Config

func (s *Server) Config(scopes ...string) auth.OAuthConfig

Config is an OAuthConfig for this server.

func (*Server) Deny

func (s *Server) Deny(deny bool)

Deny makes the user refuse consent: the server redirects with error=access_denied.

func (*Server) DenyDevice added in v1.1.0

func (s *Server) DenyDevice()

DenyDevice makes the device-code flow answer access_denied.

func (*Server) DeviceConfig added in v1.1.0

func (s *Server) DeviceConfig(scopes ...string) auth.OAuthConfig

DeviceConfig is an OAuthConfig for this server's device-code endpoint.

func (*Server) DeviceExpired added in v1.1.0

func (s *Server) DeviceExpired()

DeviceExpired makes the device-code flow answer expired_token.

func (*Server) Dynamic added in v1.1.0

func (s *Server) Dynamic(on bool)

Dynamic makes the server accept DynamicClientID at /authorize, return client_id=IssuedClientID on the callback, and accept IssuedClientID at /token.

func (*Server) GrantScope added in v1.1.0

func (s *Server) GrantScope(scope string)

GrantScope sets the scope string returned in token responses when non-empty.

func (*Server) Hang

func (s *Server) Hang(t *testing.T) (release func())

Hang makes token requests wait, without an answer, until release is called or the client goes away. release also runs when the test ends.

func (*Server) OmitExpiry

func (s *Server) OmitExpiry(on bool)

OmitExpiry makes token responses leave out expires_in.

func (*Server) Require added in v1.1.0

func (s *Server) Require(param, value string)

Require makes /authorize and /token reject requests missing param=value.

func (*Server) RespondNext

func (s *Server) RespondNext(status int, body string)

RespondNext makes the token endpoint answer its next request with status and a JSON body, whatever was asked.

func (*Server) RevokeAccess

func (s *Server) RevokeAccess()

RevokeAccess invalidates every access token issued so far; refresh tokens still work.

func (*Server) RevokeAll

func (s *Server) RevokeAll()

RevokeAll invalidates every refresh and access token issued so far.

func (*Server) RotateRefresh

func (s *Server) RotateRefresh(on bool)

RotateRefresh makes each refresh issue a new refresh token. The old one stays valid, as Microsoft's do until they expire.

func (*Server) S256Requested

func (s *Server) S256Requested() bool

S256Requested reports whether every authorization request so far asked for code_challenge_method=S256 (false before the first).

func (*Server) SetEmail

func (s *Server) SetEmail(email string)

SetEmail makes later id_tokens name email whoever signed in; "" undoes it.

func (*Server) SlowDownOnce added in v1.1.0

func (s *Server) SlowDownOnce()

SlowDownOnce makes the next device-code poll answer slow_down.

func (*Server) TokenRequests

func (s *Server) TokenRequests() int

TokenRequests is how many requests the token endpoint has received.

func (*Server) ValidAccess

func (s *Server) ValidAccess(token string) bool

ValidAccess reports whether token is a live access token.

func (*Server) VerifierChecked

func (s *Server) VerifierChecked() bool

VerifierChecked reports whether every code exchange so far sent a code_verifier matching its challenge (false before the first).

Jump to

Keyboard shortcuts

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