如何从谷歌OpenID提供商获得电子邮件(在VB)



向所有人致敬
我正在使用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

我可以通过google进行身份验证,但是没有来自google的电子邮件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>

你可能在你的网页中缺少适当的"行为"。配置文件。请学习此页面并将其应用到您的网站:https://github.com/DotNetOpenAuth/DotNetOpenAuth/wiki/Enhancements

另外,当使用此行为时,您应该在正向身份验证响应中寻找ClaimsResponse扩展,而不是FetchResponse

作为旁注,在代码背后的Page_Load方法中有许多您不需要的样板代码。您正在使用的OpenIdControl有一个LoggedIn方法,它可以完成您在这里所做的大部分工作(它可以让您一直到Case块的主体。

最新更新