Documentation
¶
Overview ¶
Package Tothic wraps Gothic behaviour for multi-tenant usage. Package gothic wraps common behaviour when using Goth. This makes it quick, and easy, to get up and running with Goth. Of course, if you want complete control over how things flow, in regards to the authentication process, feel free and use Goth directly.
See https://github.com/markbates/goth/examples/main.go to see this in action.
Index ¶
- Constants
- Variables
- func BeginAuthHandler(res http.ResponseWriter, req *http.Request, toth *toth.TothInstance, ...)
- func GetAuthURL(res http.ResponseWriter, req *http.Request, toth *toth.TothInstance, ...) (string, error)
- func KeyFromEnv() (key string)
- func SetParamsStoreHandler(newParamsStore tap.AuthRegisterBackend)
- func SetPathParams(newPathParams map[string]string, profile tap.Profile)
- func SetupSessionStore()
- type PathParam
Constants ¶
const EnvPrefix = "TYK_IB"
const SessionName = "_gothic_session"
SessionName is the key used to access the session store.
Variables ¶
var CompleteUserAuth = func(res http.ResponseWriter, req *http.Request, toth *toth.TothInstance, profile tap.Profile, jweHandler *jwe.Handler) (goth.User, error) { providerName, err := GetProviderName(profile) if err != nil { return goth.User{}, err } provider, err := toth.GetProvider(providerName) if err != nil { return goth.User{}, err } session, err := Store.Get(req, SessionName) if err != nil { return goth.User{}, errors.New("cannot get session store") } if session.Values[SessionName] == nil { return goth.User{}, errors.New("could not find a matching session for this request") } sess, err := provider.UnmarshalSession(session.Values[SessionName].(string)) if err != nil { return goth.User{}, err } _, err = sess.Authorize(provider, req.URL.Query()) if err != nil { return goth.User{}, err } JWTSession, err := prepareJWTSession(sess, jweHandler) if err != nil { return goth.User{}, err } return provider.FetchUser(JWTSession) }
CompleteUserAuth does what it says on the tin. It completes the authentication process and fetches all of the basic information about the user from the provider.
It expects to be able to get the name of the provider from the query parameters as either "provider" or ":provider".
See https://github.com/markbates/goth/examples/main.go to see this in action.
var GetProviderName = getProviderName
GetProviderName is a function used to get the name of a provider for a given request. By default, this provider is fetched from the URL query string. If you provide it in a different way, assign your own function to this variable that returns the provider name for your request.
var GetState = func(req *http.Request) string { params := req.URL.Query() state := params.Get("state") if state == "" && req.Method == http.MethodPost { state = req.FormValue("state") } if state == "" { state = "state" } return state }
GetState gets the state returned by the provider during the callback. This is used to prevent CSRF attacks, see http://tools.ietf.org/html/rfc6749#section-10.12
var Store sessions.Store
Store can/should be set by applications using gothic. The default is a cookie store.
var TothErrorHandler func(string, string, error, int, http.ResponseWriter, *http.Request)
Functions ¶
func BeginAuthHandler ¶
func BeginAuthHandler(res http.ResponseWriter, req *http.Request, toth *toth.TothInstance, pathParams map[string]string, profile tap.Profile)
BeginAuthHandler is a convienence handler for starting the authentication process. It expects to be able to get the name of the provider from the query parameters as either "provider" or ":provider".
BeginAuthHandler will redirect the user to the appropriate authentication end-point for the requested provider.
See https://github.com/markbates/goth/examples/main.go to see this in action.
func GetAuthURL ¶
func GetAuthURL(res http.ResponseWriter, req *http.Request, toth *toth.TothInstance, profile tap.Profile) (string, error)
GetAuthURL starts the authentication process with the requested provided. It will return a URL that should be used to send users to.
It expects to be able to get the name of the provider from the query parameters as either "provider" or ":provider".
I would recommend using the BeginAuthHandler instead of doing all of these steps yourself, but that's entirely up to you.
func KeyFromEnv ¶
func KeyFromEnv() (key string)
func SetParamsStoreHandler ¶ added in v1.1.0
func SetParamsStoreHandler(newParamsStore tap.AuthRegisterBackend)
func SetPathParams ¶ added in v1.1.0
func SetupSessionStore ¶ added in v1.5.0
func SetupSessionStore()