capacitor-community / generic-oauth2

Generic Capacitor OAuth 2 client plugin. Stop the war in Ukraine!
MIT License
231 stars 113 forks source link

Bug: I am getting an error - ERR_STATES_NOT_MATCH on Android #203

Closed Keyurhardas closed 2 years ago

Keyurhardas commented 2 years ago

Capacitor version:

Latest Dependencies:

@capacitor/cli: 3.4.3 @capacitor/core: 3.4.3 @capacitor/android: 3.4.3 @capacitor/ios: 3.4.3

Installed Dependencies:

@capacitor/ios: not installed @capacitor/core: 3.4.3 @capacitor/cli: 3.4.3 @capacitor/android: 3.4.3

Library version:

OAuth Provider:

Your Plugin Configuration

{
      appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
      authorizationBaseUrl:
        'https://login.microsoftonline.com/'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/v2.0/authorize',
      accessTokenEndpoint:
        'https://login.microsoftonline.com/'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/v2.0/token',
      responseType: 'token',
      scope: 'User.Read',
      pkceEnabled: true,
      logsEnabled: true,
      web: {
        responseType: 'token id_token',
        redirectUrl: 'http://localhost:8100',
        accessTokenEndpoint: '',
      },
      android: {
      redirectUrl: 'msauth://id.package.my/xxxxxxxxxxxxxxxxxxxxxxxxxxxx' // URL encoded signature hash
        accessTokenEndpoint: '',
        handleResultOnNewIntent: true,
        handleResultOnActivityResult: true,
      },
      ios: {
        redirectUrl: 'msauth.com.xxxxx://auth',

      },
    };

Affected Platform(s):

Current Behavior

I am getting an error - ERR_STATES_NOT_MATCH in my android app. When I change the responseType to "code" then I get a response from the server with the same configurations. I am not sure what am I doing wrong in here. On the web with responseType as "token" I get the access token but on android I get this error with responseType as "token".

Expected Behavior

I need to get the access token whenever the user logs in through the sign in page on Android. I have followed all the steps from the default android setup but I am not able to get the access token on Android.

Keyurhardas commented 2 years ago

Turns out there was an issue with my accessTokenEndpoint. My bad.
Everything is now working fine on Android with the configurations mentioned. Awesome plugin, Thanks!

nitish2407 commented 1 year ago

Hi @Keyurhardas will you please help me how you solved the issue. I am also facing the same issue