我真的对此感到困惑,我知道这里有几个重复的帖子,完成了一些阅读,我知道一些关于ClaimsResponse(至少我认为我做的)与SREG和AX信息一起工作,用于启用AXFetchAsSregTransform的web.config配置,如何使用ClaimsRequest通过DemandLevel.Require获取Google电子邮件。我想要做的是让我的样本工作(来自strathweb的样本)与v4.0之后的统一DotNetOpenAuth.dll库作为我的项目的单个引用而不是nuget包。示例适用于版本DotNetOpenAuth-3.4.7.11121。如果有人能给我一些关于这个问题的信息,我将不胜感激。当我创建请求并使用DotNetOpenAuth.dll v3.4.7时,一切顺利:
public IAuthenticationRequest ValidateAtOpenIdProvider(string openIdIdentifier,Realm realm,Uri returnurl)
{
IAuthenticationRequest openIdRequest = openId.CreateRequest(Identifier.Parse(openIdIdentifier),领域, RETURNURL);
var fields = new ClaimsRequest() { Email = DemandLevel.Require, FullName = DemandLevel.Require, Nickname = DemandLevel.Require }; openIdRequest.AddExtension(fields); return openIdRequest; }
将用户重定向到服务提供商:
var response = openidemembership.ValidateAtOpenIdProvider(identifier, 领域,新的Uri(“DomainUrl或Localhost / GoogleCallback”));
if (response != null) { return response.RedirectingResponse.AsActionResult(); }
用户重定向后,会调用这两个方法:
public OpenIdUser GetUser() {
OpenIdUser user = null; IAuthenticationResponse openIdResponse = openId.GetResponse(); if (openIdResponse.IsSuccessful()) { user = ResponseIntoUser(openIdResponse); } return user; }
私有OpenIdUser ParseResponse(IAuthenticationResponse响应) {
OpenIdUser user = null; var claimResponseUntrusted = response.GetUntrustedExtension<ClaimsResponse>(); var claimResponse = response.GetExtension<ClaimsResponse>(); if (claimResponse != null) { user = new OpenIdUser(claimResponse, response.ClaimedIdentifier); } else if (claimResponseUntrusted != null) { user = new OpenIdUser(claimResponseUntrusted, response.ClaimedIdentifier); } return user; }
控制器内部:
public ActionResult GoogleCallback() {
var user = openidemembership.GetUser(); if (user != null) { //Create cookie and redirect the user back return new RedirectResult(Request.Params["ReturnUrl"] ?? "/"); } return View(); }
的Web.Config
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true" />
<dotNetOpenAuth>
<openid>
<relyingParty>
<behaviors>
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
</relyingParty>
</openid>
</dotNetOpenAuth>
仍然在使用DotNetOpenAuth.dll v4.0 +++之后,在ParseResponse方法调用中我无法从ClaimsResponse获取任何值。我正在使用名称空间DotNetOpenAuth.OpenId.Extensions.SimpleRegistration。使用nuget一切都很好,但有没有其他方法可以让它与单个dll一起使用,我真的不会将所有这些来自nuget的引用添加到我正在为我的一个客户工作的现有项目中,谢谢你提前。
答案 0 :(得分:0)
更新您的web.config文件以使用DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform
。 (注意命名空间中的更改以向其添加“RelyingParty”。在v4.x中,DotNetOpenAuth移动了行为的命名空间以支持多组件构建,甚至影响了统一的程序集版本。
<dotNetOpenAuth>
<openid>
<relyingParty>
<behaviors>
<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
</relyingParty>
</openid>
</dotNetOpenAuth>
此外,即使你想要统一的程序集,你仍然可以使用NuGet获得DotNetOpenAuth:
安装包DotNetOpenAuth.Ultimate