public async Task <IActionResult> SendNonce(string identifier, string type = "default") { try { // create a nonce/token pair, store them, get Nonce var nonce = await _authService.CreateAndStoreNonce(identifier, type); // run the BeforeSendingNonce callback, put result in message body var extraBodyData = await _callbackService.BeforeSendingNonce(identifier, type) ?? "{}"; // create body for message to be sent to user & send it var body = _templateProcessor.ProcessTemplate(nonce, extraBodyData, type); await _senderService.SendAsync(identifier, body); _logger.LogDebug($"A message was sent to: {identifier}. It contained the body: {body}."); return(Ok($"Success! Sent Nonce to: {identifier}.")); } catch (InvalidIdentifierException e) { _logger.LogError(e.ToString()); return(BadRequest("Identifier invalid.")); } catch (Exception e) { _logger.LogError(e.ToString()); return(BadRequest("Something went wrong.")); } }