Google app engine 将AppEngine/Go用户API与OAuth一起使用:代码示例、工作流、任何帮助?

Google app engine 将AppEngine/Go用户API与OAuth一起使用:代码示例、工作流、任何帮助?,google-app-engine,oauth,go,openid,oath,Google App Engine,Oauth,Go,Openid,Oath,虽然我对AppEngine/Python运行时很有经验,但我是一个新手。我的第一个应用程序即将推出,但我仍然需要为用户提供登录功能。我希望使用OpenID,因为我不希望用户拥有Google Id 然而,似乎没有或几乎没有工作示例,AppEngine文档明确省略了我需要实现的函数的内容: func init() { http.HandleFunc("/_ah/login_required", openIdHandler) } func openIdHandler(w http.Respo

虽然我对AppEngine/Python运行时很有经验,但我是一个新手。我的第一个应用程序即将推出,但我仍然需要为用户提供登录功能。我希望使用OpenID,因为我不希望用户拥有Google Id

然而,似乎没有或几乎没有工作示例,AppEngine文档明确省略了我需要实现的函数的内容:

func init() {
    http.HandleFunc("/_ah/login_required", openIdHandler)
}

func openIdHandler(w http.ResponseWriter, r *http.Request) {
    // ...
}
openIdHandler
func中有什么内容

我知道我需要提供一个页面,允许用户从众多OpenId提供者中选择一个,并为该系统输入他们的Id。我只是不知道那之后该怎么办。工作流程是什么?是否有人知道我可以查看的任何示例代码,以便大致了解我必须做什么以及必须处理哪些数据?我所有的谷歌富都让我一事无成


明确地说,我不希望与这些OpenId提供商提供的任何服务进行交互;我不希望创建推特或嗡嗡声。我不想访问联系人、文档、墙贴或其他任何内容。我只是想要一个经过验证的Credential,我可以在我的应用程序中使用它来限制用户只访问他或她自己的数据

如果我很了解你-你需要的,不是。 我为go-lang重写了python示例()。希望对您有所帮助

package gae_go_openid_demo

import (
    "fmt"
    "os"
    "http"

    "appengine"
    "appengine/user"
)

func init() {
    http.HandleFunc("/", hello)
    http.HandleFunc("/_ah/login_required", openIdHandler)
}

func hello(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    u := user.Current(c)
    if u != nil {
        url, err := user.LogoutURL(c, "/")
        check(err);
        fmt.Fprintf(w, "Hello, %s! (<a href='%s'>Sign out</a>)", u, url)
    } else {
        fmt.Fprintf(w, "Please, <a href='/_ah/login_required'>login</a>.")
    }

}

func openIdHandler(w http.ResponseWriter, r *http.Request) {
    providers := map[string]string {
        "Google"   : "www.google.com/accounts/o8/id", // shorter alternative: "Gmail.com"
        "Yahoo"    : "yahoo.com",
        "MySpace"  : "myspace.com",
        "AOL"      : "aol.com",
        "MyOpenID" : "myopenid.com",
        // add more here
    }

    c := appengine.NewContext(r)
    fmt.Fprintf(w, "Sign in at: ")
    for name, url := range providers {
        login_url, err := user.LoginURLFederated(c, "/", url)
        check(err);
        fmt.Fprintf(w, "[<a href='%s'>%s</a>]", login_url, name)
    }
}

// check aborts the current execution if err is non-nil.
func check(err os.Error) {
    if err != nil {
        panic(err)
    }
}
包gae\u go\u openid\u演示
进口(
“fmt”
“操作系统”
“http”
“阿彭金”
“应用程序/用户”
)
func init(){
http.HandleFunc(“/”,您好)
http.HandleFunc(“/\uAH/login\uRequired”,openIdHandler)
}
func hello(w http.ResponseWriter,r*http.Request){
c:=appengine.NewContext(r)
u:=用户当前(c)
如果你!=零{
url,err:=user.LogoutURL(c,“/”)
检查(错误);
Fprintf(w,“Hello,%s!()”,u,url)
}否则{
fmt.Fprintf(带“请”字)
}
}
func openIdHandler(w http.ResponseWriter,r*http.Request){
提供者:=映射[字符串]字符串{
“谷歌”:“www.Google.com/accounts/o8/id”,//较短的备选方案:“Gmail.com”
“Yahoo”:“Yahoo.com”,
“MySpace”:“MySpace.com”,
“AOL”:“AOL.com”,
“MyOpenID”:“MyOpenID.com”,
//在这里添加更多
}
c:=appengine.NewContext(r)
fmt.Fprintf(w,“登录位置:”)
对于名称,url:=范围提供程序{
login\u url,err:=user.LoginURLFederated(c,“/”,url)
检查(错误);
fmt.Fprintf(w,“[]”,登录地址,名称)
}
}
//如果err为非nil,check将中止当前执行。
功能检查(错误操作系统错误){
如果错误!=零{
恐慌(错误)
}
}