Bdaya-Dev / oidc

Flutter OpenIdConnect plugin
https://bdaya-dev.github.io/oidc/
MIT License
33 stars 16 forks source link

fix: Failed to authorize: #128

Open bsutton opened 2 weeks ago

bsutton commented 2 weeks ago

Description

Probably not a bug just me not knowing how to use the system.

I'm getting an error during the auth process on Android - I have no trouble authing on linux using the same code base.

PlatformException: PlatformException(null_intent, Failed to authorize: Null intent received, null, null)
method_channel_flutter_appauth.dart in MethodChannelFlutterAppAuth.authorize at line 21 within flutter_appauth_platform_interface
Called from: <asynchronous suspension>
oidc_flutter_appauth.dart in OidcFlutterAppauth.getAuthorizationResponse at line 46 within oidc_flutter_appauth
Called from: <asynchronous suspension>
user_manager_base.dart in OidcUserManagerBase.tryGetAuthResponse at line 283 within oidc_core
Called from: <asynchronous suspension>
xero_auth.dart in XeroAuth.login at line 57 within hmb

My auth code:

 Future<void> _init() async {
    final _scopes = <String>[
      'openid',
      'profile',
      'email',
      'offline_access',
      'accounting.transactions',
      'accounting.contacts'
    ];

    final credentials = await _fetchCredentials();
    manager = OidcUserManager.lazy(
        discoveryDocumentUri: OidcUtils.getOpenIdConfigWellKnownUri(
          Uri.parse('https://identity.xero.com'),
        ),
        clientCredentials: OidcClientAuthentication.clientSecretBasic(
            clientId: credentials.clientId,
            clientSecret: credentials.clientSecret),
        store: OidcDefaultStore(),
        settings: OidcUserManagerSettings(
            scope: _scopes, redirectUri: _getRedirectUrl()));

    // Initialize the manager
    await manager!.init();

  }

Android Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="dev.onepub.handyman">
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <!-- <uses-permission android:name="android.permission.SEND_SMS" /> -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!-- <uses-permission android:name="android.permission.RECEIVE_SMS" /> -->
    <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
    <!-- so we can backup the db -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <!-- backup_ruiles and data_extraction_rules required by oidc package -->
    <application android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:enableOnBackInvokedCallback="true" android:fullBackupContent="@xml/backup_rules" android:dataExtractionRules="@xml/data_extraction_rules">
        <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTask" android:taskAffinity="" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
            <!--
            Specifies an Android theme to apply to this Activity as soon as
            the Android process has started. This theme is visible to the user
            while the Flutter UI initializes. After that, this theme continues
            to determine the Window background behind the Flutter UI.
            -->
            <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" />
            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SENDTO" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="smsto" />
            </intent-filter>
            <!-- App Link:  deep linking -->
            <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="https" android:host="ivanhoehandyman.com.au" android:pathPrefix="/xero/auth_complete" />
                <data android:scheme="http" />
            </intent-filter>
            <!--
            Don't delete the meta-data below.
            This is used by the Flutter tool to generate GeneratedPluginRegistrant.java
            -->
            <meta-data android:name="flutterEmbedding" android:value="2" />
        </activity>
    </application>
    <!--
    Required to query activities that can process text, see:
    https://developer.android.com/training/package-visibility and
    https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

    In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin.
    -->
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT" />
            <data android:mimeType="text/plain" />
        </intent>
          <!-- If your app checks for SMS support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="sms" />
        </intent>
        <!-- used by flutter_email_sender to send emails. -->
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>
</manifest>

Steps To Reproduce The above code is called from a physical Android device (pixel 5 - android 14) and I successfully complete the xero authentication via the browser. Once the auth is complete my app comes to the foreground with the above exception being thrown.

Even if this isn't a bug the lack of useful information in the exception makes this essentially impossible to debug.

The same process/code works without issue on Linux.

ahmednfwela commented 2 weeks ago

hi @bsutton this is an issue with flutter appauth https://github.com/MaikuB/flutter_appauth/issues/493