How can we integrate identityserver4 and web api in the same project(port) instead of creating different projects for each?

Viewed 4717

Couldn't configure the identityserver 4 authorization and bearer token authentication middleware in the same project.

3 Answers

It is now a built-in feature of Identityserver. Added with this PR.

services.AddLocalApiAuthentication();

And here is an official example of a protected API.

I suggest you make API and Identity Server in separate apps. This makes it a lot easier to maintain.

Identity server provides you the authentication against your clients/API's. The database operations , the business logic should be handled by your clients/APIs . So keep them in separate apps should be a better choice .

If you insist on making them in single project , you can click here and here for code samples.

You shouldn't.

The thing is that your authentication and your application are totally different services, with different scopes, and you should make them different.

This goes with Separation of Concern : if you want to change your auth service later, you won't have to modify your whole application.

Related