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
1.97k stars 438 forks source link

'org.openid.appauth.general error -3' Intermittent issue #813

Open sarasamuel opened 1 year ago

sarasamuel commented 1 year ago

Issue

I'm currently using react-native-app-auth 6.4.3 and react native 0.70.6, and I'm using the react-native-app-auth authorization function as follows:

        const config = {
            authority: "x",
            clientId: this.clientID, 
            clientSecret: this.clientSecret,
            redirectUrl: this.redirectURI, 
            scopes: ["openid"],
              loadUserInfo: false,
              serviceConfiguration: {
                authorizationEndpoint: authorizationEndpoint,
                tokenEndpoint: tokenEndpoint
              },
              additionalParameters: {
              },
              clientAuthMethod: "",
              dangerouslyAllowInsecureHttpRequests: false,
              customHeaders: {
                token: {},
                authorize: {},
                register: {},
              },
              additionalHeaders: {},
                useNonce: false,
                usePKCE: false,
                skipCodeExchange: true,
                connectionTimeoutSeconds: 60,
                issuer: issuer
              }

        await authorize(config).then(async (res)=> {
           .... //some stuff
          })
        .catch((err)=>console.log("ERROR:", err));

Sometimes I am able to log in as expected, but other times it catches the error, "The operation couldn’t be completed. (org.openid.appauth.general error -3.)". The issue is very intermittent. Is there a suggested fix for this issue?


Environment

PauloHFS commented 1 year ago

I have capture this error on my app in production by sentry but only on android devices, but I can't reproduce this on my environment, can you explain more about you issue, or paste here the error stack trace, it can help! I am working on get by sentry the error stack trace in future releases of my app.

souravdasslg commented 1 year ago

Facing the same issue :(

mdiin commented 1 year ago

Not sure anymore, but I think I see this consistently in our Sentry logs when a user cancels the login modal. You might try closing the authentication modal before completing the auth flow to see if that reproduces the error.

sarasamuel commented 1 year ago

I think I found a fix for this. Essentially, I was calling the authorize() function asynchronously and attempting to set the auth state while awaiting authorize(). It seems as if structuring the code this way caused the auth component to re-render, at which point the error would arise. I resolved this by wrapping the authorization function in a useCallback() hook (similar to the structure in the example code), which prevents it from being run on each render.