Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: service/user/interface.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: Lightning talk licenses. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « service/user/context.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package user 5 package user
6 6
7 // Interface provides access to the "appengine/users" API methods. 7 import (
8 type Interface interface { 8 » "golang.org/x/net/context"
9 )
10
11 // RawInterface provides access to the "appengine/users" API methods.
12 type RawInterface interface {
9 Current() *User 13 Current() *User
10 CurrentOAuth(scopes ...string) (*User, error) 14 CurrentOAuth(scopes ...string) (*User, error)
11 15
12 IsAdmin() bool 16 IsAdmin() bool
13 17
14 LoginURL(dest string) (string, error) 18 LoginURL(dest string) (string, error)
15 LoginURLFederated(dest, identity string) (string, error) 19 LoginURLFederated(dest, identity string) (string, error)
16 LogoutURL(dest string) (string, error) 20 LogoutURL(dest string) (string, error)
17 21
18 OAuthConsumerKey() (string, error) 22 OAuthConsumerKey() (string, error)
19 23
20 // If this implementation supports it, this will return an instance of t he 24 // If this implementation supports it, this will return an instance of t he
21 // Testable object for this service, which will let you 'log in' virtual users 25 // Testable object for this service, which will let you 'log in' virtual users
22 // in your test cases. If the implementation doesn't support it, it will 26 // in your test cases. If the implementation doesn't support it, it will
23 // return nil. 27 // return nil.
24 » Testable() Testable 28 » GetTestable() Testable
25 } 29 }
30
31 // Current returns the currently logged-in user, or nil if the user is not
32 // signed in.
33 func Current(c context.Context) *User {
34 return Raw(c).Current()
35 }
36
37 // CurrentOAuth returns the user associated with the OAuth consumer making this
38 // request.
39 //
40 // If the OAuth consumer did not make a valid OAuth request, or the scopes is
41 // non-empty and the current user does not have at least one of the scopes, this
42 // method will return an error.
43 func CurrentOAuth(c context.Context, scopes ...string) (*User, error) {
44 return Raw(c).CurrentOAuth(scopes...)
45 }
46
47 // IsAdmin returns true if the current user is an administrator for this
48 // AppEngine project.
49 func IsAdmin(c context.Context) bool {
50 return Raw(c).IsAdmin()
51 }
52
53 // LoginURL returns a URL that, when visited, prompts the user to sign in, then
54 // redirects the user to the URL specified by dest.
55 func LoginURL(c context.Context, dest string) (string, error) {
56 return Raw(c).LoginURL(dest)
57 }
58
59 // LoginURLFederated is like LoginURL but accepts a user's OpenID identifier.
60 func LoginURLFederated(c context.Context, dest, identity string) (string, error) {
61 return Raw(c).LoginURLFederated(dest, identity)
62 }
63
64 // LogoutURL returns a URL that, when visited, signs the user out, then redirect s
65 // the user to the URL specified by dest.
66 func LogoutURL(c context.Context, dest string) (string, error) {
67 return Raw(c).LogoutURL(dest)
68 }
69
70 // OAuthConsumerKey returns the OAuth consumer key provided with the current
71 // request.
72 //
73 // This method will return an error if the OAuth request was invalid.
74 func OAuthConsumerKey(c context.Context) (string, error) {
75 return Raw(c).OAuthConsumerKey()
76 }
77
78 // GetTestable returns a Testable for the current task queue service in c, or
79 // nil if it does not offer one.
80 //
81 // The Testable instance will let you 'log in' virtual users in your test cases.
82 func GetTestable(c context.Context) Testable {
83 return Raw(c).GetTestable()
84 }
OLDNEW
« no previous file with comments | « service/user/context.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698