Documentation ¶
Overview ¶
Package oauth2 contains Martini handlers to provide user login via an OAuth 2.0 backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Path to handle OAuth 2.0 logins. PathLogin = "/login" // Path to handle OAuth 2.0 logouts. PathLogout = "/logout" // Path to handle callback from OAuth 2.0 backend // to exchange credentials. PathCallback = "/oauth2callback" // Path to handle error cases. PathError = "/oauth2error" )
View Source
var LoginRequired martini.Handler = func() martini.Handler { return func(s sessions.Session, c martini.Context, w http.ResponseWriter, r *http.Request) { token := unmarshallToken(s) if token == nil || token.IsExpired() { next := url.QueryEscape(r.URL.RequestURI()) http.Redirect(w, r, PathLogin+"?next="+next, codeRedirect) } } }()
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 ¶
Returns a generic OAuth 2.0 backend endpoint.
Types ¶
Click to show internal directories.
Click to hide internal directories.