Пример #1
0
        public IActionResult RemoveDatabase()
        {
            _clientContext.RemoveRange(_clientContext.Clients);
            _scopeContext.RemoveRange(_scopeContext.Scopes);
            _operationalContext.RemoveRange(_operationalContext.Tokens);
            _operationalContext.RemoveRange(_operationalContext.Consents);

            _clientContext.SaveChanges();
            _scopeContext.SaveChanges();
            _operationalContext.SaveChanges();
            return(Json("Success"));
        }
        private void AddScopes()
        {
            foreach (var sc in Scopes.Get())
            {
                var scope = new Scope <Guid>()
                {
                    ClaimsRule              = sc.ClaimsRule,
                    Description             = sc.Description,
                    DisplayName             = sc.DisplayName,
                    Emphasize               = sc.Emphasize,
                    Enabled                 = sc.Enabled,
                    IncludeAllClaimsForUser = sc.IncludeAllClaimsForUser,
                    Name     = sc.Name,
                    Required = sc.Required,
                    ShowInDiscoveryDocument = sc.ShowInDiscoveryDocument,
                    Type = (int)sc.Type,
                    AllowUnrestrictedIntrospection = sc.AllowUnrestrictedIntrospection,
                };
                scope.ScopeClaims  = new List <ScopeClaim <Guid> >();
                scope.ScopeSecrets = new List <ScopeSecret <Guid> >();

                //Add ScopeClaims
                foreach (var claim in sc.Claims)
                {
                    var scopeClaim = new ScopeClaim <Guid>()
                    {
                        AlwaysIncludeInIdToken = claim.AlwaysIncludeInIdToken,
                        Description            = claim.Description,
                        Name = claim.Name
                    };
                    scope.ScopeClaims.Add(scopeClaim);
                }

                //AddScopeSecrets
                foreach (var secret in sc.ScopeSecrets)
                {
                    var scopeSecret = new ScopeSecret <Guid>()
                    {
                        Description = secret.Description,
                        Expiration  = secret.Expiration.HasValue ? (DateTime?)secret.Expiration.Value.DateTime : null,
                        Type        = secret.Type,
                        Value       = secret.Value
                    };
                    scope.ScopeSecrets.Add(scopeSecret);
                }

                _scopeContext.Scopes.Add(scope);
            }
            _scopeContext.SaveChanges();
        }