Documentation ¶
Index ¶
- Constants
- Variables
- func DomainChecker(res http.ResponseWriter, tokens oauth2.Tokens)
- func InitRoutes(m *martini.ClassicMartini, redisConn Doer)
- func InitSession(m *martini.ClassicMartini, rc redisCreds)
- type AuthDeleteHandler
- type AuthGetHandler
- type AuthPostHandler
- type AuthPutHandler
- type Controller
- type Doer
- type GUIDMake
- type GUIDMaker
- type KeyGen
- type KeyGenerator
- type MeGetHandler
- type Response
- type UserMatch
- type ValidateGetHandler
Constants ¶
const ( ClientID = "1083030294947-6g3bhhrgl3s7ul736jet625ajvp94f5p.apps.googleusercontent.com" ClientSecret = "kfgM5mT3BqPQ84VeXsYokAK_" AuthFailStatus = 403 )
Constants to construct my oauth calls
const ( //HMFieldActive - name of metadata hash field containing active status HMFieldActive = "active" //HMFieldDetails - name of metadata hash field containing user and key details HMFieldDetails = "details" )
const ( UserParam = "user" APIVersion1 = "v1" AuthGroup = "auth" APIKeys = "/api-keys" ValidKeyCheck = "/valid-key" StaticPath = "public" )
Constants to construct routes with
const ( //GUIDLength - length of valid key GUIDLength = 36 //HeaderKeyName - header keyname for api-key value HeaderKeyName = "X-API-KEY" //FailStatusCode - statuscode of failed request FailStatusCode = 403 //SuccessStatusCode - statuscode of successful request SuccessStatusCode = 200 //ErrInvalidKeyFormatMsg - error msg for invalid key ErrInvalidKeyFormatMsg = "Invalid key format" )
Variables ¶
var ( Scopes = []string{"https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/userinfo.email"} AuthFailureResponse = []byte(`{"error": "not logged in as a valid user, or the access token is expired"}`) OauthConfig *goauth2.Config )
Vars for my oauth calls
var ( //ErrUnparsableHash - an error for a hash that is not formed properly ErrUnparsableHash = errors.New("Could not parse the hash or hash was nil") //ErrEmptyKeyResponse - an error for a invalid or empty key ErrEmptyKeyResponse = errors.New("The key could not be found or was not valid") )
var ( APIKey = fmt.Sprintf("/api-key/:%s", UserParam) URLAuthBaseV1 = fmt.Sprintf("/%s/%s", APIVersion1, AuthGroup) )
formatted strings based on constants, to be used in URLs
var DomainCheck = func() martini.Handler { return DomainChecker }()
DomainCheck - a handler to check if we are in a valid domain
var (
ErrInvalidCallerEmail = errors.New("Invalid user token for your requested action")
)
Authentication Handler vars
var (
ErrNotValidActionForUser = errors.New("not a valid user to perform this action")
)
UserMatch exported vars
var GetUserInfo = func(tokens oauth2.Tokens) (userObject map[string]interface{}) { url := "https://www.googleapis.com/plus/v1/people/me" token := &goauth2.Token{ AccessToken: tokens.Access(), TokenType: "Bearer", RefreshToken: tokens.Refresh(), Expiry: tokens.ExpiryTime(), } client := OauthConfig.Client(goauth2.NoContext, token) resp, _ := client.Get(url) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) json.Unmarshal(body, &userObject) return }
GetUserInfo - query googleapi for the authenticated users information
Functions ¶
func DomainChecker ¶
func DomainChecker(res http.ResponseWriter, tokens oauth2.Tokens)
DomainChecker - check the authenticated users domain to see if it is in the whitelist
func InitRoutes ¶
func InitRoutes(m *martini.ClassicMartini, redisConn Doer)
InitRoutes - initialize the mappings for controllers against valid routes
func InitSession ¶
func InitSession(m *martini.ClassicMartini, rc redisCreds)
InitSession - initializes authentication middleware for controllers
Types ¶
type AuthDeleteHandler ¶
type AuthDeleteHandler func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens)
AuthDeleteHandler - auth control handler for delete calls
type AuthGetHandler ¶
type AuthGetHandler func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens)
AuthGetHandler - auth control handler for get calls
type AuthPostHandler ¶
type AuthPostHandler func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens)
AuthPostHandler - auth control handler for post calls
type AuthPutHandler ¶
type AuthPutHandler func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens)
AuthPutHandler - auth control handler for put calls
type Controller ¶
type Controller interface { Put() interface{} Post() interface{} Get() interface{} Delete() interface{} }
Controller - interface of a base controller
func NewAuthKeyV1 ¶
func NewAuthKeyV1(kg KeyGenerator) Controller
NewAuthKeyV1 - get an instance of a V1 authkey controller
func NewMeController ¶
func NewMeController() Controller
NewMeController - a controller for me requests
func NewValidateV1 ¶
func NewValidateV1(kg KeyGenerator) Controller
NewValidateV1 - create a validation controller
type GUIDMaker ¶
type GUIDMaker interface {
Create() string
}
GUIDMaker - interface for a guid maker
type KeyGen ¶
type KeyGen struct {
// contains filtered or unexported fields
}
KeyGen - and implementation of the KeyGenerator interface
type KeyGenerator ¶
type KeyGenerator interface { Get(user string) (string, error) GetByKey(key string) (hash string, val interface{}, err error) Create(user, details string) error Delete(user string) error }
KeyGenerator - interface to work with apikeys
func NewKeyGen ¶
func NewKeyGen(doer Doer, guid GUIDMaker) KeyGenerator
NewKeyGen - create a new implementation of a KeyGenerator interface
type MeGetHandler ¶
MeGetHandler - a get control handler for me requests
type UserMatch ¶
type UserMatch struct {
// contains filtered or unexported fields
}
UserMatch - an object used to check if a user is updating the records on a user key they are able to access
func NewUserMatch ¶
func NewUserMatch() *UserMatch
NewUserMatch - creates a new usermatch struct pointer