1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-10 07:00:08 +00:00
cloudkeys-go/vendor/google.golang.org/appengine/user/user_vm.go
Knut Ahlers 99ff9846a3
Update vendoring using dep
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-12-29 23:13:47 +01:00

38 lines
1.1 KiB
Go

// 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"
}