Git Product home page Git Product logo

Comments (5)

joaomatossilva avatar joaomatossilva commented on June 17, 2024

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.

from aspnetcore.identity.documentdb.

projecteon avatar projecteon commented on June 17, 2024

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

from aspnetcore.identity.documentdb.

rafaykh90 avatar rafaykh90 commented on June 17, 2024

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.

from aspnetcore.identity.documentdb.

codekoenig avatar codekoenig commented on June 17, 2024

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

from aspnetcore.identity.documentdb.

jpmtl avatar jpmtl commented on June 17, 2024

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

from aspnetcore.identity.documentdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.