【问题标题】:Does an OpenID realm have to be the base URL of the web site?OpenID 领域是否必须是网站的基本 URL?
【发布时间】:2012-10-11 22:12:06
【问题描述】:

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

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

2012-10-10 15:17:46,000 (GMT-4) [24] ERROR DotNetOpenAuth.OpenId - Attribute Exchange extension did not provide any aliases in the if_available or required lists.

代码:

依赖方:

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

【问题讨论】:

  • 你能详细说明一下冻结吗?是浏览器卡死了吗?还是网页在流程中的某个时刻没有改变?你会无限重定向吗?

标签: c# asp.net .net openid dotnetopenauth


【解决方案1】:

您的问题的答案是“否”。领域可以是站点的基本 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 创建了一个 FetchRequest 扩展并将其添加到 OpenID 身份验证请求,但您尚未使用您请求的任何实际属性初始化 FetchRequest。

我无法根据您提供的信息告诉您为什么您的应用会冻结。

【讨论】:

  • 好的,谢谢。我将保持原样离开这个领域,因为它似乎正在工作。我还删除了 fetchrequest 并且错误消失了。 “冻结”是一个不正确的术语来描述正在发生的事情 - 我已经调查了更多,我会发布一个新问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 2013-04-29
  • 1970-01-01
  • 1970-01-01
  • 2012-09-23
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多