提问人:Jon 提问时间:8/10/2023 最后编辑:Jon 更新时间:8/11/2023 访问量:35
DUO / C# - 如何在没有回调的情况下进行单个调用以对用户进行身份验证
DUO / C# - How to make a single call to Authenticate a User, with out a Callback
问:
在 C# DUO Universal 中。我怎样才能拨打一个电话来验证用户,在他们的手机上“ping”DUO应用程序并进行身份验证。DUO Universal 示例使用 Page 回调。我有 DUO Universal 样品工作正常......https://github.com/duosecurity/duo_universal_csharp
我想在 DUO URL 和用户名中进行单个 HTTP 调用传递。我希望创建一个微服务来提供此功能。
我尝试了以下方法..但不会“调用”DUO iPhone App。
使用 Microsoft.AspNetCore.Mvc; 使用 System.Net.Http; 使用 System.Threading.Tasks;
命名空间 DuoAuthenticationExample.Controllers { [API控制器] [路由(“api/[控制器]”)] 公共类 DuoController : ControllerBase { private 只读 HttpClient _httpClient;
public DuoController(IHttpClientFactory httpClientFactory)
{
_httpClient = httpClientFactory.CreateClient();
}
[HttpPost("authenticate")]
public async Task<IActionResult> AuthenticateUser(string username, string passcode)
{
// Generate a signed passcode request
string passcodeRequestUrl = "https://api-XXXX.duosecurity.com/auth/v2/auth";
var passcodeRequest = new
{
username = username,
passcode = passcode,
// Add other required parameters
};
// Send passcode request to Duo Auth API
HttpResponseMessage response = await _httpClient.PostAsJsonAsync(passcodeRequestUrl, passcodeRequest);
不调用我的 DUO IPHONE 应用程序
// Handle Duo API response and determine authentication status
if (response.IsSuccessStatusCode)
{
// Check authentication status and grant access or deny
// ...
return Ok("User authenticated successfully");
}
else
{
// Handle API error and deny access
return Unauthorized("Authentication failed");
}
}
}
}
有什么想法吗?感谢
答: 暂无答案
评论