In this repo we will implement IdentityServer with ASP.NET Core Identity and MongoDB as Database. So, the MongoDB will be the Identity Database instead of SQL Server. I have explained all the setup steps on my tutorial. This tutorial contains the following topics.
- What is IdentityServer
- What we will build?
- IdentityServer OpenID Connect OAuth 2.0
- Creating IdentityServer 4 Project
- Setup IdentityServer in ASP.NET Core
- IdentityServer settings in appsettings.json
- What are IdentityServer Clients
- What are IdentityServer ApiScopes
- What are IdentityServer ApiResources
- Defining IdentityServer settings class
- Configure IdentityServer on Startup.cs
- IdentityServer Discovery Endpoint
- Fetching IdentityServer Token from Postman
- Implementing OpenID Connect
- Calling IdentityServer secured Web API
- IdentityServer Role Based Authentication
- Role Claim in OpenID Connect
- Role claims in the ClaimsPrincipal
- Securing Controllers with Role Based Authentication
- IdentityServer Policy Based Authentication
There are 2 projects: - ISExample
& ISClient
. ISExample is the Identity Server. ISClient is the client that contains secured web api.
Running "ISExample"
- Inside the ISExample project their is docker-compose.yml
for MongoDB. Run it with docker-compose up -d
to start the container. Now run "ISExample" on IIS Express. Now create user account with the "Create Identity User" link on the Menu. It's url is - https://localhost:44312/Operations/Create
. If you want to go to details about MongoDB and Identity setup then visit ASP.NET Core Identity with MongoDB as Database/.
Running "ISClient"
- Run the project on https kestrel hosting and not IIS Express. Now click "Secured" menu link. You will be redirected to Identity Server asking to log on. Log on with your account. Next you will be redirected to client project and you will see secured weather data.
Note - If you want to test login again then you have to delete all the cookies from the "Application" tab of developers tools of your browser.
Your support of every $5 will be a great reward for me to carry on my work. Thank you!