Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DocumentDb Identity Provider for ASP.NET Core

Tags:

asp.net-core

I am trying to provide authorization to the user, using DocumentDb at the backend - But I am unable to find any resources regarding the same. The documentation provided is for SQL based ones (https://docs.asp.net/en/latest/security/authentication/identity.html).

Any help?

like image 809
Arun Selva Kumar Avatar asked Aug 25 '16 16:08

Arun Selva Kumar


2 Answers

To provide you with a starting point, there are several important issues to bear in mind when looking at using Identity with ASP.Net Core:

Framework Compatibility

You mention that you will be using ASP.Net Core, and this can be used with either .Net Core, or the 'full' .Net Framework (e.g. .Net Framework 4.5.1), which can be specified in your project.json under the frameworks property.

The Microsoft DocumentDB native .Net client does not support .Net Core; so, you must configure ASP.Net Core to target the 'full' .Net Framework. If you are unsure how to do this, you can create a new project in Visual Studio 2015, and select the 'ASP.Net Core (.Net Framework)' Project Template; the project.json will have its framework property correctly configured for you.

'Identity' Version

There are several versions of ASP.Net Identity; be aware when selecting a provider, that most currently reference ASP.Net Identity 2.2.1; however, the latest version is 3, released alongside ASP.Net Core, supported by the NuGet package Microsoft.AspNetCore.Identity 1.0.0, which has some differences and additional features. (Note that you can use this latter package with the full .Net Framework.)

No Official Implementation

Microsoft has decided not to create an official DocumentDB implementation for ASP.Net Identity, citing that 'there are two community projects available' (reference here)

Third-Party Support

Of the available third-party implementations, this one by Adrian Fernandez is the most widely used that provides support for ASP.Net Identity 3 using the Microsoft native DocumentDB client. Samples are included in the GitHub repository. (Please see update below.)

Example Usage

An example of using this DocumentDB provider with ASP.Net, including additional features, can be found here.

An additional example of using ASP.Net Core with the Microsoft DocumentDB provider can be found here.

I have written my own Identity 3 provider for DocumentDB; if I release this on GitHub I will update this answer with a link.

UPDATE 19/04/2017

For those looking for a solution, I now recommend the AspNetCore.Identity.DocumentDb project by Bernhard Koenig. It is feature-complete, includes Unit Tests, and a sample ASP.Net Core project. Also available via Nuget. It supports netstandard1.6 an net46 profiles.

like image 101
dmcquiggin Avatar answered Sep 20 '22 23:09

dmcquiggin


my understanding is the Microsoft made it possible to use Mongo drivers with DocumentDb so maybe you could use this Mongo implementation for asp.net core identity

or google further for existing work that others may have done in this direction.

To implement it yourself you would need to implement at minimum IUserStore and IRoleStore you can also refer to the EF implementations UserStore and RoleStore for inspiration and guidance on implementing those.

like image 45
Joe Audette Avatar answered Sep 21 '22 23:09

Joe Audette