DotNetOpenAuth ClaimsResponse返回Null与统一库v4.0 ++ Google OpenId

本文关键字:v4 Google OpenId 返回 ClaimsResponse Null DotNetOpenAuth | 更新日期: 2023-09-27 17:52:54

我真的很困惑,我知道有几个重复的帖子像这样,做了相当多的阅读,我知道一点关于ClaimsResponse(至少我认为我做)与SREG和AX信息,web工作。配置配置为启用AXFetchAsSregTransform,如何使用ClaimsRequest获得谷歌电子邮件与DemandLevel.Require。我要做的是让我的样本工作(从strathweb使用的样本)与统一的DotNetOpenAuth.dll库在v4.0之后作为我的项目的单一参考,而不是一个nuget包。示例适用于版本DotNetOpenAuth-3.4.7.11121。如果有人能给我一些关于这个问题的信息,我将不胜感激。当我创建请求并使用DotNetOpenAuth.dll v3.4.7时,一切都很顺利:

公共IAuthenticationRequest ValidateAtOpenIdProvider(字符串openiddentifier, Realm, Realm, Uri

{

IAuthenticationRequest openIdRequest = openId.CreateRequest(Identifier.Parse(openiddentifier)), realm,returnurl);

        var fields = new ClaimsRequest()
        {
            Email = DemandLevel.Require,
            FullName = DemandLevel.Require,
            Nickname = DemandLevel.Require
        };
        openIdRequest.AddExtension(fields);
        return openIdRequest;
    }

并将用户重定向到服务提供商:

var response = openidemembership。ValidateAtOpenIdProvider(标识符,realm, new Uri("DomainUrl or Localhost/GoogleCallback"));

        if (response != null)
        {
            return response.RedirectingResponse.AsActionResult();
        }

User被重定向回后,这两个方法被调用:

public OpenIdUser GetUser(){

        OpenIdUser user = null;
        IAuthenticationResponse openIdResponse = openId.GetResponse();
        if (openIdResponse.IsSuccessful())
        {
            user = ResponseIntoUser(openIdResponse);
        }
        return user;
    }

private OpenIdUser parserresponse (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();
    }

网络。配置

 <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 ++之后,在parserresponse方法调用中,我无法从ClaimsResponse中获得任何值。我正在使用命名空间dotnetopenauth . openid . extensions . simplereregistration。有了nuget,一切都很好,但是有没有其他方法可以让它与单个dll一起工作,我真的不愿意将所有这些参考资料从nuget添加到我现有的项目中,我目前正在为我的一个客户工作,提前感谢您。

DotNetOpenAuth ClaimsResponse返回Null与统一库v4.0 ++ Google OpenId

更新你的网页。使用DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform . config文件。(请注意在命名空间中添加了"RelyingParty"。在v4。x, DotNetOpenAuth移动了行为的命名空间,以支持多汇编构建,它甚至影响了统一的汇编版本。

<dotNetOpenAuth>
    <openid>
      <relyingParty>
        <behaviors>
          <add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
        </behaviors>
      </relyingParty>
    </openid>
  </dotNetOpenAuth>

另外,即使你想要统一的程序集,你仍然可以使用NuGet来获取DotNetOpenAuth:

安装包DotNetOpenAuth。最终