Exemplo n.º 1
0
    public void CanMapScope()
    {
        var model        = new Duende.IdentityServer.Models.ApiScope();
        var mappedEntity = model.ToEntity();
        var mappedModel  = mappedEntity.ToModel();

        Assert.NotNull(mappedModel);
        Assert.NotNull(mappedEntity);
    }
    public async Task CreateAsync(ApiScopeModel model)
    {
        var scope = new Duende.IdentityServer.Models.ApiScope()
        {
            Name        = model.Name,
            DisplayName = model.DisplayName?.Trim()
        };

        var claims = model.UserClaims?.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray() ?? Enumerable.Empty <string>();

        if (claims.Any())
        {
            scope.UserClaims = claims.ToList();
        }

        _context.ApiScopes.Add(scope.ToEntity());
        await _context.SaveChangesAsync();
    }
Exemplo n.º 3
0
    public void Properties_Map()
    {
        var model = new Duende.IdentityServer.Models.ApiScope()
        {
            Description = "description",
            DisplayName = "displayname",
            Name        = "foo",
            UserClaims  = { "c1", "c2" },
            Properties  =
            {
                { "x", "xx" },
                { "y", "yy" },
            },
            Enabled = false
        };


        var mappedEntity = model.ToEntity();

        mappedEntity.Description.Should().Be("description");
        mappedEntity.DisplayName.Should().Be("displayname");
        mappedEntity.Name.Should().Be("foo");

        mappedEntity.UserClaims.Count.Should().Be(2);
        mappedEntity.UserClaims.Select(x => x.Type).Should().BeEquivalentTo(new[] { "c1", "c2" });
        mappedEntity.Properties.Count.Should().Be(2);
        mappedEntity.Properties.Should().Contain(x => x.Key == "x" && x.Value == "xx");
        mappedEntity.Properties.Should().Contain(x => x.Key == "y" && x.Value == "yy");


        var mappedModel = mappedEntity.ToModel();

        mappedModel.Description.Should().Be("description");
        mappedModel.DisplayName.Should().Be("displayname");
        mappedModel.Enabled.Should().BeFalse();
        mappedModel.Name.Should().Be("foo");
        mappedModel.UserClaims.Count.Should().Be(2);
        mappedModel.UserClaims.Should().BeEquivalentTo(new[] { "c1", "c2" });
        mappedModel.Properties.Count.Should().Be(2);
        mappedModel.Properties["x"].Should().Be("xx");
        mappedModel.Properties["y"].Should().Be("yy");
    }
Exemplo n.º 4
0
 private static void SeedApiScopeClaims(IAdminStore <Entity.ApiScopeClaim> apiScopeClaimStore, ISModels.ApiScope resource)
 {
     foreach (var claim in resource.UserClaims)
     {
         try
         {
             apiScopeClaimStore.CreateAsync(new Entity.ApiScopeClaim
             {
                 ApiScopeId = resource.Name,
                 Id         = Guid.NewGuid().ToString(),
                 Type       = claim
             }).GetAwaiter().GetResult();
         }
         catch (ArgumentException)
         {
             // silent
         }
     }
 }
Exemplo n.º 5
0
 private static void SeedApiScopeProperties(IAdminStore <Entity.ApiScopeProperty> apiScopePropertyStore, ISModels.ApiScope resource)
 {
     foreach (var property in resource.Properties)
     {
         try
         {
             apiScopePropertyStore.CreateAsync(new Entity.ApiScopeProperty
             {
                 ApiScopeId = resource.Name,
                 Id         = Guid.NewGuid().ToString(),
                 Key        = property.Key,
                 Value      = property.Value
             }).GetAwaiter().GetResult();
         }
         catch (ArgumentException)
         {
             // silent
         }
     }
 }