FormidableLabs / react-native-app-auth

React native bridge for AppAuth - an SDK for communicating with OAuth2 providers
https://commerce.nearform.com/open-source/react-native-app-auth
MIT License
2.01k stars 439 forks source link

App crashes on Android when trying to authorize or redirect to provider login screen: state cannot be null or empty #866

Open GustavoBenevenuto opened 1 year ago

GustavoBenevenuto commented 1 year ago

Issue

Crash when logging into the application the first time, the other times it works normally. When the token expires and logout is called, the app also gives an error.

Note: Note: We are using react-native-config for environment variables and login with WSO2

The following error is returned:

java.lang.RuntimeException: Unable to resume activity {com.apptort/net.openid.appauth.AuthorizationManagementActivity}: java.lang.NullPointerException: state cannot be null or empty

java.lang.RuntimeException: Unable to resume activity {com.apptort/net.openid.appauth.AuthorizationManagementActivity}: java.lang.NullPointerException: state cannot be null or empty
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4975)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5008)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:210)
    at android.os.Looper.loop(Looper.java:299)
    at android.app.ActivityThread.main(ActivityThread.java:8252)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Caused by: java.lang.NullPointerException: state cannot be null or empty
    at net.openid.appauth.w.f(Unknown Source:9)
    at net.openid.appauth.w.d(Unknown Source:0)
    at net.openid.appauth.s$b.d(Unknown Source:2)
    at net.openid.appauth.s$b.b(Unknown Source:6)
    at net.openid.appauth.g.b(Unknown Source:31)
    at net.openid.appauth.AuthorizationManagementActivity.e(Unknown Source:23)
    at net.openid.appauth.AuthorizationManagementActivity.h(Unknown Source:8)
    at net.openid.appauth.AuthorizationManagementActivity.onResume(Unknown Source:26)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1565)
    at android.app.Activity.performResume(Activity.java:8668)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4965)
    ... 13 more

AndroidManifest.xml

    <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
        <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="com.apptort"/>
        </intent-filter>
    </activity>

    <activity
        android:name="net.openid.appauth.RedirectUriReceiverActivity" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="com.apptort.auth"  />
        </intent-filter>
    </activity>

.env

ISSUER = "https://url/oauth2/oidcdiscovery"
CLIENTID = "_secret_"
CLIENTSECRET = "_secret_"
REDIRECTURL = "com.apptort.auth://TortList"
POSTLOGOUTREDIRECTURL = "com.apptort.auth://Welcome"

config

const config = {
    issuer: Config.ISSUER,
    clientId: Config.CLIENTID,
    clientSecret: Config.CLIENTSECRET,
    redirectUrl: Config.REDIRECTURL,
    scopes: ['openid', 'profile'],
    dangerouslyAllowInsecureHttpRequests: true,
};

Environment

anehustorov commented 1 year ago

Hey, did you solve this issue?

GustavoBenevenuto commented 1 year ago

@anehustorov I still couldn't solve