我正在尝试使用 Google App Engine Go SDK 实现联合登录,但我能找到的关于该主题的唯一示例是关于 如何在 Python 和 Java 中执行此操作。我知道我需要调用 this function 来获取 URL,但我不确定要传递的参数。有人可以提供几个主要平台(Facebook、Twitter 等)在 GAE Golang 中联合登录的示例吗?
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 引擎 openid。