gpt4 book ai didi

asp.net-mvc - 为什么有关 openID 用户的信息不通过协议(protocol)传递?

转载 作者:行者123 更新时间:2023-12-04 15:05:20 25 4
gpt4 key购买 nike

我正在使用 DotNetOpenAuth将 openID 集成到我们的 Web 应用程序中。下面的代码向提供者请求信息。

try
{
var req = openid.CreateRequest(Request.Form["openid_identifier"]);
req.AddExtension(new DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.ClaimsRequest
{
Email = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Require,
FullName = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Require,
Nickname = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Request,
PostalCode = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Request
});

return req.RedirectingResponse.AsActionResult();
}

出于某种原因,来自 openID 提供者的响应从未附带我请求的信息。下面是代码:
// Stage 3: OpenID Provider sending assertion response
switch (response.Status) {
case AuthenticationStatus.Authenticated:
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
if (!string.IsNullOrEmpty(returnUrl)) {
return Redirect(returnUrl);
} else {
return RedirectToAction("Index", "Home");
}

我已经尝试过:response.ClaimedIdentifier 以一百万种方式,它从来没有我可以做的有值(value)的信息。有任何想法吗?

最佳答案

IAuthenticationResponse.ClaimedIdentifier property 从不包含您请求的这些属性。它只包含 OpenID 用户的“用户名”。

您正在完美地发送请求。只需在您对积极响应的处理中添加一点:

// Stage 3: OpenID Provider sending assertion response
switch (response.Status) {
case AuthenticationStatus.Authenticated:
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
var sreg = response.GetExtension<ClaimsResponse>();
if (sreg != null) { // the Provider MAY not provide anything
// and even if it does, any of these attributes MAY be missing
var email = sreg.Email;
var fullName = sreg.FullName;
// get the rest of the attributes, and store them off somewhere.
}
if (!string.IsNullOrEmpty(returnUrl)) {
return Redirect(returnUrl);
} else {
return RedirectToAction("Index", "Home");
}
break;
// ...

关于asp.net-mvc - 为什么有关 openID 用户的信息不通过协议(protocol)传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1393680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com