Skip to content

🐛 Bug Report: [FLUTTER] Appwrite OAuth2.0 api detects app link redirects as user canceling action by throwing PlatformException(User Canceled Login) #3142

Closed

Description

@devberkay

👟 Reproduction steps

this is my app link from manifest.xml :

<intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="http" />
                <data android:scheme="https" />

                <data android:host="<domain>" />
            </intent-filter>

this is my googleOAuth function :

Future<void> loginGoogleAuth() async {
    state = const AsyncLoading();
    Future result = _account.createOAuth2Session(
      success: "https://<domain>/googlevalid",
      failure: "https://<domain>/googleinvalid",
      provider: 'google',
    );

    result.then(
      (response) {
        print(response.runtimeType);
        state = const AsyncData(true);
        state = const AsyncData(null);
      },
    ).onError((e, st) {
      print('Error block has been executed');
      print(e);
      state = AsyncError(e!);
      _ref.refresh(authRequestStateProvider);
      state = const AsyncData(null);
    });
  }

this is my debug console logs after creating a new account & logging in with Google OAuth, which has contradictory results :

I/flutter (26912): Received URI: https://<domain>/googlevalid
I/flutter (26912): Error block has been executed
I/flutter (26912): PlatformException(CANCELED, User canceled login, null, null)

Contradictory is that , it sends the success redirect link (and successfully create account or log in the account) but at the same time enters the .onError() block of code.

Note : I/flutter (26912): Received URI: https://<domain>/googlevalid this log come via usage of 'uni_links' plugin from pub.dev,
which catches the app & deep links.

Problem is that , app links are designed to get back the app to the foreground automatically by their nature. appwrite oauth api shouldn't detect it as a cancelling action that has come from user's gesture.

👍 Expected behavior

Problem is that , app links are designed to get back the app to the foreground automatically by their nature. appwrite oauth api shouldn't detect it as a cancelling action that has come from user's gesture.

👎 Actual Behavior

Appwrite throwed PlatformException(User canceled login) as if user had canceled the login (which is actually not happened)

🎲 Appwrite version

Version 0.13.x

💻 Operating system

Windows

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Activity

  1. added
    bug
    on Apr 24, 2022
  2. stnguyen90 commented on Apr 25, 2022

    @stnguyen90
    Contributor

    If you use empty string for success and failure redirects, do you still have the problem?

    Also did you follow these instructions: https://github.com/appwrite/sdk-for-flutter/tree/4.0.0#android

  3. devberkay commented on Apr 25, 2022

    @devberkay
    Author

    yes, i have already followed the instructions on the link.

    When i put empty strings i didn't have any problem and it entered the result.then(onData) block of code, but of course didn't redirect itself back to the app

    also, now i am unable to test my auth module anymore, all of a sudden , i have started to facing with another issue, appwrite gives (user_already_exists) error although my user list is empty on appwrite web console so i am totally stuck... I can't test my app's authentication by reusing the same e-mail adresses

  4. stnguyen90 commented on Apr 25, 2022

    @stnguyen90
    Contributor

    The instructions have you set a url scheme like appwrite-callback-[PROJECT_ID] that should enable redirect back into your app.

    What result.then?

    When you delete the user from your admin console it just hides them. This is to prevent reuse of the email/id.

  5. devberkay commented on Apr 25, 2022

    @devberkay
    Author

    Exactly the moment i started to try your recommendation, i started to get "user_already_exists" error, therefore i can't answer what was the result.then,

    to continue testing my oauth2 functions, Firstly, i have to resolve my "user_already_exists" problem, I need a way of completely deleting an account created via oauth2 and then able to recreate it in a clean way, do we have this in appwrite?

    1-User api(ServerSDK) doesn't provide a way of deleting a user completely,
    2-I just learned from you that admin console only hides it (that's also bit odd because previously, i had deleted accounts from panel that were created via oauth2 and tested them by recreating many times , but after some point it got buggy and never show up on panel's user list and at the same time appwrite started to anomalously produce "user_already_exists" error ) ,

    Assuming admin panel also only hides it and doesn't delete the account , then i am left with no choice testing my oauth functions by deleting and recreating them right? If that's the case, oauth2 functions are becoming unpractical in the matter of testing.

    Note : also this "user_already_exists" problem never showed up when i created accounts via account.create and then deleting them from console and keep doing that multiple times and never faced with a problem.

  6. stnguyen90 commented on Apr 26, 2022

    @stnguyen90
    Contributor

    So I was incorrect when I said the user is just hidden. Several attributes including email are set to null so it should be possible to create the user again. There may be a bug somewhere but I'm not sure where.

  7. lohanidamodar commented on Apr 28, 2022

    @lohanidamodar
    Member

    @canbrkkyGit
    if you are using unique ID to create User and deleted via Server side API, you should not get user_already_exists but if the ID is not unique you get this because we don't delete User, we set everything to null so that ID cannot be reused to prevent permission issues.

  8. lohanidamodar commented on Apr 28, 2022

    @lohanidamodar
    Member

    Regarding the exception, I've been looking into it, it's probably something to do with how flutter_web_auth package works, will update you regarding this. But as @stnguyen90 suggested, you should be able to correctly redirect, if you set the callback on android as suggested in the https://github.com/appwrite/sdk-for-flutter/tree/4.0.0#android with correct project id and pass success and failure as empty string, you should be correctly redirected back to the Application.

  9. devberkay commented on Apr 28, 2022

    @devberkay
    Author

    @lohanidamodar

    regarding userId , yes i have already had 0 zero problems recreating accounts via e-mail password method , it accepts "userId:unique()" and maybe because oauth2 function doesn't have that ,it is becoming buggy after some number of recreating action but i am not sure about its userId handling mechanism.

    regarding redirect, i am not using success and failure redirect links anymore and having 0 problems with redirect, appwrite's deep link works flawlessly.(of course , at the cost of using meaningless deep link instead of app links uri with a meaningful path e.g. googlevalid,facookinvalid etc.)

    just to be in the safe side, i am not testing oauth2 with my actual accounts anymore and using only the facebook oauth2 for testing, you can easily create mock accounts on developer.facebook(roles->test accounts) to enter its credentials.

    note : I have already deleted and recreated my appwrite project but learnt this afterwards,
    for future visitors, there is a "docker-compose logs appwrite-worker-deletes" command you can use to see the regarding logs about deletion operations. It may help about why does that problem occur. If i also run into the same "user_already_exists" problem with oauth2 functions, i will update here .

  10. lohanidamodar commented on Apr 28, 2022

    @lohanidamodar
    Member

    @canbrkkyGit In order to use meaningful links, try using appwrite-callback-[projectID]://yourdomain.com/your_meaningful_path where yourdomain.com should be a valid domain added in valid redirect URLs in OAuth providers and Appwrite platforms as well.

    Let me know if this works

  11. devberkay commented on Apr 28, 2022

    @devberkay
    Author

    Not working :

    AppwriteException: null, Invalid OAuth2 Response. Key and Secret not available.

  12. added
    product / auth
    on Jan 17, 2023
  13. stnguyen90 commented on May 25, 2023

    @stnguyen90
    Contributor

    @devberkay actually, I don't think you have use any random your_meaningful_path. You'll have to use /auth/oauth2/success for the success path and /auth/oauth2/failure for the failure path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugproduct / auth

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions