public async Task <IActionResult> AuthenticationToken(string pin) { //find it based on pin string verificationProfileId; try { verificationProfileId = await _persistantStorageService.GetSpeakerVerificationProfileByPinAsync(pin); } catch { //throw new InvalidOperationException("No valid speaker profile matching PIN."); return(StatusCode(400, "No valid speaker profile matching PIN.")); } using (var memoryStream = new MemoryStream()) { try { await Request.Body.CopyToAsync(memoryStream); byte[] waveBytes = memoryStream.ToArray(); VerificationResult result = await _speakerRecognitionClient.VerifyAsync(verificationProfileId, waveBytes); if (result.Result == "Accept") { var user = await _persistantStorageService.GetUserByVerificationProfileId(verificationProfileId); if (user == null) { return(StatusCode(500, "Invalid verification profile provided.")); } var claims = new Dictionary <string, string> { { OpenIdConnectConstants.Claims.Subject, user.UserPrinipleName } }; return(Json(new { result = result.Result, jwt = _jwtHandler.Create(claims) })); } else { return(Json(new { result = result.Result })); } } catch (HttpException e) { return(StatusCode(e.StatusCode, e.Message)); } catch (Exception e) { return(StatusCode(500, e.ToString())); } } }