I have implemented flutter_appauth and I am using Keycloak as Authentication Server.
Code snippets are as follows: Main.dart
final String _clientId = 'flutter-demo-app';
//final String _redirectUrl = 'com.example.sampleflutterauthapp:/*';
final String _redirectUrl = 'com.example.sampleflutterauthapp:/*';
final String _issuer = 'https://10.0.2.2:8443/auth/realms/flutter';
final String _discoveryUrl =
'https://10.0.2.2:8443/auth/realms/flutter/.well-known/openid-configuration';
final String _postLogoutRedirectUrl = 'com.example.sampleflutterauthapp://';
final List<String> _scopes = <String>[
'openid',
'profile',
'offline_access'
];
final AuthorizationServiceConfiguration _serviceConfiguration =
const AuthorizationServiceConfiguration(
authorizationEndpoint: 'https://10.0.2.2:8443/auth/realms/flutter/protocol/openid-connect/auth',
tokenEndpoint: 'https://10.0.2.2:8443/auth/realms/flutter/protocol/openid-connect/token',
endSessionEndpoint: 'https://10.0.2.2:8443/auth/realms/flutter/protocol/openid-connect/logout',
);
Future<void> _signInWithAutoCodeExchange(
{bool preferEphemeralSession = false}) async {
try {
_setBusyState();
final AuthorizationTokenResponse? result =
await _appAuth.authorizeAndExchangeCode(
AuthorizationTokenRequest(
_clientId,
_redirectUrl,
serviceConfiguration: _serviceConfiguration,
scopes: _scopes,
preferEphemeralSession: preferEphemeralSession,
allowInsecureConnections: true,
),
);
My build.gradle file for Android App is as following for HTTPS redirection:
My keycloak config are as follows:
I am running my application on Pixel 5 API 31 (Andoid 12.0) as virtual device.
If I use following http url of Keycloak Server, It is working fine.
final String _issuer = 'http://10.0.2.2:8080/auth/realms/flutter';
If I use following HTTPS url of Keycloak Server, Authentication is done successfully but while redirecting to Android App I am getting Network Error
final String _issuer = 'https://10.0.2.2:8443/auth/realms/flutter';
PlatformException(authorize_and_exchange_code_failed, Failed to authorize: [error: null, description: Network error], java.security.cert.CertPathValidatorException: Trust anchor for certification path not found., null)
Kindly let me know what am I missing here to make it work with HTTPS.