public async Task <bool> InsertAsync(Scope scope) { using (var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false)) { try { var record = new IdentityServer4.EntityFramework.Entities.Scope { Name = scope.Name, Description = scope.Description, ShowInDiscoveryDocument = scope.IsExposed, Type = scope.Type == ScopeType.ProtectedApi ? 1 : 0, DisplayName = scope.Name, Claims = scope.Claims == null ? new List <IdentityServer4.EntityFramework.Entities.ScopeClaim>() : scope.Claims.Select(s => new IdentityServer4.EntityFramework.Entities.ScopeClaim { Name = s }).ToList() }; _context.Scopes.Add(record); await _context.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); return(true); } catch (Exception ex) { _managerEventSource.Failure(ex); transaction.Rollback(); return(false); } } }
public static Core.Models.Scope ToDomain(this IdentityServer4.EntityFramework.Entities.Scope scope) { var standardScopeNames = IdentityServer4.Models.StandardScopes.All.Select(s => s.Name); var record = new Core.Models.Scope { Name = scope.Name, Description = scope.Description, IsExposed = scope.ShowInDiscoveryDocument, IsDisplayedInConsent = true }; record.IsOpenIdScope = standardScopeNames.Contains(record.Name); record.Type = scope.Type == (int)IdentityServer4.Models.ScopeType.Identity ? Core.Models.ScopeType.ResourceOwner : Core.Models.ScopeType.ProtectedApi; if (scope.Claims != null && scope.Claims.Any()) { record.Claims = scope.Claims.Select(c => c.Name).ToList(); } return(record); }