Golang GAE – 联合登录示例

huangapple go评论77阅读模式
英文:

Golang GAE - Federated Login examples

问题

我正在尝试使用Google App Engine Go SDK实现联合登录,但是我能找到的唯一关于这个主题的示例是关于如何在Python和Java中实现的。我理解我需要调用这个函数来获取URL,但是我不确定要传递的参数。有人可以提供一些在GAE Golang中使用联合登录的示例吗(如Facebook,Twitter等)?

英文:

I'm trying to implement Federated Login using Google App Engine Go SDK, but the only examples I can find on the subject are about how to do this in Python and Java. I understand that I need to call this function to get the URL, but I'm not sure about the parameters to pass. Can someone provide examples of Federated Login in GAE Golang for a few major platforms (Facebook, Twitter, etc)?

答案1

得分: 6

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

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

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

话虽如此,如果您仍然希望使用像Yahoo、Google、MySpace这样的提供商的联合登录,代码如下:

c := appengine.NewContext(r)
// url是OpenID的URL,其他可能性包括:
//   - yahoo.com
//   - myspace.com
//   - aol.com
//   - flickr.com/USERNAME
url := "gmail.com"
// redirectURL是登录后要将用户重定向到的URL。
redirectURL := "/callback"
loginUrl, err := user.LoginURLFederated(c, redirectURL, url)
// 然后将用户重定向到该URL。
http.Redirect(w, r, loginUrl, http.StatusFound)

对于Facebook和Twitter的身份验证,您可以查看go.auth包。它可能无法与App Engine一起使用,但可能会给您一些线索。

我还在HAL/auth包中解决这个问题,但目前还不完整。这是HAL如何处理app engine openid的方式。

英文:

Facebook and Twitter don't use OpenID for authentication.

Facebook uses OAuth 2 - You'll need to use goauth2 to authenticate.

Twitter uses: OAuth. You'll need to use goauth to authenticate.

That said if you are still wanting to use Federated Login for providers like Yahoo, Google, MySpace it would look like this:

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)

For Facebook and Twitter authentication you might look at the go.auth package. It might not work with App Engine but it might give you some clues.

I'm also working on a solution to this problem in the HAL/auth package, but as of now it's incomplete. Here's how HAL handles app engine openid.

huangapple
  • 本文由 发表于 2012年7月15日 10:18:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/11488880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定