Exemplo n.º 1
0
        internal static IdentityConfiguration DeserializeIdentityConfiguration(JsonElement element)
        {
            if (element.TryGetProperty("identityType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "AMLToken": return(AmlToken.DeserializeAmlToken(element));

                case "Managed": return(ManagedIdentity.DeserializeManagedIdentity(element));

                case "UserIdentity": return(UserIdentity.DeserializeUserIdentity(element));
                }
            }
            IdentityConfigurationType identityType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("identityType"))
                {
                    identityType = new IdentityConfigurationType(property.Value.GetString());
                    continue;
                }
            }
            return(new IdentityConfiguration(identityType));
        }
Exemplo n.º 2
0
 internal ManagedIdentity(IdentityConfigurationType identityType, Guid?clientId, Guid?objectId, string resourceId) : base(identityType)
 {
     ClientId     = clientId;
     ObjectId     = objectId;
     ResourceId   = resourceId;
     IdentityType = identityType;
 }
Exemplo n.º 3
0
        internal static UserIdentity DeserializeUserIdentity(JsonElement element)
        {
            IdentityConfigurationType identityType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("identityType"))
                {
                    identityType = new IdentityConfigurationType(property.Value.GetString());
                    continue;
                }
            }
            return(new UserIdentity(identityType));
        }
Exemplo n.º 4
0
        internal static ManagedIdentity DeserializeManagedIdentity(JsonElement element)
        {
            Optional <Guid?>          clientId     = default;
            Optional <Guid?>          objectId     = default;
            Optional <string>         resourceId   = default;
            IdentityConfigurationType identityType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("clientId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        clientId = null;
                        continue;
                    }
                    clientId = property.Value.GetGuid();
                    continue;
                }
                if (property.NameEquals("objectId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        objectId = null;
                        continue;
                    }
                    objectId = property.Value.GetGuid();
                    continue;
                }
                if (property.NameEquals("resourceId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        resourceId = null;
                        continue;
                    }
                    resourceId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("identityType"))
                {
                    identityType = new IdentityConfigurationType(property.Value.GetString());
                    continue;
                }
            }
            return(new ManagedIdentity(identityType, Optional.ToNullable(clientId), Optional.ToNullable(objectId), resourceId.Value));
        }