facebook

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 8 Imported by: 17

Documentation

Overview

Package facebook provides Facebook OAuth2 login and callback handlers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnableToGetFacebookUser = errors.New("facebook: unable to get Facebook User")
)

Facebook login errors

Functions

func CallbackHandler

func CallbackHandler(config *oauth2.Config, success, failure http.Handler) http.Handler

CallbackHandler handles Facebook redirection URI requests and adds the Facebook access token and User to the ctx. If authentication succeeds, handling delegates to the success handler, otherwise to the failure handler.

func LoginHandler

func LoginHandler(config *oauth2.Config, failure http.Handler) http.Handler

LoginHandler handles Facebook login requests by reading the state value from the ctx and redirecting requests to the AuthURL with that state value.

func StateHandler

func StateHandler(config gologin.CookieConfig, success http.Handler) http.Handler

StateHandler checks for a state cookie. If found, the state value is read and added to the ctx. Otherwise, a non-guessable value is added to the ctx and to a (short-lived) state cookie issued to the requester.

Implements OAuth 2 RFC 6749 10.12 CSRF Protection. If you wish to issue state params differently, write a http.Handler which sets the ctx state, using oauth2 WithState(ctx, state) since it is required by LoginHandler and CallbackHandler.

func WithUser

func WithUser(ctx context.Context, user *User) context.Context

WithUser returns a copy of ctx that stores the Facebook User.

Types

type User

type User struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

User is a Facebook user.

Note that user ids are unique to each app.

func UserFromContext

func UserFromContext(ctx context.Context) (*User, error)

UserFromContext returns the Facebook User from the ctx.

Jump to

Keyboard shortcuts

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