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.04k stars 441 forks source link

Error: JSON deserialization error (Android) #752

Open sjransom opened 2 years ago

sjransom commented 2 years ago

Issue

I am getting JSON deserialization error with the following on Android ONLY - iOS is working as expected.

export const config = {
    issuer: 'https://opentest.coros.com',
    clientId: 'XXX',
    clientSecret: 'XXX',
    redirectUrl: `com.myapp.staging://oauth`,
    scopes: ['userInfo', 'runData'],
    serviceConfiguration: {
        authorizationEndpoint: `https://opentest.coros.com/oauth2/authorize`,
        tokenEndpoint: `https://opentest.coros.com/oauth2/accesstoken`,
        revocationEndpoint: `https://opentest.coros.com/oauth2/deauthorize`,
    }
}

const result = await authorize(config)

Response I am expecting (I got this via iOS as it works):

{
  "refreshToken": "XXX",
  "scopes": [],
  "accessToken": "XXX",
  "idToken": "",
  "tokenAdditionalParameters": {
    "openId": "XXX"
  },
  "tokenType": "",
  "authorizeAdditionalParameters": {},
  "accessTokenExpirationDate": "2022-08-19T10:24:57Z"
}

I have a hunch it's related to the tokenAdditionalParameters but I'm not 100% sure.

Worth noting I can't see any network request to COROS using Flipper.


Environment

sjransom commented 2 years ago

Also for reference just adding the COROS response from their API spec:

{
    "expires_in":2592000,
    "refresh_token":"08a06b7df38d0d2852e5927c763f09d5",
    "access_token":"db0214b6006e7570bd80b1894132b7bc",
    "openId":"b93ac3b5df6b4db3be5477706689427e"
}
oxidia commented 1 year ago

@sjransom matching the response described in https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/ solved my problem.

Aaqib925 commented 1 year ago

I used skipCodeExchange: true to resolve this error in config.

lionnel-afan commented 11 months ago

Using react-native-app-auth": "^7.1.0

In case someone is having this error with Dropbox. I'm currently working on a Dropbox integration and I was facing this same issue on Android. My usecase needed a refresh_token to be present in the response, which, according to the Dropbox documentation is filled in the response only when a token_access_type=offline is provided. Turns out the problem always happens, when I specify an additionalParameters with the token_access_type . After some testings, the only configuration that seems to be working for my use case is :

const config = {
            issuer : 'https://www.dropbox.com',
            clientId: CLIENT_ID,
            clientSecret: CLIENT_SECRET,
            redirectUrl: 'com.my_com_id://oauth',
            scopes: [], 
            serviceConfiguration: {
                authorizationEndpoint: 'https://www.dropbox.com/oauth2/authorize?token_access_type=offline',  //Notice the parameter here
                tokenEndpoint: `https://www.dropbox.com/oauth2/token`,
            }
            // For the time being, don't use the additionalParameters to specify the "token_access_type"
            //additionalParameters: {
            //     token_access_type:'offline'
            //},
 };

 const authresult = await authorize(config);

Make sure to specify the token_access_type in the authorizationEndpoint. Some more investigations are needed to know why the combination of additionalParameters and token_access_type didn't work.

rach-123 commented 6 months ago

Hi Team,

We are also facing the same issue in android physical device.We are using this lib to integrate with azure ADB2C.It would be great if we get any solution for the same.

Siddarthmalemath commented 5 months ago

Hi Team,

"react-native-app-auth": "^7.2.0", auth provider: ERP next (Frappe)

I'm facing the same issue when I omit skipCodeExchange: true, if I add it I'll get a response without code exchange. here is my config : config = { issuer: "https://site", skipCodeExchange: true, clientId: "sdfdsfads", clientSecret: "asdfdsf", redirectUrl: "com.myApp://oauthredirect, scopes: ["openid"], serviceConfiguration: { authorizationEndpoint: "https://site/.oauth2.authorize", //oauth/authorize tokenEndpoint: "https://site..oauth2.get_token", }, };

const authResult = await authorize(config); console.log("Auth State:", authResult);

I got to know the cause of the issue, I have debugged the lib and it is related to this ticket https://github.com/openid/AppAuth-Android/issues/233

any solution to this please help me

divyegd commented 3 months ago

We are facing the same issue on Android. Anyone has any insights on how to resolve it?

mandrade2 commented 2 weeks ago

I just had to add token_type: 'Bearer' in the response my backend sends on the tokenEndpoint and now my app works on Android!