Mobile App - Cognito Callback Stuck in Browser


I have a mobile app using .NET MAUI, currently testing with a "Pixel 7 - API 35 (Android 15.0-API 35)" emulator. Using Visual Studio 2022, .NET version 10
Currently I am following a very simple flow:
1. User clicks Login
2. Sends user to Amazon Cognito login, user inputs login information
3. On successful login, goes back to app with code which is then exchanged for tokens.

The problem occurs when the user logs in. When it is accepted, another window begins to open, which I assume is either the browser going to another page or else the app beginning to come to the front.
Then it stops, and goes back to the login page, which is stuck on "Sign In" and the spinning disc.

With the below code, checkpoint 2 is never hit. Also, the Visual Studio debugger closes as soon as Cognito opens in the browser, although the app continues just fine.

If I close the emulator and login again (even forcing Cognito to require another actual login, rather than just accepting the stored cookies or however that works), it works correctly and after logging in it returns the user to the app.

.NET MAUI code:

SetAuthCheckpoint("1: Before AuthenticateAsync");

string codeVerifier = CreateCodeVerifier();
string codeChallenge = CreateCodeChallenge(codeVerifier);
string state = Guid.NewGuid().ToString("N");

string clientId = "clientid";
string redirectUri = "app redirect uri";
string cognitoDomain = "domain";

string authorizeUrl = 
    $"{cognitoDomain}/oauth2/authorize" +
    $"?client_id={Uri.EscapeDataString(clientId)}" +
    $"&response_type=code" + 
    $"&scope={Uri.EscapeDataString("openid email phone custom-scope")}"+
    $"&redirect_uri={Uri.EscapeDataString(redirectUri)}" + 
    $"&state={Uri.EscapeDataString(state)}" +
    $"&code_challenge={Uri.EscapeDataString(codeChallenge)}" +
    $"&code_challenge_method=S256" + 
    $"&prompt=login"; //temporary to force login every time

WebAuthenticatorResult authResult =
    await WebAuthenticator.Default.AuthenticateAsync(
        new Uri(authorizeUrl),
        new Uri(redirectUri))

SetAuthCheckpoint("2, Async returned");

(SetAuthCheckpoint stores it into preferences)

SIgn in page after failure

0
Sep 23 at 7:49 PM
User AvatarArkanis
#android#android-emulator#maui#amazon-cognito

No answer found for this question yet.