我想通過開放ID驗證後如何獲取用戶信息。無論我何時致電無法從DotNetOpenId響應獲取屬性
response.GetExtension<ClaimsResponse>
//Or
response.GetExtension<FetchResponse>
//Or
response.GetUntrustedExtension<ClaimsResponse>
// OR
response.GetUntrustedExtension<FetchResponse>
我總是收到一個空引用,無論我是否提供ClaimRequest或FetchRequest都沒有關係。我添加的信息就像我見過的所有例子一樣:
request.AddExtension(new ClaimsRequest{ Email = DemandLevel.Require });
// Or
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(fetch);
任何想法我做錯了什麼?
更新
添加由安德魯建議的配置信息得到了我的存在方式的一部分。我終於獲得了response.GetUntrustedExtension<ClaimsResponse>
的ClaimsResponse,但response.GetExtension<ClaimsResponse>
仍然返回null。另外返回的ClaimsResponse實際上並不包含我請求的任何數據。這裏的要求:
var request = openId.CreateRequest(Request.Form["openid_identifier"]);
request.AddExtension(new ClaimsRequest
{
BirthDate = DemandLevel.Request,
Country = DemandLevel.Request,
Email = DemandLevel.Require,
FullName = DemandLevel.Request,
Gender = DemandLevel.Request,
Language = DemandLevel.Request,
Nickname = DemandLevel.Request,
PostalCode = DemandLevel.Request,
TimeZone = DemandLevel.Request
});
return request.RedirectingResponse.AsActionResult();
這裏是我的配置
<uri>
<idn enabled="All"/>
<iriParsing enabled="true"/>
</uri>
<dotNetOpenAuth>
<openid maxAuthenticationTime="0:05">
<relyingParty>
<security
requireSsl="false"
minimumRequiredOpenIdVersion="V10"
minimumHashBitLength="160"
maximumHashBitLength="256"
requireDirectedIdentity="false"
requireAssociation="false"
rejectUnsolicitedAssertions="false"
rejectDelegatingIdentifiers="false"
ignoreUnsignedExtensions="false"
privateSecretMaximumAge="07:00:00" />
<behaviors>
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
</relyingParty>
</openid>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
<!-- since this is a sample, and will often be used with localhost -->
<add name="localhost" />
</whitelistHosts>
</untrustedWebRequest>
</messaging>
我跑v3.2.0.9177
你可以加入你正在測試的OP嗎? – 2009-07-05 01:20:48
行爲配置會導致ClaimsResponse始終存在,即使沒有任何值,就像您說的那樣。它看起來像你的代碼是正確的,因爲myopenid支持sreg和AX我很驚訝這不適合你。我會看看我是否可以做更多的調查。 – 2009-07-05 14:59:55