user

package
v0.0.0-...-e6cee59 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2015 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFilters

func AddFilters(c context.Context, filts ...Filter) context.Context

AddFilters adds Interface filters to the context.

func Set

Set sets the user service in this context. Useful for testing with a quick mock. This is just a shorthand SetFactory invocation to set a factory which always returns the same object.

func SetFactory

func SetFactory(c context.Context, f Factory) context.Context

SetFactory sets the function to produce user.Interface instances, as returned by the Get method.

Types

type Factory

type Factory func(context.Context) Interface

Factory is the function signature for factory methods compatible with SetFactory.

type Filter

type Filter func(context.Context, Interface) Interface

Filter is the function signature for a filter user implementation. It gets the current user implementation, and returns a new user implementation backed by the one passed in.

type Interface

type Interface interface {
	Current() *User
	CurrentOAuth(scopes ...string) (*User, error)

	IsAdmin() bool

	LoginURL(dest string) (string, error)
	LoginURLFederated(dest, identity string) (string, error)
	LogoutURL(dest string) (string, error)

	OAuthConsumerKey() (string, error)

	// If this implementation supports it, this will return an instance of the
	// Testable object for this service, which will let you 'log in' virtual users
	// in your test cases. If the implementation doesn't support it, it will
	// return nil.
	Testable() Testable
}

Interface provides access to the "appengine/users" API methods.

func Get

func Get(c context.Context) Interface

Get pulls the user service implementation from context or nil if it wasn't set.

type Testable

type Testable interface {
	// SetUser sets the user to a pre-populated User object.
	SetUser(*User)

	// Login will generate and set a new User object with values derived from
	// email clientID, and admin values. If clientID is provided, the User will
	// look like they logged in with OAuth. If it's empty, then this will look
	// like they logged in via the cookie auth method.
	Login(email, clientID string, admin bool)

	// Equivalent to SetUser(nil), but a bit more obvious to read in the code :).
	Logout()
}

Testable is the interface that test implimentations will provide.

type User

type User struct {
	Email             string
	AuthDomain        string
	Admin             bool
	ID                string
	ClientID          string
	FederatedIdentity string
	FederatedProvider string
}

User is a mimic of https://godoc.org/google.golang.org/appengine/user#User

It's provided here for convenience, and is compile-time checked to be identical.

Jump to

Keyboard shortcuts

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