I'm trying to figure out how to get the users information after validating via open id. It doesn't matter if I supply a ClaimsRequest or FetchRequest whenever I call
我试图弄清楚如何通过open id验证后获取用户信息。如果我在呼叫时提供ClaimsRequest或FetchRequest并不重要
response.GetExtension<ClaimsResponse>
//Or
response.GetExtension<FetchResponse>
//Or
response.GetUntrustedExtension<ClaimsResponse>
// OR
response.GetUntrustedExtension<FetchResponse>
I always get a null reference. I'm adding the information just like in all the examples I've seen like this:
我总是得到一个空引用。我正在添加信息,就像我看到的所有示例一样:
request.AddExtension(new ClaimsRequest{ Email = DemandLevel.Require });
// Or
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(fetch);
Any idea what I'm doing wrong?
知道我做错了什么吗?
Update
Adding the configuration info suggested by Andrew got me part of the way there. I'm finally getting a ClaimsResponse back with response.GetUntrustedExtension<ClaimsResponse>
however response.GetExtension<ClaimsResponse>
still returns null. Also the ClaimsResponse returned doesn't actually contain any of the data I requested. Here's the request:
添加安德鲁建议的配置信息让我成为了那里的一部分。我终于通过response.GetUntrustedExtension
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();
Here is my configuration
这是我的配置
<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>
I'm running v3.2.0.9177
我正在运行v3.2.0.9177
1 个解决方案
#1
It could very well be that the Provider you're testing against doesn't support these extensions. Or, if it's Google, it only answers the question once (unless during login you're careful to not leave Remember Me checked).
您正在测试的提供商很可能不支持这些扩展。或者,如果它是谷歌,它只回答一次问题(除非在登录时你小心不要记住我记得)。
Now with DotNetOpenAuth v3.2, the best way to send extensions is probably to use the new attribute extension 'behavior'. It will automatically use sreg and/or AX (in up to three different AX formats) depending on the Provider in order to maximize your chance of getting a useful result if the Provider supports any of these extensions at all.
现在使用DotNetOpenAuth v3.2,发送扩展的最佳方式可能是使用新的属性扩展“行为”。它将自动使用sreg和/或AX(最多三种不同的AX格式),具体取决于提供商,以便在提供商支持任何这些扩展时最大限度地获得有用结果的机会。
Stick this bit in your web.config file, where suggested in the full configuration wiki page.
将此位粘贴在web.config文件中,完整配置wiki页面中的建议。
<behaviors>
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
Then use ClaimsRequest
/ClaimsResponse
(sreg) instead of AX' FetchRequest
so that the behavior can do its work.
然后使用ClaimsRequest / ClaimsResponse(sreg)而不是AX'FetchRequest,以便行为可以完成其工作。
Since you mentioned that you're testing against myopenid.com, I'll also throw out the heads up that it seems they've turned off extensions support when you're testing an RP that is on 'localhost'. Your RP apparently has to be public and maybe even discoverable (per the OpenID 2.0 rules for RP discovery) for the attribute request to be honored. This might be what you're running into.
既然你提到你正在对myopenid.com进行测试,那么当你测试'localhost'上的RP时,我也会忽略它们似乎已经关闭了扩展支持。您的RP显然必须是公开的,甚至可以发现(根据RP发现的OpenID 2.0规则),以便尊重属性请求。这可能是你遇到的。
#1
It could very well be that the Provider you're testing against doesn't support these extensions. Or, if it's Google, it only answers the question once (unless during login you're careful to not leave Remember Me checked).
您正在测试的提供商很可能不支持这些扩展。或者,如果它是谷歌,它只回答一次问题(除非在登录时你小心不要记住我记得)。
Now with DotNetOpenAuth v3.2, the best way to send extensions is probably to use the new attribute extension 'behavior'. It will automatically use sreg and/or AX (in up to three different AX formats) depending on the Provider in order to maximize your chance of getting a useful result if the Provider supports any of these extensions at all.
现在使用DotNetOpenAuth v3.2,发送扩展的最佳方式可能是使用新的属性扩展“行为”。它将自动使用sreg和/或AX(最多三种不同的AX格式),具体取决于提供商,以便在提供商支持任何这些扩展时最大限度地获得有用结果的机会。
Stick this bit in your web.config file, where suggested in the full configuration wiki page.
将此位粘贴在web.config文件中,完整配置wiki页面中的建议。
<behaviors>
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
Then use ClaimsRequest
/ClaimsResponse
(sreg) instead of AX' FetchRequest
so that the behavior can do its work.
然后使用ClaimsRequest / ClaimsResponse(sreg)而不是AX'FetchRequest,以便行为可以完成其工作。
Since you mentioned that you're testing against myopenid.com, I'll also throw out the heads up that it seems they've turned off extensions support when you're testing an RP that is on 'localhost'. Your RP apparently has to be public and maybe even discoverable (per the OpenID 2.0 rules for RP discovery) for the attribute request to be honored. This might be what you're running into.
既然你提到你正在对myopenid.com进行测试,那么当你测试'localhost'上的RP时,我也会忽略它们似乎已经关闭了扩展支持。您的RP显然必须是公开的,甚至可以发现(根据RP发现的OpenID 2.0规则),以便尊重属性请求。这可能是你遇到的。