コード例 #1
0
ファイル: ClientsController.cs プロジェクト: phoenixyj/haipa
        public async Task <IActionResult> NewKey([FromODataUri] string clientId)
        {
            var client = await _clientService.GetClient(clientId);

            if (client == null)
            {
                return(NotFound($"client with id {clientId} not found."));
            }


            var privateKey = await client.NewClientCertificate();

            await _clientService.UpdateClient(client);

            var createdClient = new ClientWithSecrets
            {
                Id            = client.Id,
                AllowedScopes = client.AllowedScopes,
                Description   = client.Description,
                Name          = client.Name,
                Key           = privateKey,
                KeyType       = ClientSecretType.RsaPrivateKey,
            };


            return(Updated(createdClient));
        }
コード例 #2
0
ファイル: ClientsController.cs プロジェクト: phoenixyj/haipa
        public async Task <IActionResult> Post([FromBody] Client client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            client.Id = Guid.NewGuid().ToString();

            var privateKey = await client.NewClientCertificate();

            await _clientService.AddClient(client);

            var createdClient = new ClientWithSecrets
            {
                Id            = client.Id,
                AllowedScopes = client.AllowedScopes,
                Description   = client.Description,
                Name          = client.Name,
                Key           = privateKey,
                KeyType       = ClientSecretType.RsaPrivateKey,
            };

            return(Created(createdClient));
        }