我正在尝试使用 DotNetOpenAuth 通过 OpenID 从 Google 检索用户的电子邮件地址。
到目前为止,我的代码为当前用户正确重定向到 Google,并请求我的应用程序读取电子邮件地址的权限。然而,在被转移回我的页面后,它直接反弹回谷歌。我明白为什么会发生这种情况(因为页面永远不会进入回发状态),但是您如何区分请求和响应数据,以便我可以正确读取页面中的电子邮件地址?
是否有推荐的/行业标准方法?
我只是刚开始使用 OpenID 和 DotNetOpenAuth,但拥有强大的 ASP.NET 技能,所以请保持你的答案清晰(!)
谢谢
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
ltl.Text = "Welcome " & User.Identity.Name
If Not Page.IsPostBack Then
Dim openid As New OpenIdRelyingParty
Dim req As IAuthenticationRequest = openid.CreateRequest(User.Identity.Name)
Dim fetch As New FetchRequest
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email)
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName)
req.AddExtension(fetch)
req.RedirectToProvider()
Else
Dim openid As New OpenIdRelyingParty
Dim resp As IAuthenticationResponse = openid.GetResponse()
If resp IsNot Nothing Then
Dim fetch As FetchResponse = resp.GetExtension(Of FetchResponse)()
If fetch IsNot Nothing Then
Trace.Warn(fetch.GetAttributeValue(WellKnownAttributes.Contact.Email))
Else
Trace.Warn("fetch was Nothing")
End If
Else
Trace.Warn("resp was Nothing")
End If
End If
End Sub