【问题标题】:AspNet WebHook Not Authenticating with IdentityAspNet WebHook 未使用身份进行身份验证
【发布时间】:2019-09-17 15:56:48
【问题描述】:

我有使用默认 Web MVC 项目的开箱即用身份验证的 webhook。

我现在尝试使用 Identity Server 将其移植到 Web API。

使用 Postman,当我进行身份验证时,我会得到一个不记名令牌。然后我收集该不记名令牌并将其附加到新的 GET 请求中,尝试访问 api/webhooks/registrations(以查看是否可以检索过滤器列表)

但我得到以下信息。

"message": "Could not determine the user ID from the given principal.",
"exceptionMessage": "Could not determine the user ID from the given principal.",
"exceptionType": "System.InvalidOperationException",
"stackTrace": "   at Microsoft.AspNet.WebHooks.WebHookUser.GetUserIdAsync(IPrincipal user)\r\n   at Microsoft.AspNet.WebHooks.Controllers.WebHookRegistrationsController.<GetUserId>d__13.MoveNext()"

如果我忽略 webhook 方法并使用相同的凭据访问另一个 API 方法,它可以工作,所以这是 WebHooks Auth 特有的。

我确实找到了这个,但我无法通过将 Claims 枚举更改为其他内容来使其工作。

Problems registering a receiver with Microsoft Webhooks

那么,任何人都可以解释为什么我的身份无法正常工作,或者建议其他方法来解决这个问题吗?

【问题讨论】:

    标签: c# webhooks identity


    【解决方案1】:

    发布答案以防其他人遇到此问题,谷歌上没有太多信息。 在我们的例子中,我们使用了一个自定义范围,它只定义了 2 个声明。

    使用上面的链接文章,我在配置自定义 web api 后添加了以下行。

                WebHookUser.IdClaimsType = Constants.CustomClaimTypes.<Claim defined in scope>;
    
    Easy when you step back and think about the problem with fresh eyes.
    
    

    【讨论】:

      猜你喜欢
      • 2015-09-23
      • 2019-06-29
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      相关资源
      最近更新 更多