replace zxq.co/ripple/hanayo
This commit is contained in:
52
vendor/google.golang.org/appengine/user/oauth.go
generated
vendored
Normal file
52
vendor/google.golang.org/appengine/user/oauth.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2012 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"google.golang.org/appengine/internal"
|
||||
pb "google.golang.org/appengine/internal/user"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func CurrentOAuth(c context.Context, scopes ...string) (*User, error) {
|
||||
req := &pb.GetOAuthUserRequest{}
|
||||
if len(scopes) != 1 || scopes[0] != "" {
|
||||
// The signature for this function used to be CurrentOAuth(Context, string).
|
||||
// Ignore the singular "" scope to preserve existing behavior.
|
||||
req.Scopes = scopes
|
||||
}
|
||||
|
||||
res := &pb.GetOAuthUserResponse{}
|
||||
|
||||
err := internal.Call(c, "user", "GetOAuthUser", req, res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &User{
|
||||
Email: *res.Email,
|
||||
AuthDomain: *res.AuthDomain,
|
||||
Admin: res.GetIsAdmin(),
|
||||
ID: *res.UserId,
|
||||
ClientID: res.GetClientId(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// OAuthConsumerKey returns the OAuth consumer key provided with the current
|
||||
// request. This method will return an error if the OAuth request was invalid.
|
||||
func OAuthConsumerKey(c context.Context) (string, error) {
|
||||
req := &pb.CheckOAuthSignatureRequest{}
|
||||
res := &pb.CheckOAuthSignatureResponse{}
|
||||
|
||||
err := internal.Call(c, "user", "CheckOAuthSignature", req, res)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return *res.OauthConsumerKey, err
|
||||
}
|
84
vendor/google.golang.org/appengine/user/user.go
generated
vendored
Normal file
84
vendor/google.golang.org/appengine/user/user.go
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright 2011 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package user provides a client for App Engine's user authentication service.
|
||||
package user // import "google.golang.org/appengine/user"
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"google.golang.org/appengine/internal"
|
||||
pb "google.golang.org/appengine/internal/user"
|
||||
)
|
||||
|
||||
// User represents a user of the application.
|
||||
type User struct {
|
||||
Email string
|
||||
AuthDomain string
|
||||
Admin bool
|
||||
|
||||
// ID is the unique permanent ID of the user.
|
||||
// It is populated if the Email is associated
|
||||
// with a Google account, or empty otherwise.
|
||||
ID string
|
||||
|
||||
// ClientID is the ID of the pre-registered client so its identity can be verified.
|
||||
// See https://developers.google.com/console/help/#generatingoauth2 for more information.
|
||||
ClientID string
|
||||
|
||||
FederatedIdentity string
|
||||
FederatedProvider string
|
||||
}
|
||||
|
||||
// String returns a displayable name for the user.
|
||||
func (u *User) String() string {
|
||||
if u.AuthDomain != "" && strings.HasSuffix(u.Email, "@"+u.AuthDomain) {
|
||||
return u.Email[:len(u.Email)-len("@"+u.AuthDomain)]
|
||||
}
|
||||
if u.FederatedIdentity != "" {
|
||||
return u.FederatedIdentity
|
||||
}
|
||||
return u.Email
|
||||
}
|
||||
|
||||
// LoginURL returns a URL that, when visited, prompts the user to sign in,
|
||||
// then redirects the user to the URL specified by dest.
|
||||
func LoginURL(c context.Context, dest string) (string, error) {
|
||||
return LoginURLFederated(c, dest, "")
|
||||
}
|
||||
|
||||
// LoginURLFederated is like LoginURL but accepts a user's OpenID identifier.
|
||||
func LoginURLFederated(c context.Context, dest, identity string) (string, error) {
|
||||
req := &pb.CreateLoginURLRequest{
|
||||
DestinationUrl: proto.String(dest),
|
||||
}
|
||||
if identity != "" {
|
||||
req.FederatedIdentity = proto.String(identity)
|
||||
}
|
||||
res := &pb.CreateLoginURLResponse{}
|
||||
if err := internal.Call(c, "user", "CreateLoginURL", req, res); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return *res.LoginUrl, nil
|
||||
}
|
||||
|
||||
// LogoutURL returns a URL that, when visited, signs the user out,
|
||||
// then redirects the user to the URL specified by dest.
|
||||
func LogoutURL(c context.Context, dest string) (string, error) {
|
||||
req := &pb.CreateLogoutURLRequest{
|
||||
DestinationUrl: proto.String(dest),
|
||||
}
|
||||
res := &pb.CreateLogoutURLResponse{}
|
||||
if err := internal.Call(c, "user", "CreateLogoutURL", req, res); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return *res.LogoutUrl, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
internal.RegisterErrorCodeMap("user", pb.UserServiceError_ErrorCode_name)
|
||||
}
|
35
vendor/google.golang.org/appengine/user/user_classic.go
generated
vendored
Normal file
35
vendor/google.golang.org/appengine/user/user_classic.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build appengine
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"appengine/user"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"google.golang.org/appengine/internal"
|
||||
)
|
||||
|
||||
func Current(ctx context.Context) *User {
|
||||
u := user.Current(internal.ClassicContextFromContext(ctx))
|
||||
if u == nil {
|
||||
return nil
|
||||
}
|
||||
// Map appengine/user.User to this package's User type.
|
||||
return &User{
|
||||
Email: u.Email,
|
||||
AuthDomain: u.AuthDomain,
|
||||
Admin: u.Admin,
|
||||
ID: u.ID,
|
||||
FederatedIdentity: u.FederatedIdentity,
|
||||
FederatedProvider: u.FederatedProvider,
|
||||
}
|
||||
}
|
||||
|
||||
func IsAdmin(ctx context.Context) bool {
|
||||
return user.IsAdmin(internal.ClassicContextFromContext(ctx))
|
||||
}
|
99
vendor/google.golang.org/appengine/user/user_test.go
generated
vendored
Normal file
99
vendor/google.golang.org/appengine/user/user_test.go
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright 2011 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !appengine
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
"google.golang.org/appengine/internal"
|
||||
"google.golang.org/appengine/internal/aetesting"
|
||||
pb "google.golang.org/appengine/internal/user"
|
||||
)
|
||||
|
||||
func baseReq() *http.Request {
|
||||
return &http.Request{
|
||||
Header: http.Header{},
|
||||
}
|
||||
}
|
||||
|
||||
type basicUserTest struct {
|
||||
nickname, email, authDomain, admin string
|
||||
// expectations
|
||||
isNil, isAdmin bool
|
||||
displayName string
|
||||
}
|
||||
|
||||
var basicUserTests = []basicUserTest{
|
||||
{"", "", "", "0", true, false, ""},
|
||||
{"ken", "ken@example.com", "example.com", "0", false, false, "ken"},
|
||||
{"ken", "ken@example.com", "auth_domain.com", "1", false, true, "ken@example.com"},
|
||||
}
|
||||
|
||||
func TestBasicUserAPI(t *testing.T) {
|
||||
for i, tc := range basicUserTests {
|
||||
req := baseReq()
|
||||
req.Header.Set("X-AppEngine-User-Nickname", tc.nickname)
|
||||
req.Header.Set("X-AppEngine-User-Email", tc.email)
|
||||
req.Header.Set("X-AppEngine-Auth-Domain", tc.authDomain)
|
||||
req.Header.Set("X-AppEngine-User-Is-Admin", tc.admin)
|
||||
|
||||
c := internal.ContextForTesting(req)
|
||||
|
||||
if ga := IsAdmin(c); ga != tc.isAdmin {
|
||||
t.Errorf("test %d: expected IsAdmin(c) = %v, got %v", i, tc.isAdmin, ga)
|
||||
}
|
||||
|
||||
u := Current(c)
|
||||
if tc.isNil {
|
||||
if u != nil {
|
||||
t.Errorf("test %d: expected u == nil, got %+v", i, u)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if u == nil {
|
||||
t.Errorf("test %d: expected u != nil, got nil", i)
|
||||
continue
|
||||
}
|
||||
if u.Email != tc.email {
|
||||
t.Errorf("test %d: expected u.Email = %q, got %q", i, tc.email, u.Email)
|
||||
}
|
||||
if gs := u.String(); gs != tc.displayName {
|
||||
t.Errorf("test %d: expected u.String() = %q, got %q", i, tc.displayName, gs)
|
||||
}
|
||||
if u.Admin != tc.isAdmin {
|
||||
t.Errorf("test %d: expected u.Admin = %v, got %v", i, tc.isAdmin, u.Admin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginURL(t *testing.T) {
|
||||
expectedQuery := &pb.CreateLoginURLRequest{
|
||||
DestinationUrl: proto.String("/destination"),
|
||||
}
|
||||
const expectedDest = "/redir/dest"
|
||||
c := aetesting.FakeSingleContext(t, "user", "CreateLoginURL", func(req *pb.CreateLoginURLRequest, res *pb.CreateLoginURLResponse) error {
|
||||
if !proto.Equal(req, expectedQuery) {
|
||||
return fmt.Errorf("got %v, want %v", req, expectedQuery)
|
||||
}
|
||||
res.LoginUrl = proto.String(expectedDest)
|
||||
return nil
|
||||
})
|
||||
|
||||
url, err := LoginURL(c, "/destination")
|
||||
if err != nil {
|
||||
t.Fatalf("LoginURL failed: %v", err)
|
||||
}
|
||||
if url != expectedDest {
|
||||
t.Errorf("got %v, want %v", url, expectedDest)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(dsymonds): Add test for LogoutURL.
|
38
vendor/google.golang.org/appengine/user/user_vm.go
generated
vendored
Normal file
38
vendor/google.golang.org/appengine/user/user_vm.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2014 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !appengine
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"google.golang.org/appengine/internal"
|
||||
)
|
||||
|
||||
// Current returns the currently logged-in user,
|
||||
// or nil if the user is not signed in.
|
||||
func Current(c context.Context) *User {
|
||||
h := internal.IncomingHeaders(c)
|
||||
u := &User{
|
||||
Email: h.Get("X-AppEngine-User-Email"),
|
||||
AuthDomain: h.Get("X-AppEngine-Auth-Domain"),
|
||||
ID: h.Get("X-AppEngine-User-Id"),
|
||||
Admin: h.Get("X-AppEngine-User-Is-Admin") == "1",
|
||||
FederatedIdentity: h.Get("X-AppEngine-Federated-Identity"),
|
||||
FederatedProvider: h.Get("X-AppEngine-Federated-Provider"),
|
||||
}
|
||||
if u.Email == "" && u.FederatedIdentity == "" {
|
||||
return nil
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
// IsAdmin returns true if the current user is signed in and
|
||||
// is currently registered as an administrator of the application.
|
||||
func IsAdmin(c context.Context) bool {
|
||||
h := internal.IncomingHeaders(c)
|
||||
return h.Get("X-AppEngine-User-Is-Admin") == "1"
|
||||
}
|
Reference in New Issue
Block a user