简体   繁体   中英

.net core 5.0 with IdentityServer4 returns for api method 404

I setup my initial solution on GitHub .

I setup swagger authorization as well as sql db user identity (program picks up correctly seeded data) and program lets me be authorized. But When I call my method /WeatherForecast it returns 404.

Whole my code is on the above repo link. 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)

I also read about jhow important is order in Startup class for app.UseAuthentication; app.UseAuthorization app.UseAuthentication; app.UseAuthorization and I checked that also.

I dont know what else I need to do in order to gain SuccessCode 200.

for those who would like to run it locally from my github repo:

appsettings.Development -> just point to local sql db server and empty database in order to start seeding the data.

client_id: the-big-client client_secret: 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 .

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. Therefore, they must be two separate APIs running by themselves. So, you should not add/use all the Identity Server wiring in your Fancy API .

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.

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. However, you then add authorization here .

The IdentityServer4 repository has some very good samples to guide us, including one for Client Credentials flow here . This may certainly help you out:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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