/IdentityServer4.Samples.Mongo

Project inspired in the "IdentityServer4.Samples" that shows how to use MongoDB for the configuration data.

Primary LanguageC#

IdentityServer4 Sample for MongoDB

IdentityServer4 samples that shows how to use MongoDB for the configuration data. These sample are based on IdentityServer4.quickstart.samples.

Solution overview:

This repo contains 02 samples based on MongoDB:

  1. IdentityServer4-mongo: Similar to [Quickstart #8: EntityFramework configuration] (https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/Quickstarts/8_EntityFrameworkStorage) but using MongoDB for the configuration data.
  1. IdentityServer4-mongo-AspIdentity: More elaborated sample based on uses ASP.NET Identity for identity management that uses using MongoDB for the configuration data.

Each Sample Solution listed above is composed of:

  • QuickstartIdentityServer - project based on IdentityServer4 that manages authentication
  • API - is a sample API project, used by client/* projects to showcase QuickstartIdentityServer functionality
  • clients/MvcClient - Asp .Net Core mvc client project sample
  • clients/Client - .NET Core console client project sample

Technical dependencies


Running the solution

Getting one of those sample project up and running on your machine should be fairly straightforward once you have any MongoDB running.

  • If you do not have MongoDB in your environment or wish to run it locally please take a look at Setup mongo
  1. With mongo depency resolved, open the selected project in Visual Studio.
  2. Make sure you have multiple projects selected to startup - "QuickstartIdentityServer", "Api" and any desired client (e.g. Clients\MvcClient) before executing solution from Visual Studio - see screenshots below:

First execution

In your very first execution you should get an exception stating that "Mongo Repository was created/populated! Please restart your website..."

This is because the first execution will automatically create a new Mongo Repository (database), but due to MongoDB.Driver limitations it is necessary to restart the solution in order to proper configure MongoDB to ignore Extra Elements such as "_id" that does not exist in IdentityServer4.Models classes.

Authentication

Once the MongoDB is created, you should see two browser tabs, one related to the MvcClient and the other related to QuickstartIdentityServer. In the Click on "Secure" menu In the the MvcClient, click on "secure", you will be redirected to QuickstartIdentityServer authentication page - it is almost identical to all original [IdentityServer4.Samples] (https://github.com/IdentityServer/IdentityServer4.Samples/), but for your convinience we took the opportunity to display a some sample user/password that were automatically added to the MongoDB.

Aditional information