Esempio n. 1
0
        private async Task <IdentityResult> AddRollupAsync(
            Neo4jIdentityServer4IdentityResource identityResource,
            IdentityResourceRollup rollup,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityResource.ThrowIfNull(nameof(identityResource));
            rollup.ThrowIfNull(nameof(rollup));

            try
            {
                var cypher = $@"
                    MATCH (c:{IdSrv4IdentityResource}{{Name: $p0}})        
                    MERGE (rollup:{IdSrv4IdentityResourceRollup} {"$p1".AsMapForNoNull(rollup)})
                    MERGE (c)-[:{Neo4jConstants.Relationships.HasRollup}]->(rollup)";

                var result = await Session.RunAsync(cypher, Params.Create(identityResource.Name, rollup));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
Esempio n. 2
0
        public async Task <IdentityServer4.Models.IdentityResource> RollupAsync(Neo4jIdentityServer4IdentityResource identityResource,
                                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityResource.ThrowIfNull(nameof(identityResource));
            var foundIdentityResource = await GetIdentityResourceAsync(identityResource, cancellationToken);

            IdentityResource model = null;

            if (foundIdentityResource != null)
            {
                model = foundIdentityResource.ToModel();
                var claims = await GetIdentityClaimsAsync(foundIdentityResource, cancellationToken);

                foreach (var claim in claims)
                {
                    model.UserClaims.Add(claim.Type);
                }

                var rollup = new IdentityResourceRollup()
                {
                    IdentityResourceJson = JsonConvert.SerializeObject(model),
                };
                await AddRollupAsync(foundIdentityResource, rollup);
            }


            return(model);
        }