gae: go.chromium.org/gae/service/user Index | Files

package user

import "go.chromium.org/gae/service/user"

Index

Package Files

context.go interface.go testable.go user.go

func AddFilters Uses

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

AddFilters adds RawInterface filters to the context.

func IsAdmin Uses

func IsAdmin(c context.Context) bool

IsAdmin returns true if the current user is an administrator for this AppEngine project.

func LoginURL Uses

func LoginURL(c context.Context, dest string) (string, error)

LoginURL returns a URL that, when visited, prompts the user to sign in, then redirects the user to the URL specified by dest.

func LoginURLFederated Uses

func LoginURLFederated(c context.Context, dest, identity string) (string, error)

LoginURLFederated is like LoginURL but accepts a user's OpenID identifier.

func LogoutURL Uses

func LogoutURL(c context.Context, dest string) (string, error)

LogoutURL returns a URL that, when visited, signs the user out, then redirects the user to the URL specified by dest.

func OAuthConsumerKey Uses

func OAuthConsumerKey(c context.Context) (string, error)

OAuthConsumerKey returns the OAuth consumer key provided with the current request.

This method will return an error if the OAuth request was invalid.

func Set Uses

func Set(c context.Context, u RawInterface) context.Context

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 Uses

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

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

type Factory Uses

type Factory func(context.Context) RawInterface

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

type Filter Uses

type Filter func(context.Context, RawInterface) RawInterface

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 RawInterface Uses

type RawInterface 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.
    GetTestable() Testable
}

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

func Raw Uses

func Raw(c context.Context) RawInterface

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

type Testable Uses

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.

func GetTestable Uses

func GetTestable(c context.Context) Testable

GetTestable returns a Testable for the current task queue service in c, or nil if it does not offer one.

The Testable instance will let you 'log in' virtual users in your test cases.

type User Uses

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.

func Current Uses

func Current(c context.Context) *User

Current returns the currently logged-in user, or nil if the user is not signed in.

func CurrentOAuth Uses

func CurrentOAuth(c context.Context, scopes ...string) (*User, error)

CurrentOAuth returns the user associated with the OAuth consumer making this request.

If the OAuth consumer did not make a valid OAuth request, or the scopes is non-empty and the current user does not have at least one of the scopes, this method will return an error.

Package user imports 2 packages (graph) and is imported by 18 packages. Updated 2018-09-08. Refresh now. Tools for package owners.