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
- Variables
- func HandleAuthorize(o Handler, t token.Source) http.Handler
- func HandleOAuth2Callback(o Handler, t token.Source, userStore models.UserStore) http.Handler
- func LogOut() http.Handler
- func SetDemoUser(userName string, t token.Source, userStore models.UserStore) http.Handler
- type GoogleOauth
- type Handler
Constants ¶
const ( // CookieName defines the name of the cookie that web access tokens // will be stored as in web requests. CookieName = "_freyr_" )
Variables ¶
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 ¶
HandleAuthorize accepts HTTP requests to be authorized and redirects the user to the Oauth providers authorization URL.
func HandleOAuth2Callback ¶
HandleOAuth2Callback handles verification of Oauth redirects from Oauth provider's and ensuring the redirected request is valid and was initiated by the system.
Types ¶
type GoogleOauth ¶
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 ¶
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 ¶
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.