codekoenig / aspnetcore.identity.documentdb Goto Github PK
View Code? Open in Web Editor NEWA Cosmos DB / DocumentDB Storage Provider for ASP.NET Core Identity
A Cosmos DB / DocumentDB Storage Provider for ASP.NET Core Identity
WebApi has no configure services method so I'm struggling to get this to run in a webapi 2 project on aspnet
Hi,
Is it possible to configure the solution to take document db collection name as parameter? It looks like currently the solution defaults to "default" collection in a document db. If so I would like to contribute this feature to the solution.
Thanks,
Himanshu.
To be able to store multiple app in the same collection, using Fullname for DocumentType instead of Name would bring this benefit I guess.
Getting an error I'm not quite understanding because the JsonClaimConverter looks right to me:
Json.JsonSerializationException: Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'claims[0].Type'
Which makes sense since Claim does not have an empty constructor. Any help would be appreciated.
If I create a user without claims it can log in without any errors.
If I add some claims to the user upon registration then the user cannot log in.
The error is thrown when the DocumentDbUserStore
FindByNameAsync
or FindByEmailAsync
actions try to read the user data.
The problem is that the Document DB SDK does not respect the JsonConver.DefaultSettings
. You wrote in a comment that this is a workaround but it is not the case.
// TODO: Until DocumentDB SDK exposes it's JSON.NET settings, we need to hijack the global settings to serialize claims
JsonConvert.DefaultSettings = () =>
{
return new JsonSerializerSettings()
{
Converters = new List<JsonConverter>() { new JsonClaimConverter(), new JsonClaimsPrincipalConverter(), new JsonClaimsIdentityConverter() }
};
};
I forked the repository and I get the following error message:
{Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'claims[0].Type', line 1, position 503.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
at Microsoft.Azure.Documents.QueryResult.Convert(Type type)
at Microsoft.Azure.Documents.QueryResult.AsType[T]()
at Microsoft.Azure.Documents.Client.FeedResponseBinder.Convert[T](FeedResponse`1 dynamicFeed)
at Microsoft.Azure.Documents.Linq.DocumentQuery`1.<GetEnumerator>d__31.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at AspNetCore.Identity.DocumentDb.Stores.DocumentDbUserStore`2.FindByNameAsync(String normalizedUserName, CancellationToken cancellationToken)
Not sure if it's just me doing something wrong but i can create a user no problem (and then use that straight away). But if i log in again with that user i get:
ArgumentNullException: Value cannot be null.
Parameter name: value
System.Security.Claims.Claim..ctor(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject, string propertyKey, string propertyValue)
As far as i can tell the actual document stored seems okay. So i'm a bit confused where this is coming from.
Any pointers?
thanks
Paul
Hi!
I am getting an ObjectDisposedException after a couple of operations.
Any ideas why?
StackTrace:
Exception has occurred: CLR/System.ObjectDisposedException
Exception thrown: 'System.ObjectDisposedException' in Microsoft.Extensions.Identity.Core.dll: 'Cannot access a disposed object.'
at Microsoft.AspNetCore.Identity.UserManager`1.ThrowIfDisposed()
at Microsoft.AspNetCore.Identity.UserManager`1.GetUsersInRoleAsync(String roleName)
at Happenings.Web.Startup.<InitializeUsers>d__8.MoveNext() in
Georgios
In Identity, sometimes all we have is a UserId
or UserName
only, but querying for as User with those already requires to know the according PartitionKey
. A generic, fast and convenient way to get a PartitionKey
from either a UserId
or a UserName
, when the PartitionKey
can really be anything, needs to be figured out (just for example: when creating a user with a PartitionKey
, store a UserId
-UserName
-PartitionKey
mapping in DocumentDb).
hi,
the code below does not remove my claim from Cosmo db user object.
await _userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, role));
is there a bug or I am doing something wrong
This might be a really simple question... How are the documents updated?
Looking through the code, I can see where a document might be created, and I can see how documents are found (based on id or name etc) - these all reference the DocumentClient.
However, I can't see anything that performs the write to update a document. Am I being really stupid? Where does this happen?
Add tests for all UserStore methods that are not covered yet
I have notice the project uses Microsoft.Azure.DocumentDB.Core, this library is deprecated and I understand is going to not be supported after August 31st, 2022.
My question is:
Is there a consideration to use Microsoft.Azure.Cosmos instead of DocumentDB?
In the sample app, the extension method AddDefaultDocumentClientForIdentity
is used. While this method exists in the source code, it does not exist in the NuGet library.
Ah, the library hasn't been updated since 2017! What's the status of this project?
I followed steps in the Readme, and when attempting to register a new user, I get this exception: BadRequestException: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.
Full Exception race is here:
Microsoft.Azure.Documents.Routing.PartitionRoutingHelper.GetProvidedPartitionKeyRanges(SqlQuerySpec querySpec, bool enableCrossPartitionQuery, bool parallelizeCrossPartitionQuery, PartitionKeyDefinition partitionKeyDefinition, QueryPartitionProvider queryPartitionProvider, string clientApiVersion, out QueryInfo queryInfo) Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext+<TryGetTargetPartitionKeyRangeAsync>d__5.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext+<ExecuteOnceAsync>d__4.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.BackoffRetryUtility+<>c__DisplayClass1_0+<<ExecuteAsync>b__0>d.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.BackoffRetryUtility+<ExecuteRetry>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.Azure.Documents.BackoffRetryUtility+<ExecuteRetry>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.BackoffRetryUtility+<ExecuteAsync>d__1.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase+<ExecuteWithRetryPolicy>d__46.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext+<ExecuteInternalAsync>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase+<ExecuteNextAsync>d__35.MoveNext()
Hello,
I can not get the project to run, as the project reference in IdentitySample.Mvc to AspNetCore.Identity.DocumentDb states: "Incompatible target framework 4.6.1".
And the other problem is that the packages are unable to be restored, at the end of the Package Console output this is the message:
Errors in /Users/daniel/Documents/Xamarin/AspNetCore.Identity.DocumentDb/src/AspNetCore.Identity.DocumentDb/AspNetCore.Identity.DocumentDb.csproj Package Microsoft.Azure.DocumentDB.Core 1.1.2 is not compatible with net46 (.NETFramework,Version=v4.6). Package Microsoft.Azure.DocumentDB.Core 1.1.2 supports: netstandard1.6 (.NETStandard,Version=v1.6) One or more packages are incompatible with .NETFramework,Version=v4.6.
Hello,
Will this package be updated to support latest ASP.NET Core 2.0 ?
https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x
Best regards
MissingMethodException: Method not found: 'System.Threading.Tasks.Task1<Microsoft.Azure.Documents.Client.ResourceResponse
1<Microsoft.Azure.Documents.Document>> Microsoft.Azure.Documents.IDocumentClient.ReadDocumentAsync(System.Uri, Microsoft.Azure.Documents.Client.RequestOptions)'.
AspNetCore.Identity.DocumentDb.Tools.DocumentDbExtensions.ReadDocumentAsync(IDocumentClient client, Uri documentUri, RequestOptions requestOptions)
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start(ref TStateMachine stateMachine)
AspNetCore.Identity.DocumentDb.Tools.DocumentDbExtensions.ReadDocumentAsync(IDocumentClient client, Uri documentUri, RequestOptions requestOptions)
AspNetCore.Identity.DocumentDb.Tools.DocumentDbExtensions.ReadDocumentAsync(IDocumentClient client, Uri documentUri)
AspNetCore.Identity.DocumentDb.Stores.DocumentDbUserStore<TUser, TRole>.FindByIdAsync(string userId, CancellationToken cancellationToken)
Hi,
I am running into a runtime error when logging in with a newly created user through:
result = await _userManager.AddLoginAsync
The same issue is mentioned here.
Any input on how to solve this or if its more deeply related to this library?
Just created new empty ASP.NET Core 3.1 project, added CodeKoenig.AspNetCore.Identity.DocumentDb
, and facing this exception:
System.TypeLoadException: Method 'NormalizeName' in type 'AspNetCore.Identity.DocumentDb.LookupNormalizer' from assembly 'CodeKoenig.AspNetCore.Identity.DocumentDb, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.\r\n at AspNetCore.Identity.DocumentDb.IdentityDocumentDbBuilderExtensions.AddDocumentDbStores(IdentityBuilder builder, Action`1 setupAction)\r\n at CosmosIdentity.Startup.ConfigureServices(IServiceCollection services)
The whole project file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CodeKoenig.AspNetCore.Identity.DocumentDb" Version="2.0.0" />
</ItemGroup>
</Project>
This is the only change I made to the template code:
public void ConfigureServices(IServiceCollection services) {
services.AddSingleton<IDocumentClient>(new DocumentClient(
serviceEndpoint: new Uri("https://localhost:8081/"),
authKeyOrResourceToken: "LOCAL"));
services.AddIdentity<DocumentDbIdentityUser, DocumentDbIdentityRole>()
.AddDocumentDbStores(options => {
options.Database = "CosmosIdentity";
options.UserStoreDocumentCollection = "AspNetIdentity";
})
.AddDefaultTokenProviders();
}
SSL is required in almost all environments these days. SSL should be enabled by default.
I'll file a PR shortly.
The AspNetCore.Identity seems to expected NormalizedRoleName
.
And it would break if RoleName is difference from NormalizedRoleName. Eg. "ADMIN" vs "admin".
It could be reproduce by changing the ShouldAddUserToRole
test case:
from
DocumentDbIdentityRoleBuilder.Create()
to
DocumentDbIdentityRoleBuilder.Create("ANonNormalizedString")
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.