DUO / C# - How to make a single call to Authenticate a User, with out a Callback

107 Views Asked by At

In C# DUO Universal. How can I make a single call that will authenticate a user , 'ping' the DUO app on their phone and authenticate. The DUO Universal example uses a Page call back. I have the DUO Universal sample working fine... https://github.com/duosecurity/duo_universal_csharp

I want to make a single HTTP call pass in the DUO URL and username. I wish to create a microservice to provide this.

I have tried the following.. but does not 'call' the DUO iPhone App.

using Microsoft.AspNetCore.Mvc; using System.Net.Http; using System.Threading.Tasks;

namespace DuoAuthenticationExample.Controllers { [ApiController] [Route("api/[controller]")] public class DuoController : ControllerBase { private readonly 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);
        
    

// DOES NOT CALL MY DUO IPHONE APP

        // 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");
        }
    }
}

}

Any ideas? thx

0

There are 0 best solutions below