Documentation ¶
Index ¶
- Variables
- func GetTokenInfo(token *oauth2.Token) (string, error)
- type Authenticator
- func (a *Authenticator) Client(ctx context.Context, token *oauth2.Token) *http.Client
- func (a *Authenticator) GetToken(r *http.Request) (*oauth2.Token, error)
- func (a *Authenticator) HandleCallback(w http.ResponseWriter, r *http.Request)
- func (a *Authenticator) Handler(handler HandlerWithToken) http.Handler
- func (a *Authenticator) Start(w http.ResponseWriter, r *http.Request, destinationPath string) error
- type HandlerWithToken
Constants ¶
This section is empty.
Variables ¶
var ErrNotAuthenticated = errors.New("googlelogin: not authenticated")
Either there is no saved token, or the cookie has expired.
var ErrTokenExpired = errors.New("googlelogin: oauth2 token expired")
Functions ¶
func GetTokenInfo ¶
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) 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 ¶
HandlerWithToken handles an HTTP request with a required OAuth2 token. This makes it explicit that this handler does not function without authentication.