如何管理我的Google应用引擎帐户(使用golang)?

时间:2013-11-11 04:26:36

标签: google-app-engine go

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

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

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

我需要你的帮助。 谢谢!祝你有美好的一天〜

1 个答案:

答案 0 :(得分:0)

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

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)
}