pezauth

package
v0.0.85 Latest Latest
Warning

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

Go to latest
Published: May 26, 2015 License: GPL-2.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ClientID     = "1083030294947-6g3bhhrgl3s7ul736jet625ajvp94f5p.apps.googleusercontent.com"
	ClientSecret = "kfgM5mT3BqPQ84VeXsYokAK_"
)

Constants to construct my oauth calls

View Source
const (
	//FailureStatus - failure response status from our unauthenticated rest endpoints
	FailureStatus = 403
	//SuccessStatus - success response status from our authenticated rest endpoints
	SuccessStatus = 200
)
View Source
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"
)
View Source
const (
	UserParam     = "user"
	APIVersion1   = "v1"
	AuthGroup     = "auth"
	OrgGroup      = "org"
	APIKeys       = "/api-keys"
	ValidKeyCheck = "/valid-key"
	StaticPath    = "public"
)

Constants to construct routes with

View Source
const (
	//GUIDLength - length of valid key
	GUIDLength = 36
	//HeaderKeyName - header keyname for api-key value
	HeaderKeyName = "X-API-KEY"
	//ErrInvalidKeyFormatMsg - error msg for invalid key
	ErrInvalidKeyFormatMsg = "Invalid key format"
)
View Source
const (
	//EmailFieldName - fieldname for email
	EmailFieldName = "email"
)

Variables

View Source
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

View Source
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")
)
View Source
var (
	//ErrNoMatchInStore - error when there is no matching org in the datastore
	ErrNoMatchInStore = errors.New("Could not find a matching user org or connection failure")
	//ErrCanNotCreateOrg - error when we can not create an org
	ErrCanNotCreateOrg = errors.New("Could not create a new org")
	//ErrCanNotAddOrgRec - error when we can not add a new org record to the datastore
	ErrCanNotAddOrgRec = errors.New("Could not add a new org record")
	//ErrCantCallAcrossUsers - error when a user is trying to update a user record other than their own
	ErrCantCallAcrossUsers = errors.New("user calling another users endpoint")
)
View Source
var (
	APIKey        = fmt.Sprintf("/api-key/:%s", UserParam)
	OrgUser       = fmt.Sprintf("/user/:%s", UserParam)
	URLAuthBaseV1 = fmt.Sprintf("/%s/%s", APIVersion1, AuthGroup)
	URLOrgBaseV1  = fmt.Sprintf("/%s/%s", APIVersion1, OrgGroup)
)

formatted strings based on constants, to be used in URLs

View Source
var DomainCheck = func() martini.Handler {
	return DomainChecker
}()

DomainCheck - a handler to check if we are in a valid domain

View Source
var (
	ErrCouldNotGetUserGUID = errors.New("query failed. unable to find matching user guid.")
)
View Source
var (
	ErrInvalidCallerEmail = errors.New("Invalid user token for your requested action")
)

Authentication Handler vars

View Source
var (
	ErrNotValidActionForUser = errors.New("not a valid user to perform this action")
)

UserMatch exported vars

View Source
var GetUserInfo = func(tokens oauth2.Tokens) (userObject map[string]interface{}) {

	if userObject = getUserInfoCached(tokens); len(userObject) == 0 {
		userObject = getUserInfo(tokens)
	}
	return
}

GetUserInfo - query googleapi for the authenticated users information

View Source
var NewOrg = func(username string, log *log.Logger, tokens oauth2.Tokens, store Persistence, authClient AuthRequestCreator) OrgManager {
	s := &orgManager{
		username: username,
		log:      log,
		tokens:   tokens,
		store:    store,
		cfClient: cloudfoundryclient.NewCloudFoundryClient(authClient, log),
	}
	return s
}

NewOrg - creates a new org manager

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, mongoConn mongoCollection, authClient AuthRequestCreator)

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 AuthRequestCreator added in v0.0.81

type AuthRequestCreator interface {
	CreateAuthRequest(verb, requestURL, path string, args interface{}) (*http.Request, error)
	CCTarget() string
	HttpClient() ccclient.ClientDoer
	Login() (*ccclient.Client, error)
}

AuthRequestCreator - interface to an object which can decorate a request with auth tokens

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 NewOrgController

func NewOrgController(c Persistence, authClient AuthRequestCreator) Controller

NewOrgController - a controller for me requests

func NewValidateV1

func NewValidateV1(kg KeyGenerator) Controller

NewValidateV1 - create a validation controller

type Doer

type Doer interface {
	Do(commandName string, args ...interface{}) (reply interface{}, err error)
}

Doer - interface to make a call to persistence store

type GUIDMake

type GUIDMake struct {
}

GUIDMake - struct for making guids

func (*GUIDMake) Create

func (s *GUIDMake) Create() string

Create - creates a new random guid

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

func (*KeyGen) Create

func (s *KeyGen) Create(user string, details string) (err error)

Create - creates a new key for a user

func (*KeyGen) Delete

func (s *KeyGen) Delete(user string) (err error)

Delete - deletes a key for a user

func (*KeyGen) Get

func (s *KeyGen) Get(user string) (res string, err error)

Get - gets a key for a user

func (*KeyGen) GetByKey

func (s *KeyGen) GetByKey(key string) (hash string, val interface{}, err error)

GetByKey - gets a user for a given key

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

type MeGetHandler func(log *log.Logger, r render.Render, tokens oauth2.Tokens)

MeGetHandler - a get control handler for me requests

type OrgGetHandler

type OrgGetHandler func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens)

OrgGetHandler - func signature of org get handler

type OrgManager added in v0.0.81

type OrgManager interface {
	Show() (result *PivotOrg, err error)
	SafeCreate() (record *PivotOrg, err error)
}

OrgManager - interface to the org creation functionality

type OrgPutHandler

type OrgPutHandler func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens)

OrgPutHandler - func signature of org put handler

type Persistence added in v0.0.81

type Persistence interface {
	FindOne(query interface{}, result interface{}) (err error)
	Upsert(selector interface{}, update interface{}) (err error)
}

Persistence - interface to a persistence store of some kind

type PivotOrg

type PivotOrg struct {
	Email   string
	OrgName string
	OrgGUID string
}

PivotOrg - struct for pivot org record

type Response

type Response struct {
	Payload  interface{}
	APIKey   string
	ErrorMsg string
}

Response - generic response object

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

func (*UserMatch) OnFailure

func (s *UserMatch) OnFailure(failFunc func()) *UserMatch

OnFailure - function to call if they are not allowed to make the call

func (*UserMatch) OnSuccess

func (s *UserMatch) OnSuccess(successFunc func()) *UserMatch

OnSuccess - function to run if they are allowed to make the calls

func (*UserMatch) Run

func (s *UserMatch) Run() (err error)

Run - executes the check and run of success or failure function

func (*UserMatch) UserInfo

func (s *UserMatch) UserInfo(userInfo map[string]interface{}) *UserMatch

UserInfo - accepts a userinfo object grabbed from google auth

func (*UserMatch) UserName

func (s *UserMatch) UserName(username string) *UserMatch

UserName - takes a username which is passed as part of the rest call

type ValidateGetHandler

type ValidateGetHandler func(log *log.Logger, r render.Render, req *http.Request)

ValidateGetHandler - a type of handler for validation get endpoints

Jump to

Keyboard shortcuts

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