gpt4 book ai didi

c# - OpenID 领域是否必须是网站的基本 URL?

转载 作者:太空狗 更新时间:2023-10-29 20:10:44 24 4
gpt4 key购买 nike

作为 this question 的延续,我在使用 dotnetopenauth 时遇到了问题。

基本上,我想知道 RP 中指定的领域是否必须是应用程序的实际基本 URL?也就是说,(http://localhost:1903)?鉴于现有架构,很难删除重定向 - 我尝试将领域设置为基本 OpenId Controller (http://localhost:1903/OpenId)并手动测试确实生成了 XRDS 文档.但是,应用程序似乎卡住了,并且 EP 日志显示以下错误:

2012-10-10 15:17:46,000 (GMT-4) [24] 错误 DotNetOpenAuth.OpenId - 属性交换扩展未在 if_available 或必需列表中提供任何别名。

代码:

依赖方:

public ActionResult Authenticate(string RuserName = "")
{
UriBuilder returnToBuilder = new UriBuilder(Request.Url);
returnToBuilder.Path = "/OpenId/Authenticate";
returnToBuilder.Query = null;
returnToBuilder.Fragment = null;

Uri returnTo = returnToBuilder.Uri;
returnToBuilder.Path = "/";
Realm realm = returnToBuilder.Uri;

var response = openid.GetResponse();

if (response == null) {
if (Request.QueryString["ReturnUrl"] != null && User.Identity.IsAuthenticated) {

} else {

string strIdentifier = "http://localhost:3314/User/Identity/" + RuserName;
var request = openid.CreateRequest(
strIdentifier,
realm,
returnTo);

var fetchRequest = new FetchRequest();
request.AddExtension(fetchRequest);
request.RedirectToProvider();
}
} else {
switch (response.Status) {
case AuthenticationStatus.Canceled:
break;
case AuthenticationStatus.Failed:
break;
case AuthenticationStatus.Authenticated:
//log the user in
break;
}
}

return new EmptyResult();

供应商:

public ActionResult Index()
{
IRequest request = OpenIdProvider.GetRequest();

if (request != null) {
if (request.IsResponseReady) {
return OpenIdProvider.PrepareResponse(request).AsActionResult();
}

ProviderEndpoint.PendingRequest = (IHostProcessedRequest)request;
return this.ProcessAuthRequest();
} else {
//user stumbled on openid endpoint - 404 maybe?
return new EmptyResult();
}
}

public ActionResult ProcessAuthRequest()
{
if (ProviderEndpoint.PendingRequest == null) {
//there is no pending request
return new EmptyResult();
}

ActionResult response;
if (this.AutoRespondIfPossible(out response)) {
return response;
}

if (ProviderEndpoint.PendingRequest.Immediate) {
return this.SendAssertion();
}

return new EmptyResult();
}

最佳答案

您的问题的答案是“否”。领域可以是您站点的基本 URL 和 return_to URL 之间的任何 URL。因此,例如,如果您的 return_to URL 是 http://localhost:1903/OpenId/Authenticate,则以下都是有效领域:

  • http://localhost:1903/OpenId/Authenticate
  • http://localhost:1903/OpenId/
  • http://localhost:1903/

鉴于上面的 return_to,以下不是有效领域:

  • http://localhost:1903/OpenId/Authenticate/(额外的尾部斜杠)
  • http://localhost:1903/openid/(区分大小写!)
  • https://localhost:1903/(方案变更)

因为某些 OpenID 提供商(例如 Google)会根据确切的领域 URL 为其用户发布成对的唯一标识符,因此建议将您的领域作为您网站的基本 URL,以使其最稳定(重新设计您的网站不会更改)。还强烈建议,如果它可以是 HTTPS,则将其设置为 HTTPS,因为这样可以让您的 return_to 成为 HTTPS,并且这种方式稍微更安全(它可以减轻 DNS 中毒攻击)。

日志中出现错误的原因是因为您的 RP 创建并向 OpenID 身份验证请求添加了一个 FetchRequest 扩展,但是您还没有使用您正在访问的任何实际属性初始化 FetchRequest请求。

虽然根据您提供的信息,我无法告诉您您的应用为何卡住。

关于c# - OpenID 领域是否必须是网站的基本 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12831332/

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