MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
270 stars 243 forks source link

Android production build in Play Store doesn't work #299

Closed ewa-radomska-codeclusive closed 2 years ago

ewa-radomska-codeclusive commented 2 years ago

I use app_auth to login my users. Application is working fine in debug mode (both emulator and real device). Profile APK is working fine. But after release the app and put it into the Play Store application doesn't work - login screen is shown, redirecting to login url is working fine, and then after login app crashes, it doesn't redirect. In iOS everything is working fine in AppStore version. I cannot figure out what I'm doing wrong.

The code looks like this:

Login method:

  final String _clientId = 'myclientId'
  final String _redirectUrl = 'my.redirect.link:/oauthredirect';

  final String _discoveryUrl =
      'https://my.mobile.link/.well-known/openid-configuration';

  final List<String> _scopes = <String>[
    'openid',
    'profile',
    'email',
    'offline_access',
    'admin-api'
  ];

  final AuthorizationServiceConfiguration _serviceConfiguration =
      const AuthorizationServiceConfiguration(
    authorizationEndpoint: 'https://my.mobile.link/connect/authorize',
    tokenEndpoint: 'https://my.mobile.link/connect/token',
    endSessionEndpoint: 'https://my.mobile.link/connect/endsession',
  );

  @override
  Future<Either<EngageException, AuthorizationTokenResponse>> getToken() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();

    try {
      final AuthorizationTokenResponse? result =
          await _appAuth.authorizeAndExchangeCode(
        AuthorizationTokenRequest(
          _clientId,
          _redirectUrl,
          serviceConfiguration: _serviceConfiguration,
          scopes: _scopes,
        ),
      );
      if (result != null) {
        await prefs.setString('token', result.accessToken!);
        await prefs.setString('refreshToken', result.refreshToken!);
        await prefs.setString('idToken', result.idToken!);
        return Right(result);
      } else {
        return const Left(EngageException.serverError());
      }
    } catch (e) {
      return const Left(EngageException.serverError());
    }
  }

build.gradle elements:

  defaultConfig {

        applicationId "app.name"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        manifestPlaceholders += [
                'appAuthRedirectScheme': 'my.redirect.link'
        ]
    }

manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="link.engageDev.engageApp">
   <uses-permission android:name="android.permission.INTERNET"/>

 <application
        android:label="${appName}"

        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />

            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

    <queries>
      <intent>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" />
      </intent>
      <intent>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.APP_BROWSER" />
        <data android:scheme="https" />
      </intent>

  <!-- If your app makes calls -->
  <intent>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
  </intent>
  <!-- If your sends SMS messages -->
  <intent>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="smsto" />
  </intent>
  <!-- If your app sends emails -->
  <intent>
    <action android:name="android.intent.action.SEND" />
    <data android:mimeType="*/*" />
  </intent>

</queries>
</manifest>
MaikuB commented 2 years ago

Have you tried doing a release build and sideloading that to one of your devices? IMO that really should've been done before you've released to app store or could've used an alpha/beta track.

I'm not going to be able to tell you what you're doing wrong but note that no one has reported release build issues so the problem is likely to do something else that your app uses. You should check to see if you have other dependencies that require doing extra configuration for release builds. If you believe the plugin itself has a release build issue then you'll need to provide a link to repo with code for minimal app that can reproduce the issue

MaikuB commented 2 years ago

Closing due to lack of response and evidence that it is to do with this plugin