flutter_appauth_platform_interface web implementation
Opened this issue · 0 comments
PandukaBWedisinghe commented
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 initialise locator.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.