Home > Blockchain >  How do to add IdentityServer4 to an existing web api?
How do to add IdentityServer4 to an existing web api?

Time:08-08

I currently am building a .NET 6 web api, and I want to add IdentityServer4 to the project and migrate it to my database too. I have checked their documentation and a lot of tutorials but none of them seem to show how to add IdentityServer4 to an already existing web api and database.

CodePudding user response:

You should always deploy IdentityService in a separate "service", don't mix it with the API or the client project. Otherwise, it will be hard to reason about the system.

Then in the API you just use the AddJwtBearer handler to communicate with IdentityServer. AddJwtBearer will then validate the received access tokens and create a ClaimsPrincipal user object from it. That user can then be used to authorize the user.

IdentityServer includes a package that can communicate against an ASP.NET Identity based database that you can use ASP.NET Identity to manage. see https://docs.identityserver.io/en/latest/quickstarts/5_entityframework.html#identityserver4-entityframework

  • Related