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
- type Callback
- type Server
- func (s *Server) Approve(email string)
- func (s *Server) Browse(t *testing.T, authURL, email string) Callback
- func (s *Server) Config(scopes ...string) auth.OAuthConfig
- func (s *Server) Deny(deny bool)
- func (s *Server) DenyDevice()
- func (s *Server) DeviceConfig(scopes ...string) auth.OAuthConfig
- func (s *Server) DeviceExpired()
- func (s *Server) Dynamic(on bool)
- func (s *Server) GrantScope(scope string)
- func (s *Server) Hang(t *testing.T) (release func())
- func (s *Server) OmitExpiry(on bool)
- func (s *Server) Require(param, value string)
- func (s *Server) RespondNext(status int, body string)
- func (s *Server) RevokeAccess()
- func (s *Server) RevokeAll()
- func (s *Server) RotateRefresh(on bool)
- func (s *Server) S256Requested() bool
- func (s *Server) SetEmail(email string)
- func (s *Server) SlowDownOnce()
- func (s *Server) TokenRequests() int
- func (s *Server) ValidAccess(token string) bool
- func (s *Server) VerifierChecked() bool
Constants ¶
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 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 (*Server) Approve ¶ added in v1.1.0
Approve makes the device-code flow succeed as email on its next poll.
func (*Server) Browse ¶
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 ¶
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
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
GrantScope sets the scope string returned in token responses when non-empty.
func (*Server) Hang ¶
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 ¶
OmitExpiry makes token responses leave out expires_in.
func (*Server) Require ¶ added in v1.1.0
Require makes /authorize and /token reject requests missing param=value.
func (*Server) RespondNext ¶
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 ¶
RotateRefresh makes each refresh issue a new refresh token. The old one stays valid, as Microsoft's do until they expire.
func (*Server) S256Requested ¶
S256Requested reports whether every authorization request so far asked for code_challenge_method=S256 (false before the first).
func (*Server) SetEmail ¶
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 ¶
TokenRequests is how many requests the token endpoint has received.
func (*Server) ValidAccess ¶
ValidAccess reports whether token is a live access token.
func (*Server) VerifierChecked ¶
VerifierChecked reports whether every code exchange so far sent a code_verifier matching its challenge (false before the first).