Пример #1
0
        public async Task <IActionResult> CreateIdentityResource([FromBody] CreateResourceRequest request)
        {
            var resource = new IdentityResource {
                Name                    = request.Name,
                DisplayName             = request.DisplayName,
                Description             = request.Description,
                Enabled                 = true,
                ShowInDiscoveryDocument = true,
                UserClaims              = request.UserClaims.Select(x => new IdentityResourceClaim {
                    Type = x
                })
                                          .ToList()
            };

            _configurationDbContext.IdentityResources.Add(resource);
            await _configurationDbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetIdentityResource), Name, new { resourceId = resource.Id }, new IdentityResourceInfo {
                Id = resource.Id,
                Name = resource.Name,
                DisplayName = resource.DisplayName,
                Description = resource.Description,
                Enabled = resource.Enabled,
                Required = resource.Required,
                Emphasize = resource.Emphasize,
                NonEditable = resource.NonEditable,
                ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument,
                AllowedClaims = resource.UserClaims.Select(x => x.Type)
            }));
        }
Пример #2
0
 public async Task<IActionResult> CreateClient([FromBody]CreateClientRequest request) {
     var client = CreateForType(request.ClientType, _generalSettings.Authority, request);
     _configurationDbContext.Clients.Add(client);
     _configurationDbContext.ClientUsers.Add(new ClientUser {
         Client = client,
         UserId = UserId
     });
     await _configurationDbContext.SaveChangesAsync();
     var response = new ClientInfo {
         ClientId = client.ClientId,
         ClientName = client.ClientName,
         ClientUri = client.ClientUri,
         Description = client.Description,
         AllowRememberConsent = client.AllowRememberConsent,
         Enabled = client.Enabled,
         LogoUri = client.LogoUri,
         RequireConsent = client.RequireConsent
     };
     if (_apiEndpointsOptions.CanRaiseEvents) {
         await _eventService.Raise(new ClientCreatedEvent(response));
     }
     return CreatedAtAction(nameof(GetClient), new { clientId = client.ClientId }, response);
 }