dlmelendez / identitydocumentdb Goto Github PK
View Code? Open in Web Editor NEWAzure DocumentDB Provider for ASP.NET Identity 2.0 framework.
License: MIT License
Azure DocumentDB Provider for ASP.NET Identity 2.0 framework.
License: MIT License
Upgraded to latest stable v 1.15.0 of Microsoft.Azure.DocumentDB nuget and I'm getting the following exception.
System.MissingMethodException occurred HResult=0x80131513 Message=Method not found: 'Void Microsoft.Azure.Documents.Client.DocumentClient..ctor(System.Uri, System.String, Microsoft.Azure.Documents.Client.ConnectionPolicy, System.Nullable
1<Microsoft.Azure.Documents.ConsistencyLevel>)'.
Source=ElCamino.AspNet.Identity.DocumentDB
StackTrace:
at ElCamino.AspNet.Identity.DocumentDB.IdentityCloudContext6..ctor(String uri, String authKey, String database, ConnectionPolicy policy, String usersCollection, String rolesCollection) at ElCamino.AspNet.Identity.DocumentDB.IdentityCloudContext
1..ctor(String uri, String authKey, String database, ConnectionPolicy policy, String usersCollectionName, String rolesCollectionName)`
Hi,
Just trying to get this set up - it works fine, but it creates a new Users collection - I want this inside existing db. Is there any way to configure this?
This may not be a bug with ElCamino.AspNet.Identity.DocumentDB which is what I am using to interface with Azure CosmosDB. I am able to create dabase and collection on the fly and I am able to add/update items just fine. However, when I go to Azure and try to see the data in Data Explorer I get error saying {"code":500,"body":"Object reference not set to an instance of an object."}.
Anyone encountered this problem?
I think it has to do with Azure interface but I suspect if ElCamino.AspNet.Identity.DocumentDB is out of sync with Azure on data layout. I am doing a POC and ElCamino saved me time. Hope I don't have to reinvent my own documentdb repository myself!
I would appreciate your feedback.
Thanks,
Prodip
Hi, I get an error in this line Into ExternalLoginConfirmation Method in AccountController:
result = await _userManager.AddLoginAsync(user, info);
Looking at source files, It seems that the property user.SelfLink is null into UpdateAsync Method.
Thanks.
When adding claims, I get an "ArgumentNullException: Value cannot be null. Parameter name: documentLink" after successfully creating a user...
result = await userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, "Admin")).ConfigureAwait(false);
I don't quite understand why the async code is written in this way: Start a new task, then block that task in waiting.
public async virtual Task CreateAsync(TUser user)
{
......
await new TaskFactory().StartNew(() =>
{
var docTask = Context.Client.CreateDocumentAsync(Context.UserDocumentCollection.DocumentsLink, user
, Context.RequestOptions, true);
docTask.Wait();
var doc = docTask.Result;
Context.SetSessionTokenIfEmpty(doc.SessionToken);
JsonConvert.PopulateObject(doc.Resource.ToString(), user);
});
}
public async virtual Task CreateAsync(TUser user)
{
......
var response = await Context.Client.CreateDocumentAsync(Context.UserDocumentCollection.DocumentsLink, user
, Context.RequestOptions, true);
Context.SetSessionTokenIfEmpty(response.SessionToken);
}
Since DocumentDB on Azure now charges by the collection, it makes more sense to let the user of this library control where the UserStore and RoleStore are backed in the database.
I have modified the Constants file so that it reads the UsersCollection and RolesCollection names from the WebConfig file instead of being hard-coded by the library.
For instance:
public static class AppSettingsKeys
{
public const string DatabaseNameKey = "IdDocDb_Database";
public const string DatabaseUriKey = "IdDocDb_Uri";
public const string DatabaseAuthKey = "IdDocDb_AuthKey";
public const string RolesCollectionKey = "IdDocDb_RolesCollectionKey";
public const string UsersCollectionKey = "IdDocDb_UsersCollectionKey";
}
public static class DocumentCollectionIds
{
private static string _rolesCollection;
private static string _usersCollection;
public static string RolesCollection
{
get
{
if (string.IsNullOrEmpty(_rolesCollection))
{
_rolesCollection = ConfigurationManager.AppSettings[AppSettingsKeys.RolesCollectionKey];
}
return _rolesCollection;
}
}
public static string UsersCollection
{
get
{
if (string.IsNullOrEmpty(_usersCollection))
{
_usersCollection = ConfigurationManager.AppSettings[AppSettingsKeys.UsersCollectionKey];
}
return _usersCollection;
}
}
}
Let me know if you'd like me to create a pull request to submit this work.
Cheers,
Jon
could you please provide a sample on how to use Roles with this provider ?
Hi David, firstly really appreciate the work you've put into this. I've already built a user store, login, password hashing and Jwt token services - then found your library when researching the Asp.Net identity and store provider model.
I've rolled all my entities into a single collection using a compound partion key "pkey" which starts with the entity type name. I've simply added "Entity" as a base class into your inheritance chain for the Models, it contains an abstract string getter "pkey" - each class can then implement it's own compound string from its own members. the base class Entity takes care of adding the instance typename as a prefix.
The immediate benefit of this is being able to easily browse a mixture of records in the collection. I have yet to load test this approach - querying tens or hundreds of thousands of records.
The cost of each separate partition made me decide to try putting all my relatively static entities into the same partition - users, organizations, roles, inventory, etc
Apologies for polluting your issues list with this - if you have time would appreciate any suggestions or thoughts around this.
Regards
Andy Welch, NZ
Is possible for you to update the sample app to show the use with roles? I couldn't find any.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.