Golang GAE - 联合登录示例

时间:2012-07-15 02:18:11

标签: google-app-engine login openid go federated-identity

我正在尝试使用Google App Engine Go SDK实现联合登录,但我能找到的关于该主题的唯一示例是关于how to do this in Python and Java。我知道我需要调用this function来获取URL,但我不确定要传递的参数。有人可以在GAE Golang中提供几个主要平台(Facebook,Twitter等)的联合登录示例吗?

1 个答案:

答案 0 :(得分:6)

Facebook和Twitter不使用OpenID进行身份验证。

Facebook使用OAuth 2 - 您需要使用goauth2进行身份验证。

Twitter使用:OAuth。您需要使用goauth进行身份验证。

如果您仍然想要为Yahoo,Google,MySpace等提供商使用联合登录,它将如下所示:

c := appengine.NewContext(r)
// url is the OpenID url other possiblities include:
//   - yahoo.com
//   - myspace.com
//   - aol.com
//   - flickr.com/USERNAME
url := "gmail.com"
// redirectURL is where you want the User to be redirected to after login.
redirectURL := "/callback"
loginUrl, err := user.LoginURLFederated(c, redirectURL, url)
// Then redirect the user to the url.
http.Redirect(w, r, loginUrl, http.StatusFound)

对于Facebook和Twitter身份验证,您可以查看go.auth包。它可能不适用于App Engine,但它可能会为您提供一些线索。

我也正在HAL/auth包中解决这个问题,但到目前为止还不完整。以下是HAL处理app engine openid的方式。

相关问题