AspNetCore.Identity.DocumentDb
AspNetCore.Identity.DocumentDb copied to clipboard
Error running application after upgrade to core 2.0
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?
Hi,
I've managed to overcome this issue by creating a new JsonConverter that ignores the ClaimsPrincipal
public class JsonClaimsPrincipalConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(ClaimsPrincipal));
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var objectToSerialize = new { }; //create the object you want to serialize here, based on your dynamic conditions
new JsonSerializer().Serialize(writer, objectToSerialize); //serialize the object to the current writer
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
Not sure if that was supposed to be intendent? Maybe it should not ignore the entire object, but just extract the Claims list and reconstruct the ClaimsPrincipal on Read?
At least I can login using this, not sure if all features of Identity are still available.
I tried adding a pull request with some new converters. Unsure if they will fit all scenarios though. #18
Hi,
I am having the same error. I created a basic .Net Core 2.0 MVC Web application and added external login functionality to it. Everything works fine with SQL Server but when I am using this package, result = await _userManager.AddLoginAsync throws exception similar to what it is mentioned above.
Apparently, the user document is being created in the DocumentDB but external logins are not being added because of the error.
Thanks.
@rafaykh90 Thanks to the PRs of @joaomatossilva and @projecteon, with the current bits this should work fine now (without any code changes on your side for now, which might change if we can't get the back compat issue discussed in #17 sorted out). I'll try to get a prerelease NuGet package out there soon, in the meantime you could download the latest bits yourself.
A cheese workaround for JsonClaimConverter issues.
[JsonProperty(PropertyName = "claims")] [JsonConverter(typeof(JsonClaimConverter))] public IList<Claim> Claims { get; set; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
IList<Claim> claims = new List<Claim>();
JToken jt = JObject.ReadFrom(reader);
for (int i = 0; i < jt.Count(); i++)
{
string type = jt.Values<string>("Type").FirstOrDefault();
string value = jt.Values<string>("Value").FirstOrDefault();
string valueType = jt.Values<string>("ValueType").FirstOrDefault();
string issuer = jt.Values<string>("Issuer").FirstOrDefault();
string originalIssuer = jt.Values<string>("OriginalIssuer").FirstOrDefault();
claims.Add(new Claim(type, value, valueType, issuer, originalIssuer));
}
return claims;
}