import "go.chromium.org/luci/gae/service/user"
context.go interface.go testable.go user.go
AddFilters adds RawInterface filters to the context.
IsAdmin returns true if the current user is an administrator for this AppEngine project.
LoginURL returns a URL that, when visited, prompts the user to sign in, then redirects the user to the URL specified by dest.
LoginURLFederated is like LoginURL but accepts a user's OpenID identifier.
LogoutURL returns a URL that, when visited, signs the user out, then redirects the user to the URL specified by dest.
OAuthConsumerKey returns the OAuth consumer key provided with the current request.
This method will return an error if the OAuth request was invalid.
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.
SetFactory sets the function to produce user.RawInterface instances, as returned by the Get method.
type Factory func(context.Context) RawInterface
Factory is the function signature for factory methods compatible with SetFactory.
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 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(c context.Context) RawInterface
Raw pulls the user service implementation from context or nil if it wasn't set.
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.
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 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.
Current returns the currently logged-in user, or nil if the user is not signed in.
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 8 packages. Updated 2021-01-25. Refresh now. Tools for package owners.