public async Task <IdentityResult> DeleteSecretAsync(
            Neo4jIdentityServer4Client client,
            Neo4jIdentityServer4ClientSecret secret,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            secret.ThrowIfNull(nameof(secret));
            try
            {
                var cypher = $@"
                MATCH (c:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasSecret}]->(s:{IdSrv4ClientSecret})
                WHERE c.ClientId = $p0 AND s.Value = $p1
                DETACH DELETE s";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId,
                                           secret.Value));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> DeleteCorsOriginsAsync(Neo4jIdentityServer4Client client,
                                                                  CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));

            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasCorsOrigin}]->(corsOrigin:{
                        IdSrv4ClientCorsOrigin
                    })
                WHERE client.ClientId = $p0 
                DETACH DELETE corsOrigin";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId
                                           ));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <Neo4jIdentityServer4ClientClaim> FindClaimAsync(Neo4jIdentityServer4Client client,
                                                                           Neo4jIdentityServer4ClientClaim claim,
                                                                           CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            claim.ThrowIfNull(nameof(claim));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasClaim}]->(claim:{IdSrv4ClientClaim})
                WHERE client.ClientId = $p0 AND claim.Type = $p1 AND claim.Value = $p2
                RETURN claim{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    claim.Type,
                                                    claim.Value
                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ClientClaim>("claim"));

            return(foundRecord);
        }
        public async Task <IdentityResult> AddClientToUserAsync(
            TUser user,
            Neo4jIdentityServer4Client client,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            user.ThrowIfNull(nameof(user));
            client.ThrowIfNull(nameof(client));
            try
            {
                var cypher = $@"
                MATCH (u:{User} {{Id: $p0}})
                CREATE UNIQUE(
                    (u)-[:{Neo4jConstants.Relationships.HasClient}]->
                    (:{IdSrv4Client} {"$p1".AsMapForNoNull(client)}))";

                var result = await Session.RunAsync(cypher, Params.Create(user.Id, client));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> DeleteIDPRestrictionAsync(Neo4jIdentityServer4Client client,
                                                                     Neo4JIdentityServer4ClientIdpRestriction idpRestriction,
                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            idpRestriction.ThrowIfNull(nameof(idpRestriction));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasIdPRestriction}]->(idp:{
                        IdSrv4ClienTIDPRestriction
                    })
                WHERE client.ClientId = $p0 AND idp.Provider = $p1 
                DETACH DELETE idp";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId,
                                           idpRestriction.Provider
                                           ));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <Neo4jIdentityServer4ClientCorsOrigin> FindCorsOriginAsync(Neo4jIdentityServer4Client client,
                                                                                     Neo4jIdentityServer4ClientCorsOrigin corsOrigin,
                                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            corsOrigin.ThrowIfNull(nameof(corsOrigin));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasCorsOrigin}]->(corsOrigin:{
                    IdSrv4ClientCorsOrigin
                })
                WHERE client.ClientId = $p0 AND corsOrigin.Origin = $p1 
                RETURN corsOrigin{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    corsOrigin.Origin
                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ClientCorsOrigin>("corsOrigin"));

            return(foundRecord);
        }
        public async Task <Neo4jIdentityServer4ClientRedirectUri> FindRedirectUriAsync(Neo4jIdentityServer4Client client,
                                                                                       Neo4jIdentityServer4ClientRedirectUri redirectUri,
                                                                                       CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            redirectUri.ThrowIfNull(nameof(redirectUri));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasRedirectUri}]->(redirectUri:{
                    IdSrv4ClientRedirectUri
                })
                WHERE client.ClientId = $p0 AND redirectUri.RedirectUri = $p1  
                RETURN redirectUri{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    redirectUri.RedirectUri

                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ClientRedirectUri>("redirectUri"));

            return(foundRecord);
        }
Ejemplo n.º 8
0
        public async Task <Neo4jIdentityServer4ClientProperty> FindPropertyAsync(Neo4jIdentityServer4Client client,
                                                                                 Neo4jIdentityServer4ClientProperty property,
                                                                                 CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            property.ThrowIfNull(nameof(property));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasProperty}]->(property:{
                    IdSrv4ClientProperty
                })
                WHERE client.ClientId = $p0 AND property.Key = $p1 AND property.Value = $p2  
                RETURN property{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    property.Key,
                                                    property.Value

                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ClientProperty>("property"));

            return(foundRecord);
        }
Ejemplo n.º 9
0
        public async Task <IdentityResult> DeletePropertyAsync(Neo4jIdentityServer4Client client,
                                                               Neo4jIdentityServer4ClientProperty property,
                                                               CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            property.ThrowIfNull(nameof(property));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasProperty}]->(property:{
                        IdSrv4ClientProperty
                    })
                WHERE client.ClientId = $p0 AND property.Key = $p1 AND property.Value = $p2 
                DETACH DELETE property";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId,
                                           property.Key,
                                           property.Value
                                           ));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> AddRedirectUriToClientAsync(Neo4jIdentityServer4Client client,
                                                                       Neo4jIdentityServer4ClientRedirectUri redirectUri,
                                                                       CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            redirectUri.ThrowIfNull(nameof(redirectUri));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client} {{ClientId: $p0}})
                MERGE (redirectUri:{IdSrv4ClientRedirectUri} {"$p1".AsMapForNoNull<Neo4jIdentityServer4ClientRedirectUri>(redirectUri)})
                MERGE (client)-[:{Neo4jConstants.Relationships.HasRedirectUri}]->(redirectUri)";

                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, redirectUri));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> DeleteAllowedGrantTypeToClientAsync(Neo4jIdentityServer4Client client,
                                                                               Neo4JIdentityServer4IdentityServer4GrantType identityServer4GrantType, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            identityServer4GrantType.ThrowIfNull(nameof(identityServer4GrantType));
            try
            {
                var cypher = $@"
                MATCH 
                    (client:{IdSrv4Client})
                    -[:{Neo4jConstants.Relationships.HasGrantType}]->
                    (allowedGT:{IdSrv4AllowedGrantType})
                WHERE client.ClientId = $p0 AND allowedGT.IdentityServer4GrantType = $p1 
                DETACH DELETE allowedGT";

                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, identityServer4GrantType.GrantType));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
Ejemplo n.º 12
0
        public async Task <IdentityResult> AddRollupToClientAsync(
            Neo4jIdentityServer4Client client,
            ClientRollup rollup,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            rollup.ThrowIfNull(nameof(rollup));
            try
            {
                var cypher = $@"
                MATCH (c:{IdSrv4Client} {{ClientId: $p0}})
                MERGE (rollup:{IdSrv4ClientRollup} {"$p1".AsMapForNoNull(rollup)})
                MERGE (c)-[:{Neo4jConstants.Relationships.HasRollup}]->(rollup)";

                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, rollup));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> DeletePostLogoutRedirectUriAsync(Neo4jIdentityServer4Client client,
                                                                            Neo4jIdentityServer4ClientPostLogoutRedirectUri postLogoutRedirectUri,
                                                                            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            postLogoutRedirectUri.ThrowIfNull(nameof(postLogoutRedirectUri));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{
                        Neo4jConstants.Relationships.HasPostLogoutRedirectUri
                    }]->(postLogoutRedirectUri:{IdSrv4ClientPostLogoutRedirectUri})
                WHERE client.ClientId = $p0 AND postLogoutRedirectUri.PostLogoutRedirectUri = $p1  
                DETACH DELETE postLogoutRedirectUri";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId,
                                           postLogoutRedirectUri.PostLogoutRedirectUri
                                           ));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> DeleteClaimAsync(Neo4jIdentityServer4Client client,
                                                            Neo4jIdentityServer4ClientClaim claim,
                                                            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            claim.ThrowIfNull(nameof(claim));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasClaim}]->(claim:{IdSrv4ClientClaim})
                WHERE client.ClientId = $p0 AND claim.Type = $p1 AND claim.Value = $p2
                DETACH DELETE claim";

                await Session.RunAsync(cypher,
                                       Params.Create(
                                           client.ClientId,
                                           claim.Type,
                                           claim.Value
                                           ));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <Neo4JIdentityServer4ClientIdpRestriction> FindIDPRestrictionAsync(
            Neo4jIdentityServer4Client client,
            Neo4JIdentityServer4ClientIdpRestriction idpRestriction,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            idpRestriction.ThrowIfNull(nameof(idpRestriction));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasIdPRestriction}]->(idp:{
                    IdSrv4ClienTIDPRestriction
                })
                WHERE client.ClientId = $p0 AND idp.Provider = $p1  
                RETURN idp{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    idpRestriction.Provider
                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4JIdentityServer4ClientIdpRestriction>("idp"));

            return(foundRecord);
        }
        public async Task <IdentityResult> DeleteClientAsync(Neo4jIdentityServer4Client client,
                                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));

            await RaiseClientChangeEventAsync(client);
            await DeleteRedirectUrisAsync(client, cancellationToken);
            await DeletePostLogoutRedirectUrisAsync(client, cancellationToken);
            await DeleteClaimsAsync(client, cancellationToken);
            await DeleteCorsOriginsAsync(client, cancellationToken);
            await DeleteIDPRestrictionsAsync(client, cancellationToken);
            await DeletePropertiesAsync(client, cancellationToken);
            await DeleteScopesAsync(client, cancellationToken);
            await DeleteSecretsAsync(client, cancellationToken);

            try
            {
                var cypher = $@"
                MATCH (c:{IdSrv4Client})
                WHERE c.ClientId = $p0
                DETACH DELETE c";

                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> AddCorsOriginToClientAsync(Neo4jIdentityServer4Client client,
                                                                      Neo4jIdentityServer4ClientCorsOrigin corsOrigin,
                                                                      CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            corsOrigin.ThrowIfNull(nameof(corsOrigin));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client} {{ClientId: $p0}})
                CREATE UNIQUE(
                    (client)-[:{Neo4jConstants.Relationships.HasCorsOrigin}]->
                    (:{IdSrv4ClientCorsOrigin} {"$p1".AsMapForNoNull(corsOrigin)}))";


                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, corsOrigin));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
Ejemplo n.º 18
0
        public async Task <IList <Neo4jIdentityServer4ClientScope> > GetScopesAsync(Neo4jIdentityServer4Client client,
                                                                                    CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));

            var cypher = $@"
                 MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasScope}]->(scope:{IdSrv4ClientScope})
                WHERE client.ClientId = $p0
                RETURN scope{{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(client.ClientId));

            var scopes = await result.ToListAsync(r => r.MapTo <Neo4jIdentityServer4ClientScope>("scope"));

            return(scopes);
        }
        public async Task <IdentityResult> CreateClientAsync(Neo4jIdentityServer4Client client,
                                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            try
            {
                var cypher = $@"CREATE (r:{IdSrv4Client} $p0)";
                await Session.RunAsync(cypher, Params.Create(client.ConvertToMap()));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IList <Neo4JIdentityServer4ClientIdpRestriction> > GetIDPRestrictionsAsync(
            Neo4jIdentityServer4Client client,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));

            var cypher = $@"
                 MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasIdPRestriction}]->(idp:{
                    IdSrv4ClienTIDPRestriction
                })
                WHERE client.ClientId = $p0
                RETURN idp{{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(client.ClientId));

            var ipds = await result.ToListAsync(r => r.MapTo <Neo4JIdentityServer4ClientIdpRestriction>("idp"));

            return(ipds);
        }
        public async Task <IList <Neo4jIdentityServer4ClientPostLogoutRedirectUri> > GetPostLogoutRedirectUrisAsync(
            Neo4jIdentityServer4Client client,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));

            var cypher = $@"
                 MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasPostLogoutRedirectUri}]->(post:{
                    IdSrv4ClientPostLogoutRedirectUri
                })
                WHERE client.ClientId = $p0
                RETURN post{{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(client.ClientId));

            var records =
                await result.ToListAsync(r => r.MapTo <Neo4jIdentityServer4ClientPostLogoutRedirectUri>("post"));

            return(records);
        }
Ejemplo n.º 22
0
        public async Task <IdentityServer4.Models.Client> GetRollupAsync(Neo4jIdentityServer4Client client,
                                                                         CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));

            var cypher = $@"
                MATCH (c:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasRollup}]->(rollup:{IdSrv4ClientRollup})
                WHERE c.ClientId = $p0
                RETURN rollup{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId));

            IdentityServer4.Models.Client model = null;
            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <ClientRollup>("rollup"));

            if (foundRecord == null)
            {
                model = await RollupAsync(client, cancellationToken);
            }
            else
            {
                model = JsonConvert.DeserializeObject <IdentityServer4.Models.ClientExtra>(foundRecord.ClientJson);
                if (!string.IsNullOrEmpty(foundRecord.ClaimsJson))
                {
                    var claims = JsonConvert.DeserializeObject <List <Neo4jIdentityServer4ClientClaim> >(foundRecord.ClaimsJson);
                    foreach (var item in claims)
                    {
                        model.Claims.Add(new Claim(item.Type, item.Value));
                    }
                }
            }
            return(model);
        }
        public async Task <IdentityResult> UpdateClientAsync(Neo4jIdentityServer4Client client,
                                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            try
            {
                var cypher = $@"
                MATCH (r:{IdSrv4Client})
                WHERE r.ClientId = $p0
                SET r = $p1";

                await Session.RunAsync(cypher, Params.Create(client.ClientId, client.ConvertToMap()));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
Ejemplo n.º 24
0
        public async Task <Neo4jIdentityServer4ClientScope> FindScopeAsync(Neo4jIdentityServer4Client client,
                                                                           Neo4jIdentityServer4ClientScope scope,
                                                                           CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            scope.ThrowIfNull(nameof(scope));
            var cypher = $@"
                MATCH (client:{IdSrv4Client})-[:{Neo4jConstants.Relationships.HasScope}]->(scope:{IdSrv4ClientScope})
                WHERE client.ClientId = $p0 AND scope.Scope = $p1  
                RETURN scope{{ .* }}";

            var result = await Session.RunAsync(cypher,
                                                Params.Create(
                                                    client.ClientId,
                                                    scope.Scope
                                                    ));

            var foundRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ClientScope>("scope"));

            return(foundRecord);
        }
Ejemplo n.º 25
0
        public async Task <IdentityServer4.Models.Client> RollupAsync(
            Neo4jIdentityServer4Client client,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            await RaiseClientChangeEventAsync(client);

            var finalResult = new Client();
            var clientFound = await FindClientByClientIdAsync(client.ClientId, cancellationToken);

            var model   = clientFound.ToModel();
            var secrets = await GetSecretsAsync(client, cancellationToken);

            if (secrets != null)
            {
                foreach (var secret in secrets)
                {
                    model.ClientSecrets.Add(secret.ToModel());
                }
            }

            var allowedGrants = await GetAllowedGrantTypesAsync(client, cancellationToken);

            if (allowedGrants != null)
            {
                foreach (var item in allowedGrants)
                {
                    model.AllowedGrantTypes.Add(item.GrantType);
                }
            }


            var corsOrigins = await GetCorsOriginsAsync(client, cancellationToken);

            if (corsOrigins != null)
            {
                foreach (var item in corsOrigins)
                {
                    model.AllowedCorsOrigins.Add(item.Origin);
                }
            }
            var idpRestrictions = await GetIDPRestrictionsAsync(client, cancellationToken);

            if (idpRestrictions != null)
            {
                foreach (var item in idpRestrictions)
                {
                    model.IdentityProviderRestrictions.Add(item.Provider);
                }
            }
            var postLogoutRedirectUris = await GetPostLogoutRedirectUrisAsync(client, cancellationToken);

            if (postLogoutRedirectUris != null)
            {
                foreach (var item in postLogoutRedirectUris)
                {
                    model.PostLogoutRedirectUris.Add(item.PostLogoutRedirectUri);
                }
            }
            var properties = await GetPropertiesAsync(client, cancellationToken);

            if (properties != null)
            {
                foreach (var item in properties)
                {
                    model.Properties.Add(item.Key, item.Value);
                }
            }
            var redirectUris = await GetRedirectUrisAsync(client, cancellationToken);

            if (redirectUris != null)
            {
                foreach (var item in redirectUris)
                {
                    model.RedirectUris.Add(item.RedirectUri);
                }
            }
            var scopes = await GetScopesAsync(client, cancellationToken);

            if (redirectUris != null)
            {
                foreach (var item in scopes)
                {
                    model.AllowedScopes.Add(item.Scope);
                }
            }
            var claims = await GetClaimsAsync(client, cancellationToken);

            string claimsJson = null;

            if (claims != null)
            {
                claimsJson = JsonConvert.SerializeObject(claims);
            }
            var rollup = new ClientRollup()
            {
                ClientJson = JsonConvert.SerializeObject(model),
                ClaimsJson = claimsJson
            };
            var result = await AddRollupToClientAsync(client, rollup, cancellationToken);

            if (claims != null)
            {
                foreach (var item in claims)
                {
                    model.Claims.Add(new Claim(item.Type, item.Value));
                }
            }
            return(model);
        }