oauth2: github.com/dougbarrett/oauth2 Index | Files

package oauth2

import "github.com/dougbarrett/oauth2"

Package oauth2 contains Martini handlers to provide user login via an OAuth 2.0 backend.


Package Files



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"
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() ... {})

func Facebook Uses

func Facebook(opts *Options) martini.Handler

func Github Uses

func Github(opts *Options) martini.Handler

Returns a new Github OAuth 2.0 backend endpoint.

func Google Uses

func Google(opts *Options) martini.Handler

Returns a new Google OAuth 2.0 backend endpoint.

func LinkedIn Uses

func LinkedIn(opts *Options) martini.Handler

func NewOAuth2Provider Uses

func NewOAuth2Provider(opts *Options) martini.Handler

Returns a generic OAuth 2.0 backend endpoint.

type Options Uses

type Options struct {
    ClientId     string
    ClientSecret string
    RedirectURL  string
    Scopes       []string

    AuthUrl  string
    TokenUrl string

Represents OAuth2 backend options.

type Tokens Uses

type Tokens interface {
    Access() string
    Refresh() string
    IsExpired() bool
    ExpiryTime() time.Time
    ExtraData() map[string]string

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

Package oauth2 imports 9 packages (graph). Updated 2016-07-19. Refresh now. Tools for package owners.