teranetsrl / oauth2_client

Simple Dart library for interacting with OAuth2 servers.
BSD 2-Clause "Simplified" License
96 stars 112 forks source link

Auth flow closing if you switch focus between the app and the browser #186

Open andrewpmoore opened 5 months ago

andrewpmoore commented 5 months ago

I'm finding the library great for simplifying the auth flow, thanks. I'm having one issue, I have the following code

IhOAuth2Client oauth2Client = IhOAuth2Client(
      domain: environment.getAuthDomain(), // such as 'auth.example.co.uk'
      redirectUri: platformGetRedirectUri(),
      customUriScheme: platformGetCustomUriScheme(),
    );

OAuth2Helper oauth2Helper = OAuth2Helper(oauth2Client,
        grantType: OAuth2Helper.authorizationCode,
        clientId: 'mobileClient',
        webAuthOpts: {'preferEphemeral': true},
        scopes: ["unclaimTask", "task", "calendars", "submitDataCapture", "claimTask", "noteTypes", "viewActivePatientServices", "executeRule", "tasks"]);

http.Response resp = await oAuth2Helper!.get('https://auth.example.co.uk/api/oauthuser');

When I launch the last line to get the authUser the browser pops up as expected, if I log in everything is fine. The issue is that when the window pops up I switch back to the app without entering anything in the browser I get an error from the http.Response. That means that if you switch back to the browser to log in, it's not tied to anything and just errors.

Is there something I'm missing in what I need to do to handle this? So far I've tried it on windows and android and both show the same behavior