2010-12-27 11 views
1

私はDotNetOpenAuthto認証済みのユーザーを使用しようとしています。しかし、私は電子メール、ファーストネーム、姓、など、Googleによって提供されるような追加のパラメータを取得する方法を見つけることができません。私が使用していますDotNetOpenAuthを使用してGoogleユーザーのemailIdを取得する方法

コードスニペットは、次のとおりです。

<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty" TagPrefix="rp" %> 

..............................

答えて

4

私のブログ記事のいくつかのヒントHow to pretty much guarantee that you might get an email address with OpenID。要するに

、あなたはactivate the AXFetchAsSregTransform behaviorする必要があります。

<configuration> 
    <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> 
</configuration> 

そして、あなたは、ユーザーの電子メールアドレスが必要なプロバイダーを伝える必要があります。しかしOpenIdButtonに取り組んでから<Extensions>タグを保持DotNetOpenAuthのバグが(v3.4.7がこれを修正する)がある

<rp:OpenIdButton runat="server" 
    Text="Log in with Google" 
    Identifier="https://www.google.com/accounts/o8/id"> 
    <Extensions> 
     <sreg:ClaimsRequest Email="Require" /> 
    </Extensions> 
</rp:OpenIdButton> 

:理想的には、これは次のように行われます。代わりに、コードビハインドで属性要求を追加する必要があります。だからあなたのタグは次のようになります。

<rp:OpenIdButton runat="server" 
    Text="Log in with Google" 
    OnLoggingIn="OpenId_LoggingIn" 
    Identifier="https://www.google.com/accounts/o8/id" /> 

そして、あなたのコードビハインドこのメソッドを持っています

protected void OpenId_LoggingIn(object sender, OpenIdEventArgs e) { 
    e.Request.AddExtension(new ClaimsRequest() { Email = DemandLevel.Require }); 
} 
+0

おかげアンドリュー・アーノット。 btwライブラリは素晴らしいです:) – Ranger

+0

非常に有益。 – pqsk

+0

こんにちは、 "AXFetchAsSregTransformの動作をアクティブにする:"リンクが死んでいるようです。 GitHubから404を取得する。この情報は移動されましたか?もしそうならどこ?私はもう一度それを読むのが大好きです。 –

関連する問題