public void GivenIds3IdentityScopeWithUserClaims_ExpectClaimsCorrectlyMapped()
        {
            var scopeClaim = new ScopeClaim
            {
                Name                   = Guid.NewGuid().ToString(),
                Description            = Guid.NewGuid().ToString(), // data will be lost
                AlwaysIncludeInIdToken = true                       // data will be lost
            };
            var scope = new Scope {
                Type = (int)ScopeType.Identity, ScopeClaims = new List <ScopeClaim>()
                {
                    scopeClaim
                }
            };
            var scopes = new List <Scope> {
                scope
            };

            var resources = scopes.GetIdentityResources();

            resources.Should().NotBeEmpty();
            resources.Should().HaveCount(scopes.Count);

            var resource = resources.Single(x => x.Name == scope.Name);

            resource.Should().NotBeNull();
            resource.UserClaims.Should().NotBeEmpty();
            resource.UserClaims.Should().Contain(scopeClaim.Name);
        }
Exemplo n.º 2
0
        public async Task <Scope> AddScope(Scope scope)
        {
            _context.Scopes.Add(scope);
            await _context.SaveChangesAsync();

            return(scope);
        }
        public void GivenApiScope_ExpectEmptyCollectionReturned()
        {
            var scope = new Scope {
                Type = (int)ScopeType.Resource
            };
            var scopes = new List <Scope> {
                scope
            };

            scopes.GetIdentityResources().Should().BeEmpty();
        }
Exemplo n.º 4
0
        public void GivenIdentityScope_ExpectEmptyCollectionReturned()
        {
            var scope = new Scope {
                Type = (int)ScopeType.Identity
            };
            var scopes = new List <Scope> {
                scope
            };

            var result = scopes.GetApiResourcesAndApiScopes();

            result.apiResources.Should().BeEmpty();
            result.scopes.Should().BeEmpty();
        }
        public void AutomapperConfigurationIsValid()
        {
            IdentityServer3.Core.Models.Scope s = new IdentityServer3.Core.Models.Scope()
            {
            };
            var e = s.ToEntity();

            IdentityServer3.EntityFramework.Entities.Scope s2 = new IdentityServer3.EntityFramework.Entities.Scope()
            {
                ScopeClaims = new HashSet<IdentityServer3.EntityFramework.Entities.ScopeClaim>()
            };
            var m = s2.ToModel();

            Mapper.AssertConfigurationIsValid();
        }
Exemplo n.º 6
0
        public void AutomapperConfigurationIsValid()
        {
            IdentityServer3.Core.Models.Scope s = new IdentityServer3.Core.Models.Scope()
            {
            };
            var e = s.ToEntity();

            IdentityServer3.EntityFramework.Entities.Scope s2 = new IdentityServer3.EntityFramework.Entities.Scope()
            {
                ScopeClaims = new HashSet <IdentityServer3.EntityFramework.Entities.ScopeClaim>()
            };
            var m = s2.ToModel();

            Mapper.AssertConfigurationIsValid();
        }
        public IdentityAdminCoreManagerTests()
        {
            _identityAdminManagerService = new IdentityAdminManagerService("IdSvr3ConfigAdmin");
            using (var db = new ClientConfigurationDbContext(ConnectionString))
            {
                var allClients = db.Clients.Where(p => true);
                foreach (var c in allClients  )
                {
                    db.Clients.Remove(c);
                }
                db.SaveChanges();
                var testClient = new Client
                {
                    ClientId = "IdToTest",
                    ClientName = _clientName,
                    Enabled = true,
                    Flow = Flows.Implicit,
                    RequireConsent = true,
                    AllowRememberConsent = true,
                    RedirectUris =new List<ClientRedirectUri>() {new ClientRedirectUri {Id = 1, Uri = "www.redirect.com"}},
                    PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri>(){new ClientPostLogoutRedirectUri{Id = 1, Uri = "www.postRedirectUri.com"}},
                    AllowedScopes = new List<ClientScope>() { new ClientScope { Scope = "read" ,Id = 1} },
                    AccessTokenType = AccessTokenType.Jwt,
                    ClientSecrets = new List<ClientSecret>{new ClientSecret{Id = 1,Description = "removeMe",Type = "ssssshhh", Value = "nothing to see here"}},
                    IdentityProviderRestrictions = new List<ClientIdPRestriction>(){new ClientIdPRestriction{Id = 1,Provider = "www.provideme.com"}},
                    AllowedCustomGrantTypes = new List<ClientCustomGrantType>{new ClientCustomGrantType{Id = 1, GrantType = "Authorization Grant"}},
                    Claims = new List<ClientClaim>{new ClientClaim{Id = 1,Value = "tester", Type = "role"}},
                    AllowedCorsOrigins = new List<ClientCorsOrigin> { new ClientCorsOrigin { Id = 1,Origin = "www.CrossOriginMe.com"} }
                };
                db.Clients.Add(testClient);
                db.SaveChanges();
                _clientSubject = testClient.Id.ToString();
            }

            using (var db = new ScopeConfigurationDbContext(ConnectionString))
            {
                var allScopes = db.Scopes.Where(p => true);
                foreach (var c in allScopes)
                {
                    db.Scopes.Remove(c);
                }
                db.SaveChanges();
                var testScope = new Scope { Name = _scopeName,ScopeClaims = new List<ScopeClaim>{new ScopeClaim{Id = 1,Description = "To Test", Name = "testScope"}}};
                db.Scopes.Add(testScope);
                db.SaveChanges();
                _scopeSubject = testScope.Id.ToString();
            }
        }
Exemplo n.º 8
0
        public void GivenApiScope_ExpectApiScopeCorrectlyMapped()
        {
            var scope = new Scope
            {
                Description             = Guid.NewGuid().ToString(),
                DisplayName             = Guid.NewGuid().ToString(),
                Emphasize               = true,
                Name                    = Guid.NewGuid().ToString(),
                Required                = true,
                ShowInDiscoveryDocument = false,
                Type                    = (int)ScopeType.Resource
            };
            var scopes = new List <Scope> {
                scope
            };

            var result = scopes.GetApiResourcesAndApiScopes();

            result.apiResources.Should().NotBeEmpty();
            result.scopes.Should().NotBeEmpty();

            result.apiResources.Should().HaveCount(scopes.Count);
            result.scopes.Should().HaveCount(scopes.Count);

            var resource = result.apiResources.Single(x => x.Name == scope.Name);

            resource.Should().NotBeNull();
            resource.Scopes.Should().NotBeEmpty();
            resource.Scopes.Should().HaveCount(1);

            var apiScope = result.scopes.Single();

            apiScope.Description.Should().Be(scope.Description);
            apiScope.DisplayName.Should().Be(scope.DisplayName);
            apiScope.Emphasize.Should().Be(scope.Emphasize);
            apiScope.Name.Should().Be(scope.Name);
            apiScope.Required.Should().Be(scope.Required);
            apiScope.ShowInDiscoveryDocument.Should().Be(scope.ShowInDiscoveryDocument);
            apiScope.UserClaims.Should().BeEmpty();
        }
Exemplo n.º 9
0
        public void GivenApiScopeWithSecrets_ExpectSecretsCorrectlyMapped()
        {
            var secret = new ScopeSecret()
            {
                Type        = Constants.SecretTypes.SharedSecret,
                Value       = Guid.NewGuid().ToString(),
                Description = Guid.NewGuid().ToString(),
                Expiration  = DateTimeOffset.UtcNow.AddDays(2)
            };

            var scope = new Scope {
                Type = (int)ScopeType.Resource, ScopeSecrets = new List <ScopeSecret> {
                    secret
                }
            };
            var scopes = new List <Scope> {
                scope
            };

            var result = scopes.GetApiResourcesAndApiScopes();

            result.apiResources.Should().NotBeEmpty();
            result.scopes.Should().NotBeEmpty();

            result.apiResources.Should().HaveCount(scopes.Count);
            result.scopes.Should().HaveCount(scopes.Count);

            var resource = result.apiResources.Single(x => x.Name == scope.Name);

            resource.ApiSecrets.Should().NotBeEmpty();
            resource.ApiSecrets.Should().HaveCount(scope.ScopeSecrets.Count);

            var apiSecret = resource.ApiSecrets.First();

            apiSecret.Type.Should().BeEquivalentTo(secret.Type);
            apiSecret.Type.Should().BeEquivalentTo(IdentityServerConstants.SecretTypes.SharedSecret);
            apiSecret.Value.Should().BeEquivalentTo(secret.Value);
            apiSecret.Description.Should().BeEquivalentTo(secret.Description);
            apiSecret.Expiration?.Should().BeExactly(new TimeSpan(secret.Expiration.Value.Ticks));
        }
        public void AutomapperConfigurationIsValid()
        {
            IdentityServer3.Core.Models.Scope s = new IdentityServer3.Core.Models.Scope()
            {
            };
            var e = s.ToEntity();

            IdentityServer3.Core.Models.Client c = new IdentityServer3.Core.Models.Client()
            {
            };
            var e2 = c.ToEntity();

            IdentityServer3.EntityFramework.Entities.Scope s2 = new IdentityServer3.EntityFramework.Entities.Scope()
            {
                ScopeClaims  = new HashSet <IdentityServer3.EntityFramework.Entities.ScopeClaim>(),
                ScopeSecrets = new HashSet <IdentityServer3.EntityFramework.Entities.ScopeSecret>(),
            };
            var m = s2.ToModel();

            IdentityServer3.EntityFramework.Entities.EntitiesMap.Mapper.ConfigurationProvider.AssertConfigurationIsValid();
            IdentityServer3.Core.Models.EntitiesMap.Mapper.ConfigurationProvider.AssertConfigurationIsValid();
        }
        public void AutomapperConfigurationIsValid()
        {
            IdentityServer3.Core.Models.Scope s = new IdentityServer3.Core.Models.Scope()
            {
            };
            var e = s.ToEntity();

            IdentityServer3.Core.Models.Client c = new IdentityServer3.Core.Models.Client()
            {
            };
            var e2 = c.ToEntity();

            IdentityServer3.EntityFramework.Entities.Scope s2 = new IdentityServer3.EntityFramework.Entities.Scope()
            {
                ScopeClaims = new HashSet<IdentityServer3.EntityFramework.Entities.ScopeClaim>(),
                ScopeSecrets = new HashSet<IdentityServer3.EntityFramework.Entities.ScopeSecret>(),
            };
            var m = s2.ToModel();

            IdentityServer3.EntityFramework.Entities.EntitiesMap.Mapper.ConfigurationProvider.AssertConfigurationIsValid();
            IdentityServer3.Core.Models.EntitiesMap.Mapper.ConfigurationProvider.AssertConfigurationIsValid();
        }
Exemplo n.º 12
0
        public void GivenApiScope_ExpectApiResourceCorrectlyMapped()
        {
            var scope = new Scope
            {
                Description             = Guid.NewGuid().ToString(),
                DisplayName             = Guid.NewGuid().ToString(),
                Emphasize               = true,
                Enabled                 = false,
                Name                    = Guid.NewGuid().ToString(),
                Required                = true,
                ShowInDiscoveryDocument = false,
                Type                    = (int)ScopeType.Resource,

                AllowUnrestrictedIntrospection = true,  // data will be lost
                ClaimsRule = Guid.NewGuid().ToString(), // data will be lost
                IncludeAllClaimsForUser = true,         // data will be lost
            };
            var scopes = new List <Scope> {
                scope
            };

            var result = scopes.GetApiResourcesAndApiScopes();

            result.apiResources.Should().NotBeEmpty();
            result.scopes.Should().NotBeEmpty();

            result.apiResources.Should().HaveCount(scopes.Count);
            result.scopes.Should().HaveCount(scopes.Count);

            var resource = result.apiResources.Single(x => x.Name == scope.Name);

            resource.Should().NotBeNull();
            resource.Name.Should().Be(scope.Name);
            resource.DisplayName.Should().Be(scope.DisplayName);
            resource.Description.Should().Be(scope.Description);
            resource.Enabled.Should().Be(scope.Enabled);
        }
Exemplo n.º 13
0
        public IdentityAdminCoreManagerTests()
        {
            _identityAdminManagerService = new IdentityAdminManagerService("IdSvr3ConfigAdmin");
            using (var db = new ClientConfigurationDbContext(ConnectionString))
            {
                var allClients = db.Clients.Where(p => true);
                foreach (var c in allClients)
                {
                    db.Clients.Remove(c);
                }
                db.SaveChanges();
                var testClient = new Client
                {
                    ClientId             = "IdToTest",
                    ClientName           = _clientName,
                    Enabled              = true,
                    Flow                 = Flows.Implicit,
                    RequireConsent       = true,
                    AllowRememberConsent = true,
                    RedirectUris         = new List <ClientRedirectUri>()
                    {
                        new ClientRedirectUri {
                            Id = 1, Uri = "www.redirect.com"
                        }
                    },
                    PostLogoutRedirectUris = new List <ClientPostLogoutRedirectUri>()
                    {
                        new ClientPostLogoutRedirectUri {
                            Id = 1, Uri = "www.postRedirectUri.com"
                        }
                    },
                    AllowedScopes = new List <ClientScope>()
                    {
                        new ClientScope {
                            Scope = "read", Id = 1
                        }
                    },
                    AccessTokenType = AccessTokenType.Jwt,
                    ClientSecrets   = new List <ClientSecret> {
                        new ClientSecret {
                            Id = 1, Description = "removeMe", Type = "ssssshhh", Value = "nothing to see here"
                        }
                    },
                    IdentityProviderRestrictions = new List <ClientIdPRestriction>()
                    {
                        new ClientIdPRestriction {
                            Id = 1, Provider = "www.provideme.com"
                        }
                    },
                    AllowedCustomGrantTypes = new List <ClientCustomGrantType> {
                        new ClientCustomGrantType {
                            Id = 1, GrantType = "Authorization Grant"
                        }
                    },
                    Claims = new List <ClientClaim> {
                        new ClientClaim {
                            Id = 1, Value = "tester", Type = "role"
                        }
                    },
                    AllowedCorsOrigins = new List <ClientCorsOrigin> {
                        new ClientCorsOrigin {
                            Id = 1, Origin = "www.CrossOriginMe.com"
                        }
                    }
                };
                db.Clients.Add(testClient);
                db.SaveChanges();
                _clientSubject = testClient.Id.ToString();
            }

            using (var db = new ScopeConfigurationDbContext(ConnectionString))
            {
                var allScopes = db.Scopes.Where(p => true);
                foreach (var c in allScopes)
                {
                    db.Scopes.Remove(c);
                }
                db.SaveChanges();
                var testScope = new Scope {
                    Name = _scopeName, ScopeClaims = new List <ScopeClaim> {
                        new ScopeClaim {
                            Id = 1, Description = "To Test", Name = "testScope"
                        }
                    }
                };
                db.Scopes.Add(testScope);
                db.SaveChanges();
                _scopeSubject = testScope.Id.ToString();
            }
        }