Documentation ¶
Overview ¶
Package goat implements a native Go oauth access token server.
The expected flow for this server:
1. Client requests an access token for a provider, say, "google", for the current user.
2. The goat server returns an access token (or an empty string if one isn't available)
3. If an access token is not available, the client sends the browser to /google/url?redirect_url=something on the goat server.
4. The goat server redirects to the consent page for the provider ("google"). Once consent succeeds, the server then redirects the browser to the redirect URL configured for the provider which souuld be the goat server.
5. When redirected from the provider, the goat server gets the access token via standard oauth2 flows. This is then saved to its secure storage. The goat server than redirects to the URI provided in step3.
6. The client gets the redirect to this page and starts with step 1 which shoudl now succeed.
Session & Secure Storage
The goat server requries three components for security:
1. A session storage to hold the state parameter to prevent CSRF attacks.
2. An token storage to store encrypted tokens.
3. An encrpyption engine to encrypt/decrypt tokens.
Example implementations for these are available in sub-directories.
An example that puts this together is available in the cmd/goat example.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncrypterDecrypter ¶
type EncrypterDecrypter interface { Encrypt(ctx context.Context, data []byte) ([]byte, error) Decrypt(ctx context.Context, data []byte) ([]byte, error) }
EncrypterDecrypter is the interface to be implemented by an encryption engine.
type Handler ¶
type Handler struct { // Providers contains the list of providers. Providers []*Provider // AuthenticatedUser is a function that checks that the // request is authenticated and gets the identity of the // requester. All Goat requests must be authenticated. AuthenticatedUser func(r *http.Request) (string, error) // Tokens is the token storage. All the tokens are encrypted // before-hand and so this does not require special handling // for security. Tokens TokenStore // Sessions is used to take a random nonce to prevent CSRF // attacks. It is a transient store. Sessions SessionStore // Secrets provides the encryption/description support. Secrets EncrypterDecrypter }
Handler is a http.Handler that serves all the http requests.
type Paths ¶
type Paths struct { // Consent specifies the path for consent requests. These get // redirected to the aouth2 provider's auth URL // // Requests to the consent URL require a redirect_url // parameter that is used to redirect to after completion of // the full consent flow. Consent string // Code specifies the path configured as the RedirectURL with // the oauth provider. This is expected to contain the code // that can be exchanged for the auth token. Code string // SetRefreshToken specifies the path where SetRefreshToken // requests happen. The refresh_token parameter (query or form // value) should hold the actual refresh token. This is first // validated and so must be a real refresh token. SetRefreshToken string // GetAccessToken specifies the path where the acess token can // be fetched from. The response is a JSON with valid // refresh_token field or an empth hash (indicating no // credentials available). GetAccessToken string }
Paths contains the paths for a single provider.
type Provider ¶
type Provider struct { // Name of the provider. Used with TokenStore & SessionStore Name string // Config should specify endpoints and such oauth2.Config // UsePKCE specifies that the provider users PKCE. UsePKCE bool // Paths should specify the endpoints for the Goat // server. This should be unique and not shared between // providers. Paths Paths // AuthURLParams specifies additional auth url options. // Offline access is included automatically. AuthURLParams map[string]string }
Provider specifies a specific oauth provider + associated config.
type SessionStore ¶
type SessionStore interface { Get(ctx context.Context, provider, nonce string) ([]byte, error) Set(ctx context.Context, provider, nonce string, session []byte) error }
SessionStore is the interface a session store must implement. It is a simple key value store.
Note:
The session store should expire the values quickly (1m is recommended).
The sesion store should also delete the keys once they are fetched. That is, all Get calls should effectively also delete immediately.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
goat
This command demonstrates how to run a goat server.
|
This command demonstrates how to run a goat server. |
Package secrets implements goat secret encryption/decryption.
|
Package secrets implements goat secret encryption/decryption. |
Package sessions implements a session store for goat.
|
Package sessions implements a session store for goat. |