logOutAccount method
Log out of Keycloak session and if successful proceed to logout locally
Implementation
Future<bool> logOutAccount() async {
OAuthAccount? account = currentOauthAccount ?? await loadAccountFromCache<OAuthAccount>();
if (account == null) throw new Exception("Invalid Account");
var postData = await getRefreshTokenPostData(account);
var resp = await httpClient.post(
Uri.parse(
"${this.baseUrl}/auth/realms/${this.realm}/protocol/openid-connect/logout"),
headers: {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
body: postData
);
if (resp.statusCode == 204) {
// print('KeycloakProvider.logOutAccount Success - Performing local logOut');
await this.logOut();
return true;
} else {
// TODO: Define Error/Exception classes to distinguish between network (external) exceptions and usage (internal) errors
print("KeycloakProvider.logOutAccount Failure - statusCode: ${resp.statusCode}, reason ${resp.reasonPhrase}");
return false;
}
}