Documentation ¶
Overview ¶
Package oauth2 contains Macaron handlers to provide user login via an OAuth 2.0 backend.
Index ¶
Constants ¶
View Source
const ( KEY_TOKEN = "oauth2_token" KEY_NEXT_PAGE = "next" )
Variables ¶
View Source
var ( // PathLogin is the path to handle OAuth 2.0 logins. PathLogin = "/login" // PathLogout is the path to handle OAuth 2.0 logouts. PathLogout = "/logout" // PathCallback is the path to handle callback from OAuth 2.0 backend // to exchange credentials. PathCallback = "/oauth2callback" // PathError is the path to handle error cases. PathError = "/oauth2error" )
View Source
var LoginRequired = func() macaron.Handler { return func(s session.Store, ctx *macaron.Context) { token := unmarshallToken(s) if token == nil || token.Expired() { next := url.QueryEscape(ctx.Req.URL.RequestURI()) ctx.Redirect(PathLogin + "?next=" + next) } } }()
Handler that redirects user to the login page if user is not logged in. Sample usage: m.Get("/login-required", oauth2.LoginRequired, func() ... {})
Functions ¶
func NewOAuth2Provider ¶
NewOAuth2Provider returns a generic OAuth 2.0 backend endpoint.
Types ¶
Click to show internal directories.
Click to hide internal directories.