oauth

package
v0.0.0-...-721f978 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2017 License: MIT Imports: 9 Imported by: 3

Documentation

Overview

Package oauth defines methods for handling Three-legged Oauth with various third-parties (e.g. Google) as well as HTTP handlers.

Index

Constants

View Source
const (
	// CookieName defines the name of the cookie that web access tokens
	// will be stored as in web requests.
	CookieName = "_freyr_"
)

Variables

View Source
var (

	// ErrorInvalidClaims is returned when an oauth requests claims do
	// not match that which the system sets.
	ErrorInvalidClaims = errors.New("Claims are invalid")
)

Functions

func HandleAuthorize

func HandleAuthorize(o Handler, t token.Source) http.Handler

HandleAuthorize accepts HTTP requests to be authorized and redirects the user to the Oauth providers authorization URL.

func HandleOAuth2Callback

func HandleOAuth2Callback(o Handler, t token.Source, userStore models.UserStore) http.Handler

HandleOAuth2Callback handles verification of Oauth redirects from Oauth provider's and ensuring the redirected request is valid and was initiated by the system.

func LogOut

func LogOut() http.Handler

LogOut resets the user's JWT web access cookie so their session is no longer valid.

func SetDemoUser

func SetDemoUser(userName string, t token.Source, userStore models.UserStore) http.Handler

SetDemoUser accepts an HTTP request and provides a signed a web access JWT to allow the current site user to view example data in the demo user's account.

Types

type GoogleOauth

type GoogleOauth struct {
	Config *oauth2.Config
}

GoogleOauth defines the OauthHandler interface for use against Google's Oauth api.

func NewGoogleOauth

func NewGoogleOauth(clientID, clientSecret, domain string) *GoogleOauth

NewGoogleOauth is a convenience method for generating a GoogleOauth type with the oauth2.Config initialized.

func (GoogleOauth) GetCallbackCsrfToken

func (g GoogleOauth) GetCallbackCsrfToken(r *http.Request) string

GetCallbackCsrfToken extracts the csrf token from the Oauth redirect url

func (GoogleOauth) GetExchangeToken

func (g GoogleOauth) GetExchangeToken(r *http.Request) (*oauth2.Token, error)

GetExchangeToken extracts the exchange token sent from Google authorizing the system to make requests of a user's basic data.

func (GoogleOauth) GetRedirectURL

func (g GoogleOauth) GetRedirectURL(csrfToken string) string

GetRedirectURL generates the redirect URL with the provided csrf token

func (GoogleOauth) GetUserData

func (g GoogleOauth) GetUserData(tok *oauth2.Token) (user models.User, err error)

GetUserData makes a request of the user's data using the provided access token.

type Handler

type Handler interface {
	GetRedirectURL(csrftoken string) string
	GetCallbackCsrfToken(r *http.Request) string
	GetExchangeToken(r *http.Request) (*oauth2.Token, error)
	GetUserData(tok *oauth2.Token) (models.User, error)
}

Handler is an interface representing types that provide the interface to perform Oauth three-legged authorization against a system such as Google or Twitter.

Jump to

Keyboard shortcuts

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