MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
269 stars 238 forks source link

authorize_and_exchange_code_failed, Failed to authorize: [error: null, description: Invalid ID Token] #486

Open ricardoBritoSantos opened 4 months ago

ricardoBritoSantos commented 4 months ago

I need urgent help, I'm trying to make my app authenticate with Microsoft Login ID.

If I use it the way below, there is no error and it can get the authorization code, so I think the application configuration in Azure is correct.

   final AuthorizationResponse? result = await appAuth.authorize(
     AuthorizationRequest(_clientId, _redirectUrl,
         discoveryUrl: _discoveryUrl, scopes: _scopes, loginHint: null),
   );

But I need the email address that logged in, so I understand that I need to use the method below, but when I use it it returns this error: Exception has occurred. PlatformException (PlatformException(authorize_and_exchange_code_failed, Failed to authorize: [error: null, description: Invalid ID Token], Issuer mismatch, null))

   final AuthorizationTokenResponse? result1 =
       await appAuth.authorizeAndExchangeCode(
     AuthorizationTokenRequest(
       _clientId,
       _redirectUrl,
       discoveryUrl: _discoveryUrl,
       scopes: _scopes,
     ),
   );

@MaikuB Can you help me please?

additional information

final String _discoveryUrl =
    'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration';
final List<String> _scopes = <String>['openid', 'profile', 'email'];
FullstackWEB-developer commented 1 month ago

@ricardoBritoSantos I also faced the same problem. Unfortunately, I was unable to find a solution with this package, so I manually configured the authentication logic using webview_flutter. Please refer this package