googlelogin

package
v0.0.0-...-2071987 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAuthenticated = errors.New("googlelogin: not authenticated")

Either there is no saved token, or the cookie has expired.

View Source
var ErrTokenExpired = errors.New("googlelogin: oauth2 token expired")

Functions

func GetTokenInfo

func GetTokenInfo(token *oauth2.Token) (string, error)

Makes a request to Google's TokenInfo endpoint and returns the payload. Useful for verifying that a token is still valid. If the user explicitly revokes it, Google returns an HTTP error such as 400 Bad Request with additional details in the body (e.g "Invalid Value")

Types

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authenticator obtains access tokens from Google on behalf of an end user web browser.

func New

func New(clientID string, clientSecret string, redirectURL string, scopes []string,
	securecookies *securecookie.SecureCookie, noAuthPath string, mux *http.ServeMux) (
	*Authenticator, error)

New creates a new Authenticator for authenticating users. The clientID, clientSecret, and redirectURL must registered with Google. The scopes list the permissions required by this application. The browser will be redirected to noAuthPath when HandleWithToken and they are not authenticated.

func (*Authenticator) Client

func (a *Authenticator) Client(ctx context.Context, token *oauth2.Token) *http.Client

func (*Authenticator) GetToken

func (a *Authenticator) GetToken(r *http.Request) (*oauth2.Token, error)

Returns the oauth2.Token corresponding to this request.

func (*Authenticator) HandleCallback

func (a *Authenticator) HandleCallback(w http.ResponseWriter, r *http.Request)

func (*Authenticator) Handler

func (a *Authenticator) Handler(handler HandlerWithToken) http.Handler

func (*Authenticator) Start

func (a *Authenticator) Start(w http.ResponseWriter, r *http.Request, destinationPath string) error

Redirects the browser to obtain a new token from Google. TODO: Ensure that this request was CSRF protected? http://www.oauthsecurity.com/ TODO: Verify that this request was a POST?

type HandlerWithToken

type HandlerWithToken func(w http.ResponseWriter, r *http.Request, token *oauth2.Token)

HandlerWithToken handles an HTTP request with a required OAuth2 token. This makes it explicit that this handler does not function without authentication.

Jump to

Keyboard shortcuts

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