gpt4 book ai didi

google-app-engine - 如何管理我的谷歌应用引擎(使用 golang)的帐户?

转载 作者:数据小太阳 更新时间:2023-10-29 03:29:23 25 4
gpt4 key购买 nike

我阅读了文档“Using the Users Service”并且它有效。但是我只想允许几个用户访问我的 GAE,并限制其他用户。

那么,我该如何管理我的谷歌应用引擎(使用 golang)的用户帐户?

我将使用“Google 帐户”系统。

我需要你的帮助。谢谢!祝你有个愉快的一天~

最佳答案

我想你有两个选择:
1.您可以只限制您的Google App域的用户,进入管理>>应用程序设置>>身份验证类型。
2. “appengine/user” pakage 只是给你基本的功能。您可以使用它来检查当前用户的电子邮件是否在允许列表中。

var allowed = []string{"tom@example.com", "jack@example.com"}
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
u := user.Current(c)
if u == nil {
url, err := user.LoginURL(c, r.URL.String())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Location", url)
w.WriteHeader(http.StatusFound)
return
}

var granted bool
for _, email := range allowed {
if u.Email == email {
granted = true
break;
}
}
if !granted {
http.Error(w, "you're not in the allowed list", 400)
return
}
fmt.Fprintf(w, "Hello, %v!", u)
}

关于google-app-engine - 如何管理我的谷歌应用引擎(使用 golang)的帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19898823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com