如何从Google OpenID提供商处获取电子邮件(在VB中)

时间:2011-12-22 03:52:12

标签: asp.net vb.net openid dotnetopenauth

萨拉姆对所有人来说 我正在使用DotNetOpenAuth控件进行谷歌验证。这是我正在使用的代码。

<rp:OpenIdLogin ID="OID" runat=server Identifier="https://www.google.com/accounts/o8/id" RequestEmail="Require" ></rp:OpenIdLogin>

要从提供商处获取电子邮件ID的响应,我在default.aspx的页面加载事件中使用此代码

 Public Email As String = "N/A"

    Public FullName As String = "N/A"

    Public Country As String = "N/A"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim openid As OpenIdRelyingParty = New OpenIdRelyingParty
        Dim response = openid.GetResponse
        If (Not (response) Is Nothing) Then
            Select Case (response.Status)
                Case AuthenticationStatus.Authenticated
                    Dim fetch = response.GetExtension
                    Dim email As String = String.Empty
                    If (Not (fetch) Is Nothing) Then
                        email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email)
                    End If
                    FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, False)
            End Select
        End If


    End Sub

我可以通过谷歌进行身份验证,但谷歌没有回复电子邮件ID 请告诉我我错过了什么导致了这个问题。

更新

  <configSections>
    <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
  </configSections>
  <dotNetOpenAuth>
    <openid>
      <relyingParty>
        <behaviors>
          <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
                    with OPs that use Attribute Exchange (in various formats). -->
          <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
        </behaviors>
      </relyingParty>
    </openid>
  </dotNetOpenAuth>

1 个答案:

答案 0 :(得分:2)

您可能错过了web.config文件中的相应“行为”。请学习此页面并将其应用到您的网站:https://github.com/DotNetOpenAuth/DotNetOpenAuth/wiki/Enhancements

此外,使用此行为时,您应该在肯定身份验证响应中而不是ClaimsResponse中查找FetchResponse扩展名。

作为旁注,您在代码隐藏的Page_Load方法中有很多样板代码,而您不需要这些代码。您使用的OpenIdControl有一个LoggedIn方法可以完成您在此处所执行的大部分工作(它可以让您一直到达Case块的正文。