如何使用OpenIddict创建一个身份验证用户来检索令牌以使用Integration Test

问题描述 投票:0回答:1

大家,

我有一个带有OpenIddict身份验证的web api。

  • Core.Net 2.0(C#),
  • EntityFrameWorkCore 2.0

我想做集成测试,但我的控制器有Authorize属性,所以我需要一个验证用户。

对于我的IT,我使用的SQLite有一个内存模式,docs

我不知道如何创建用户身份验证和检索令牌,我需要传递给Web Api调用。

有什么建议?

最好的祝福。

Jolynice

authentication token integration openiddict
1个回答
0
投票

对于完整的集成测试,您可以使用自定义授权类型,如在此其他SO线程中使用的那样:Rich Twitter Digits/Google Auth with OpenIdDictServer

如果您只是想测试受[Authorize]保护的动作,则更容易模拟ISecureDataFormat<AuthenticationTicket>并使用它来设置OAuthValidationOptions.AccessTokenFormat。您可以查看the aspnet-contrib validation handler tests,看看如何使用ASP.NET Core的TestServer完成它。

© www.soinside.com 2019 - 2024. All rights reserved.