是这样的,网上介绍的Oauth认证一般都是授权服务器和资源服务器分开,但是我只想在一个网站中使用asp.net core自带的Identity认证给用户访问网站用,同时提供一些api接口通过Token访问给app使用,于是参照网上的各种教程使用IdentityServer实现了Grant_Type=password的授权访问后,发现Identity的认证又用不了了,其实.net core 的这一套SignInManager框架还是挺好用的。经过多天查找,终于了解应该是默认验证框架的原因,解决方法有一下两个:

1.设置Api的 [Authorize] ,指定为 [Authorize (AuthenticationSchemes =  "Identity.Application" +","+ JwtBearerDefaults.AuthenticationScheme) ]

   AuthenticationSchemes 是可以指定多个验证框架的,这里指定了Identity的Identity.Application验证和 “Bearer”验证,注意,Identity的验证不是用的Cookies Authorization。

asp.net core 同时添加Identity和Bearer认证

 

2.设置默认的 Policy。

  在ConfigureServices配置默认的Policy,也可以设置一个Policy后在【Authorize】中指定。

 asp.net core 同时添加Identity和Bearer认证

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2018-05-29
  • 2021-09-20
  • 2022-12-23
  • 2022-01-10
猜你喜欢
  • 2021-12-28
  • 2022-12-23
  • 2018-12-13
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案