MaikuB / flutter_appauth

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

Failed to authorize: [error: null, description: JSON deserialization error] #344

Closed Decodeuprefo closed 1 year ago

Decodeuprefo commented 2 years ago

I am trying to authenticate a user using authorizeAndExchangeCode method from FlutterAppAuth 4.0.1. I am getting an exception PlatformException(authorize_and_exchange_code_failed, Failed to authorize: [error: null, description: JSON deserialization error], Value Not of type java.lang.String cannot be converted to JSONObject, null) when I click on login button in my app.

This is what I am doing.

AuthorizationTokenResponse? loginResult = await _appAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
        AUTH0_CLIENT_ID,
        AUTH0_REDIRECT_URI,
        issuer: AUTH0_ISSUER,
        serviceConfiguration: AuthorizationServiceConfiguration(
               authorizationEndpoint: AUTHORIZATIONENDPOINT,
               tokenEndpoint: TOKENENDPOINT,
               endSessionEndpoint: ENDSESSIONENDPOINT,
               ),
        scopes: AUTH0_SCOPES,
      ));

Is there is anything wrong in this integration, Am I using FlutterAppAuth in correct way? Or anything else I need to do?

MaikuB commented 2 years ago

An error like this suggests that the response isn't a valid JSON, which in turn implies an incorrect configuration. If so, this is something you would need to look further into. I'm not able to provide more assistance/info on this

Decodeuprefo commented 2 years ago

If configuration is incorrect then there won't be any log for the login user, Right? But I am getting successful login log in the Auth0 dashboard for all type of login. But getting error when that data needs to be retrieved in the application. So, There is no any error in the configuration.

MaikuB commented 2 years ago

Not necessarily. For example, you can specify the wrong redirect URL and users can sign in. You're going to need to debug further and double check your config to figure out what's going. The code for the plugin is open-source so that would allow you to debug through the plugin itself