Documentation ¶
Overview ¶
Based on https://github.com/markbates/goth/blob/edc3e96387cb58c3f3d58e70db2f115815ccdf1e/gothic/gothic.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CompleteUserAuth = func(ectx echo.Context) (goth.User, error) { defer func() { _ = Logout(ectx) }() providerName, err := GetProviderName(ectx) if err != nil { return goth.User{}, err } provider, err := goth.GetProvider(providerName) if err != nil { return goth.User{}, err } value, err := GetFromSession(providerName, ectx) if err != nil { return goth.User{}, err } sess, err := provider.UnmarshalSession(value) if err != nil { return goth.User{}, err } err = validateState(ectx, sess) if err != nil { return goth.User{}, err } user, err := provider.FetchUser(sess) if err == nil { return user, err } params := ectx.Request().URL.Query() if params.Encode() == "" && ectx.Request().Method == "POST" { err = ectx.Request().ParseForm() if err != nil { return goth.User{}, err } params = ectx.Request().Form } _, err = sess.Authorize(provider, params) if err != nil { return goth.User{}, err } err = StoreInSession(providerName, sess.Marshal(), ectx) if err != nil { return goth.User{}, err } gu, err := provider.FetchUser(sess) return gu, err }
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".
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(ectx echo.Context) string { return gothic.GetState(ectx.Request()) }
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 SetState = func(ectx echo.Context) string { return gothic.SetState(ectx.Request()) }
SetState sets the state string associated with the given request. If no state string is associated with the request, one will be generated. This state is sent to the provider and can be retrieved during the callback.
Functions ¶
func BeginAuthHandler ¶
func BeginAuthHandler(ectx echo.Context) error
BeginAuthHandler is a convenience 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.
func GetAuthURL ¶
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 GetFromSession ¶
GetFromSession retrieves a previously-stored value from the session. If no value has previously been stored at the specified key, it will return an error.
func StoreInSession ¶
StoreInSession stores a specified key/value pair in the session.
Types ¶
This section is empty.