2016-07-25 20:00:28 +00:00
|
|
|
// Package connector defines interfaces for federated identity strategies.
|
|
|
|
package connector
|
|
|
|
|
2016-11-18 21:40:41 +00:00
|
|
|
import (
|
2017-03-08 18:33:19 +00:00
|
|
|
"context"
|
2016-11-18 21:40:41 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
2016-07-25 20:00:28 +00:00
|
|
|
|
|
|
|
// Connector is a mechanism for federating login to a remote identity service.
|
|
|
|
//
|
|
|
|
// Implementations are expected to implement either the PasswordConnector or
|
|
|
|
// CallbackConnector interface.
|
2016-11-18 21:40:41 +00:00
|
|
|
type Connector interface{}
|
|
|
|
|
|
|
|
// Scopes represents additional data requested by the clients about the end user.
|
|
|
|
type Scopes struct {
|
|
|
|
// The client has requested a refresh token from the server.
|
|
|
|
OfflineAccess bool
|
|
|
|
|
|
|
|
// The client has requested group information about the end user.
|
|
|
|
Groups bool
|
2016-07-25 20:00:28 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 04:14:24 +00:00
|
|
|
// Identity represents the ID Token claims supported by the server.
|
|
|
|
type Identity struct {
|
|
|
|
UserID string
|
|
|
|
Username string
|
|
|
|
Email string
|
|
|
|
EmailVerified bool
|
|
|
|
|
2016-11-18 21:40:41 +00:00
|
|
|
Groups []string
|
|
|
|
|
2016-08-03 04:14:24 +00:00
|
|
|
// ConnectorData holds data used by the connector for subsequent requests after initial
|
|
|
|
// authentication, such as access tokens for upstream provides.
|
|
|
|
//
|
|
|
|
// This data is never shared with end users, OAuth clients, or through the API.
|
|
|
|
ConnectorData []byte
|
|
|
|
}
|
|
|
|
|
2016-11-18 21:40:41 +00:00
|
|
|
// PasswordConnector is an interface implemented by connectors which take a
|
|
|
|
// username and password.
|
2016-07-25 20:00:28 +00:00
|
|
|
type PasswordConnector interface {
|
2016-11-18 21:40:41 +00:00
|
|
|
Login(ctx context.Context, s Scopes, username, password string) (identity Identity, validPassword bool, err error)
|
2016-07-25 20:00:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 21:40:41 +00:00
|
|
|
// CallbackConnector is an interface implemented by connectors which use an OAuth
|
|
|
|
// style redirect flow to determine user information.
|
2016-07-25 20:00:28 +00:00
|
|
|
type CallbackConnector interface {
|
2016-11-18 21:40:41 +00:00
|
|
|
// The initial URL to redirect the user to.
|
|
|
|
//
|
|
|
|
// OAuth2 implementations should request different scopes from the upstream
|
|
|
|
// identity provider based on the scopes requested by the downstream client.
|
|
|
|
// For example, if the downstream client requests a refresh token from the
|
|
|
|
// server, the connector should also request a token from the provider.
|
|
|
|
//
|
|
|
|
// Many identity providers have arbitrary restrictions on refresh tokens. For
|
|
|
|
// example Google only allows a single refresh token per client/user/scopes
|
|
|
|
// combination, and wont return a refresh token even if offline access is
|
|
|
|
// requested if one has already been issues. There's no good general answer
|
|
|
|
// for these kind of restrictions, and may require this package to become more
|
|
|
|
// aware of the global set of user/connector interactions.
|
|
|
|
LoginURL(s Scopes, callbackURL, state string) (string, error)
|
|
|
|
|
|
|
|
// Handle the callback to the server and return an identity.
|
|
|
|
HandleCallback(s Scopes, r *http.Request) (identity Identity, err error)
|
2016-07-25 20:00:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 01:24:17 +00:00
|
|
|
// SAMLConnector represents SAML connectors which implement the HTTP POST binding.
|
2017-03-21 20:16:42 +00:00
|
|
|
// RelayState is handled by the server.
|
2016-12-21 01:24:17 +00:00
|
|
|
//
|
2017-03-21 20:16:42 +00:00
|
|
|
// See: https://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf
|
|
|
|
// "3.5 HTTP POST Binding"
|
2016-12-21 01:24:17 +00:00
|
|
|
type SAMLConnector interface {
|
|
|
|
// POSTData returns an encoded SAML request and SSO URL for the server to
|
|
|
|
// render a POST form with.
|
2017-03-21 20:16:42 +00:00
|
|
|
//
|
|
|
|
// POSTData should encode the provided request ID in the returned serialized
|
|
|
|
// SAML request.
|
|
|
|
POSTData(s Scopes, requestID string) (sooURL, samlRequest string, err error)
|
2016-12-21 01:24:17 +00:00
|
|
|
|
2017-03-21 20:16:42 +00:00
|
|
|
// HandlePOST decodes, verifies, and maps attributes from the SAML response.
|
|
|
|
// It passes the expected value of the "InResponseTo" response field, which
|
|
|
|
// the connector must ensure matches the response value.
|
2016-12-21 01:24:17 +00:00
|
|
|
//
|
|
|
|
// See: https://www.oasis-open.org/committees/download.php/35711/sstc-saml-core-errata-2.0-wd-06-diff.pdf
|
|
|
|
// "3.2.2 Complex Type StatusResponseType"
|
2017-03-21 20:16:42 +00:00
|
|
|
HandlePOST(s Scopes, samlResponse, inResponseTo string) (identity Identity, err error)
|
2016-12-21 01:24:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 21:40:41 +00:00
|
|
|
// RefreshConnector is a connector that can update the client claims.
|
|
|
|
type RefreshConnector interface {
|
|
|
|
// Refresh is called when a client attempts to claim a refresh token. The
|
|
|
|
// connector should attempt to update the identity object to reflect any
|
|
|
|
// changes since the token was last refreshed.
|
|
|
|
Refresh(ctx context.Context, s Scopes, identity Identity) (Identity, error)
|
2016-07-25 20:00:28 +00:00
|
|
|
}
|