oauth2

package module
v0.0.0-...-e827b20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2016 License: Apache-2.0 Imports: 11 Imported by: 2

README

OAuth2

Middleware oauth2 provides support of user login via an OAuth 2.0 backend for Macaron.

Usage

// ...
m.Use(oauth2.Google(
	&goauth2.Config{
		ClientID:     "client_id",
		ClientSecret: "client_secret",
		Scopes:       []string{"https://www.googleapis.com/auth/drive"},
		RedirectURL:  "redirect_url",
	},
))
// ...

Credits

This package is forked from martini-contrib/oauth2 with modifications.

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

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 Facebook

func Facebook(conf *oauth2.Config) macaron.Handler

Facebook returns a new Facebook OAuth 2.0 backend endpoint.

func Github

func Github(conf *oauth2.Config) macaron.Handler

Github returns a new Github OAuth 2.0 backend endpoint.

func Google

func Google(conf *oauth2.Config) macaron.Handler

Google returns a new Google OAuth 2.0 backend endpoint.

func LinkedIn

func LinkedIn(conf *oauth2.Config) macaron.Handler

LinkedIn returns a new LinkedIn OAuth 2.0 backend endpoint.

func NewOAuth2Provider

func NewOAuth2Provider(conf *oauth2.Config) macaron.Handler

NewOAuth2Provider returns a generic OAuth 2.0 backend endpoint.

Types

type Tokens

type Tokens interface {
	Access() string
	Refresh() string
	Expired() bool
	ExpiryTime() time.Time
}

Tokens represents a container that contains user's OAuth 2.0 access and refresh tokens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL