简体   繁体   English

.net 核心 5.0 与 IdentityServer4 返回 api 方法 404

[英].net core 5.0 with IdentityServer4 returns for api method 404

I setup my initial solution on GitHub .我在GitHub上设置了我的初始解决方案。

I setup swagger authorization as well as sql db user identity (program picks up correctly seeded data) and program lets me be authorized.我设置了 swagger 授权以及 sql db 用户身份(程序获取正确的种子数据)并且程序让我获得授权。 But When I call my method /WeatherForecast it returns 404.但是当我调用我的方法/WeatherForecast它返回 404。

Whole my code is on the above repo link.我的整个代码都在上面的 repo 链接上。 Please tell me if you need to attach here directly some code.请告诉我您是否需要直接在此处附加一些代码。

Ofc, when I remove [Authorize] annotaion from my api controller, I can reach the method (enters into a method) Ofc,当我从我的 api controller 中删除 [Authorize] 注释时,我可以达到方法(进入方法)

I also read about jhow important is order in Startup class for app.UseAuthentication; app.UseAuthorization我还阅读了 jhow important is order in Startup class for app.UseAuthentication; app.UseAuthorization app.UseAuthentication; app.UseAuthorization and I checked that also. app.UseAuthentication; app.UseAuthorization我也检查了。

I dont know what else I need to do in order to gain SuccessCode 200.我不知道我还需要做什么才能获得 SuccessCode 200。

for those who would like to run it locally from my github repo:对于那些想从我的 github repo 本地运行它的人:

appsettings.Development -> just point to local sql db server and empty database in order to start seeding the data. appsettings.Development -> 只需指向本地 sql 数据库服务器和空数据库即可开始播种数据。

client_id: the-big-client client_secret: secret client_id:大客户 client_secret:秘密

please check both scopes (read, write)请检查两个范围(读、写)

You seem to want to use the Client Credentials flow to authenticate your API's Swagger... At least, it is the security definition you are adding to Swagger here .您似乎想使用客户端凭据流来验证您的 API 的 Swagger... 至少,这是您在此处添加到 Swagger 的安全定义。

However, as you can see from the link to the explanation of the flow, that requires your Identity Server and your Fancy API to talk to each other.但是,正如您从流程解释的链接中看到的那样,这需要您的Identity Server和您的Fancy API相互通信。 Therefore, they must be two separate APIs running by themselves.因此,它们必须是两个独立运行的 API。 So, you should not add/use all the Identity Server wiring in your Fancy API .因此,您不应在Fancy API中添加/使用所有 Identity Server 接线。

The authority against which your Swagger and your API are authenticating - as you define in the authorization and token URLs - must be that Identity Server.您的 Swagger 和 API 进行身份验证的权限 - 正如您在授权和令牌 URL中定义的那样 - 必须是该身份服务器。

Moreover, you have the authentication of your API commented out here - and with an authority different from Swagger -, so you do not seem to be using the token you are receiving.此外,您的 API 的身份验证已在此处注释掉 - 并且具有不同于 Swagger 的权限 - 所以您似乎没有使用您收到的令牌。 However, you then add authorization here .但是,您随后在此处添加授权。

The IdentityServer4 repository has some very good samples to guide us, including one for Client Credentials flow here . IdentityServer4存储库有一些非常好的示例来指导我们,包括一个用于客户端凭证流程示例。 This may certainly help you out:)这当然可以帮助你:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM