Example #1
0
    public virtual ValueTask SetDescriptionAsync(OpenIddictScopeModel scope, string description, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        scope.Description = description;

        return(default);
    public static OpenIddictScopeModel ToModel(this OpenIddictScope entity)
    {
        if (entity == null)
        {
            return(null);
        }

        var model = new OpenIddictScopeModel
        {
            Id           = entity.Id,
            Description  = entity.Description,
            Descriptions = entity.Descriptions,
            DisplayName  = entity.DisplayName,
            DisplayNames = entity.DisplayNames,
            Name         = entity.Name,
            Properties   = entity.Properties,
            Resources    = entity.Resources
        };


        foreach (var extraProperty in entity.ExtraProperties)
        {
            model.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
        }

        return(model);
    }
Example #3
0
    public virtual ValueTask <ImmutableArray <string> > GetResourcesAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        if (string.IsNullOrEmpty(scope.Resources))
        {
            return(new ValueTask <ImmutableArray <string> >(ImmutableArray.Create <string>()));
        }

        using (var document = JsonDocument.Parse(scope.Resources))
        {
            var builder = ImmutableArray.CreateBuilder <string>(document.RootElement.GetArrayLength());

            foreach (var element in document.RootElement.EnumerateArray())
            {
                var value = element.GetString();
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                builder.Add(value);
            }

            return(new ValueTask <ImmutableArray <string> >(builder.ToImmutable()));
        }
    }
Example #4
0
    public virtual async ValueTask CreateAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        await Repository.InsertAsync(scope.ToEntity(), autoSave : true, cancellationToken : cancellationToken);

        scope = (await Repository.FindAsync(scope.Id, cancellationToken: cancellationToken)).ToModel();
    }
    public static OpenIddictScope ToEntity(this OpenIddictScopeModel model, OpenIddictScope entity)
    {
        Check.NotNull(model, nameof(model));
        Check.NotNull(entity, nameof(entity));

        entity.Description  = model.Description;
        entity.Descriptions = model.Descriptions;
        entity.DisplayName  = model.DisplayName;
        entity.DisplayNames = model.DisplayNames;
        entity.Name         = model.Name;
        entity.Properties   = model.Properties;
        entity.Resources    = model.Resources;

        foreach (var extraProperty in model.ExtraProperties)
        {
            entity.ExtraProperties.Remove(extraProperty.Key);
            entity.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
        }

        return(entity);
    }
    public static OpenIddictScope ToEntity(this OpenIddictScopeModel model)
    {
        Check.NotNull(model, nameof(model));

        var entity = new OpenIddictScope(model.Id)
        {
            Description  = model.Description,
            Descriptions = model.Descriptions,
            DisplayName  = model.DisplayName,
            DisplayNames = model.DisplayNames,
            Name         = model.Name,
            Properties   = model.Properties,
            Resources    = model.Resources
        };

        foreach (var extraProperty in model.ExtraProperties)
        {
            entity.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
        }

        return(entity);
    }
Example #7
0
    public virtual async ValueTask DeleteAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        await Repository.DeleteAsync(scope.Id, autoSave : true, cancellationToken : cancellationToken);
    }
Example #8
0
    public virtual ValueTask <ImmutableDictionary <string, JsonElement> > GetPropertiesAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        if (string.IsNullOrEmpty(scope.Properties))
        {
            return(new ValueTask <ImmutableDictionary <string, JsonElement> >(ImmutableDictionary.Create <string, JsonElement>()));
        }

        using (var document = JsonDocument.Parse(scope.Properties))
        {
            var builder = ImmutableDictionary.CreateBuilder <string, JsonElement>();

            foreach (var property in document.RootElement.EnumerateObject())
            {
                builder[property.Name] = property.Value.Clone();
            }

            return(new ValueTask <ImmutableDictionary <string, JsonElement> >(builder.ToImmutable()));
        }
    }
Example #9
0
    public virtual ValueTask <string> GetNameAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        return(new ValueTask <string>(scope.Name));
    }
Example #10
0
    public virtual ValueTask <string> GetIdAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        return(new ValueTask <string>(ConvertIdentifierToString(scope.Id)));
    }
Example #11
0
    public virtual ValueTask <ImmutableDictionary <CultureInfo, string> > GetDisplayNamesAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
    {
        Check.NotNull(scope, nameof(scope));

        if (string.IsNullOrEmpty(scope.DisplayNames))
        {
            return(new ValueTask <ImmutableDictionary <CultureInfo, string> >(ImmutableDictionary.Create <CultureInfo, string>()));
        }

        using (var document = JsonDocument.Parse(scope.DisplayNames))
        {
            var builder = ImmutableDictionary.CreateBuilder <CultureInfo, string>();

            foreach (var property in document.RootElement.EnumerateObject())
            {
                var value = property.Value.GetString();
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                builder[CultureInfo.GetCultureInfo(property.Name)] = value;
            }

            return(new ValueTask <ImmutableDictionary <CultureInfo, string> >(builder.ToImmutable()));
        }
    }