Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running application after upgrade to core 2.0 #16

Open
projecteon opened this issue Nov 6, 2017 · 5 comments
Open

Error running application after upgrade to core 2.0 #16

projecteon opened this issue Nov 6, 2017 · 5 comments
Assignees
Milestone

Comments

@projecteon
Copy link
Contributor

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?

@joaomatossilva
Copy link
Contributor

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.

@projecteon
Copy link
Contributor Author

I tried adding a pull request with some new converters. Unsure if they will fit all scenarios though. #18

@rafaykh90
Copy link

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.

@codekoenig codekoenig self-assigned this Dec 17, 2017
@codekoenig
Copy link
Owner

@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.

@codekoenig codekoenig added the bug label Dec 18, 2017
@codekoenig codekoenig added this to the 2.1.0 milestone Dec 18, 2017
@jpmtl
Copy link

jpmtl commented Feb 1, 2018

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants