modulepackage
0.0.0-20150221011304-383220cdf334
Repository: https://github.com/martini-contrib/oauth2.git
Documentation: pkg.go.dev
# README
oauth2 
Allows your Martini application to support user login via an OAuth 2.0 backend. Requires sessions
middleware. Google, Facebook, LinkedIn and Github sign-in are currently supported. Once endpoints are provided, this middleware can work with any OAuth 2.0 backend.
Usage
See example_test.go
for a sample.
If a route requires login, you can add oauth2.LoginRequired
to the handler chain. If user is not logged, they will be automatically redirected to the login path.
m.Get("/login-required", oauth2.LoginRequired, func() ...)
Auth flow
/login
will redirect user to the OAuth 2.0 provider's permissions dialog. If there is anext
query param provided, user is redirected to the next page afterwards.- If user agrees to connect, OAuth 2.0 provider will redirect to
/oauth2callback
to let your app to make the handshake. You need to register/oauth2callback
as a Redirect URL in your application settings. /logout
will log the user out. If there is anext
query param provided, user is redirected to the next page afterwards.
You can customize the login, logout, oauth2callback and error paths:
oauth2.PathLogin = "/oauth2login"
oauth2.PathLogout = "/oauth2logout"
...
Authors
# Functions
Facebook returns a new Facebook OAuth 2.0 backend endpoint.
Github returns a new Github OAuth 2.0 backend endpoint.
Google returns a new Google OAuth 2.0 backend endpoint.
LinkedIn returns a new LinkedIn OAuth 2.0 backend endpoint.
NewOAuth2Provider returns a generic OAuth 2.0 backend endpoint.
# Variables
Handler that redirects user to the login page if user is not logged in.
PathCallback is the path to handle callback from OAuth 2.0 backend to exchange credentials.
PathError is the path to handle error cases.
PathLogin is the path to handle OAuth 2.0 logins.
PathLogout is the path to handle OAuth 2.0 logouts.
# Interfaces
Tokens represents a container that contains user's OAuth 2.0 access and refresh tokens.