예제 #1
0
        public async Task <IActionResult> Keys([FromBody] CreateKeyRequest request)
        {
            _logger.LogInformation("Adding {0} authentication key {1} to tenant {2} by {3}", request.IsAdminKey ? "admin" : "device", request.Credential.Id, User.Tenant(), User.Identity?.Name);
            var credentialAttestation = request.Credential.ToCredentialAttestation();
            var metadata = await _metadataService.GetMetadataAsync(credentialAttestation.Attestation.AuthenticatorData.AttestedCredentialData.Aaguid);

            var credential = new KeyCredential
            {
                Id        = WebEncoders.Base64UrlEncode(credentialAttestation.CredentialId),
                PublicKey = WebEncoders.Base64UrlEncode(credentialAttestation.Attestation.AuthenticatorData
                                                        .AttestedCredentialData.PublicKey.Cbor.EncodeToBytes()),
                MetadataName = metadata?.Description,
                MetadataIcon = metadata?.Icon,
                TenantName   = User.Tenant(),
                IsAdminKey   = request.IsAdminKey
            };
            await _keyManager.CreateAsync(credential);

            _logger.LogInformation("Registered {0} authentication key {1}", request.IsAdminKey ? "admin" : "device", request.Credential.Id);
            return(Ok(metadata));
        }