Exemple #1
0
        public async Task <IdentityResult> InsertApiResource(
            ApiResource model,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            model.ThrowIfNull(nameof(model));
            try
            {
                var dto    = model.ToNeo4jEntity();
                var result = await CreateApiResourceAsync(dto, cancellationToken);

                if (!result.Succeeded)
                {
                    return(result);
                }

                foreach (var claim in model.UserClaims)
                {
                    var dtoClaim = new Neo4jIdentityServer4ApiResourceClaim()
                    {
                        Type = claim
                    };
                    result = await AddApiResourceClaimAsync(dto, dtoClaim, cancellationToken);

                    if (!result.Succeeded)
                    {
                        return(result);
                    }
                }

                foreach (var scope in model.Scopes)
                {
                    var dtoScope = scope.ToNeo4jEntity();
                    result = await AddApiScopeAsync(dto, dtoScope, cancellationToken);

                    if (!result.Succeeded)
                    {
                        return(result);
                    }
                    foreach (var claim in scope.UserClaims)
                    {
                        var dtoClaim = new Neo4jIdentityServer4ApiScopeClaim()
                        {
                            Type = claim
                        };
                        result = await AddApiScopeClaimAsync(dto, dtoScope, dtoClaim, cancellationToken);

                        if (!result.Succeeded)
                        {
                            return(result);
                        }
                    }
                }

                foreach (var apiSecret in model.ApiSecrets)
                {
                    var dtoSecret = apiSecret.ToNeo4jApiSecretEntity();
                    result = await AddApiSecretAsync(dto, dtoSecret, cancellationToken);

                    if (!result.Succeeded)
                    {
                        return(result);
                    }
                }

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }