MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
274 stars 246 forks source link

flutter_appauth_platform_interface web implementation #501

Closed PandukaBWedisinghe closed 3 months ago

PandukaBWedisinghe commented 5 months ago

Can someone please help me with guidance to use flutter_appauth_platform_interface to support web app. I am already using flutter_appauth on Mobile and it is working.

When I try to use flutter_appauth_platform_interface and run on web, it throws

Error in signInWithAutoCodeExchange: MissingPluginException(No implementation found for method authorizeAndExchangeCode on channel crossingthestreams.io/flutter_appauth)

I am using GetIt package and initialiselocator.registerLazySingleton(() => FlutterAppAuthPlatform.instance); in my locator file.

Then


late FlutterAppAuthPlatform _appAuth;

Future<bool> signInWithAutoCodeExchange(String selectedUserProfile) async {
    const serviceConfiguration = AuthorizationServiceConfiguration(
      authorizationEndpoint: ApiUrlConstants.authorizationEndPoint,
      tokenEndpoint: ApiUrlConstants.tokenEndPoint,
      endSessionEndpoint: ApiUrlConstants.endSessionEndPoint,
    );

    final authorizationRequest = AuthorizationTokenRequest(
      ApiUrlConstants.clientId,
      ApiUrlConstants.redirectUrl,
      issuer: ApiUrlConstants.issuer,
      serviceConfiguration: serviceConfiguration,
      scopes: ApiUrlConstants.scopes,
      preferEphemeralSession: true,
      promptValues: ['login'],
    );
    bool isCodeExchangeSuccess = false;

    try {
      final result = await _appAuth
          .authorizeAndExchangeCode(authorizationRequest)
          .onError((error, stackTrace) {
        debugPrint("Error in signInWithAutoCodeExchange: $error $stackTrace");
        return null;
      });
      if (_isAuthResultValid(result)) {
        await _processAuthTokenResponse(result, selectedUserProfile);
        isCodeExchangeSuccess = true;
      }
    } catch (e) {
      debugPrint("Error $e");
    }
    return isCodeExchangeSuccess;
  }

This works on mobile both Android and iOS. Please help and support is highly appreciated.

MaikuB commented 3 months ago

What you're facing is expected as this plugin doesn't support web to begin with