public async Task <IdentityResult> DeleteRollupAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); try { var cypher = $@" MATCH (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasScope}]-> (:{IdSrv4ClientApiScope}{{Name: $p1}})-[:{Neo4jConstants.Relationships.HasRollup}]->(r:{IdSrv4ApiScopeRollup}) DETACH DELETE r"; await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name)); return(IdentityResult.Success); } catch (ClientException ex) { return(ex.ToIdentityResult()); } }
public async Task <Scope> GetRollupAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); var cypher = $@" MATCH (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasScope}]-> (:{IdSrv4ClientApiScope}{{Name: $p1}})-[:{Neo4jConstants.Relationships.HasRollup}]-> (r:{IdSrv4ApiScopeRollup}) RETURN r{{ .* }}"; var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name)); IdentityServer4.Models.Scope model = null; var foundRecord = await result.SingleOrDefaultAsync(r => r.MapTo <ApiScopeRollup>("r")); if (foundRecord == null) { model = await RollupAsync(apiResource, apiScope, cancellationToken); } else { model = JsonConvert.DeserializeObject <Scope>(foundRecord.ApiScopeJson); } return(model); }
private async Task <IdentityResult> AddRollupAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, ApiScopeRollup rollup, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); rollup.ThrowIfNull(nameof(rollup)); try { var cypher = $@" MATCH (:{IdSrv4ApiResource}{{Name: $p0}}) -[:{Neo4jConstants.Relationships.HasScope}]-> (c:{IdSrv4ClientApiScope}{{Name: $p1}}) MERGE (rollup:{IdSrv4ApiScopeRollup} {"$p2".AsMapForNoNull<ApiScopeRollup>(rollup)}) MERGE (c)-[:{Neo4jConstants.Relationships.HasRollup}]->(rollup)"; var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name, rollup)); return(IdentityResult.Success); } catch (ClientException ex) { return(ex.ToIdentityResult()); } }
public async Task <IdentityResult> AddApiScopeAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); try { var cypher = $@" MATCH (r:{IdSrv4ApiResource}{{Name: $p0}}) MERGE (l:{IdSrv4ClientApiScope} {"$p1".AsMapForNoNull<Neo4jIdentityServer4ApiScope>(apiScope)}) MERGE (r)-[:{Neo4jConstants.Relationships.HasScope}]->(l)"; var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope)); await RaiseApiResourceChangeEventAsync(apiResource); return(IdentityResult.Success); } catch (ClientException ex) { return(ex.ToIdentityResult()); } }
public async Task <Scope> RollupAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); await RaiseApiScopeChangeEventAsync(apiResource, apiScope); var finalResult = new Client(); var apiScopeFound = await GetApiScopeAsync(apiResource, apiScope, cancellationToken); var model = apiScopeFound.ToModel(); var apiScopeClaims = await GetApiScopeClaimsAsync(apiResource, apiScopeFound, cancellationToken); if (apiScopeClaims != null) { foreach (var item in apiScopeClaims) { model.UserClaims.Add(item.Type); } } var rollup = new ApiScopeRollup() { ApiScopeJson = JsonConvert.SerializeObject(model), }; var result = await AddRollupAsync(apiResource, apiScopeFound, rollup, cancellationToken); return(model); }
public async Task <Neo4jIdentityServer4ApiScopeClaim> GetApiScopeClaimAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, Neo4jIdentityServer4ApiScopeClaim apiScopeClaim, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); var cypher = $@" MATCH (:{IdSrv4ApiResource}{{Name: $p0}})-[:{Neo4jConstants.Relationships.HasScope}]-> (:{IdSrv4ClientApiScope}{{Name: $p1}})-[:{Neo4jConstants.Relationships.HasClaim}]-> (s:{IdSrv4ClientApiScopeClaim}{{Type: $p2}}) RETURN s {{ .* }}"; var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name, apiScopeClaim.Type)); var record = await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ApiScopeClaim>("s")); return(record); }
public async Task <Neo4jIdentityServer4ApiScope> GetApiScopeAsync( Neo4jIdentityServer4ApiResource apiResource, Neo4jIdentityServer4ApiScope apiScope, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); apiResource.ThrowIfNull(nameof(apiResource)); apiScope.ThrowIfNull(nameof(apiScope)); var cypher = $@" MATCH (apiResource:{IdSrv4ApiResource})-[:{Neo4jConstants.Relationships.HasScope}]->(apiScope:{IdSrv4ClientApiScope}) WHERE apiResource.Name = $p0 AND apiScope.Name = $p1 RETURN apiScope {{ .* }}"; var result = await Session.RunAsync(cypher, Params.Create(apiResource.Name, apiScope.Name)); var record = await result.SingleOrDefaultAsync(r => r.MapTo <Neo4jIdentityServer4ApiScope>("apiScope")); return(record); }