AspNet WebHook不使用身份验证

时间:2019-09-17 15:56:48

标签: c# webhooks identity

我使用默认Web MVC项目中的开箱即用auth进行webhooks。

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

使用邮递员,当我进行身份验证时,我会得到一个承载令牌。然后,我收集该承载令牌并将其附加到新的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

那么,有人能阐明我的身份为何不起作用的原因,还是建议其他方法来解决这个问题呢?

1 个答案:

答案 0 :(得分:0)

如果其他人遇到此问题,则发布答案,Google上没有太多信息。 在我们的案例中,我们使用的是仅定义了2个声明的自定义范围。

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

            WebHookUser.IdClaimsType = Constants.CustomClaimTypes.<Claim defined in scope>;

Easy when you step back and think about the problem with fresh eyes.

相关问题