flutter_keycloak 1.1.5 copy "flutter_keycloak: ^1.1.5" to clipboard
flutter_keycloak: ^1.1.5 copied to clipboard

A Flutter Keycloak wrapper, to manage the authentication and tokens automatically

flutter_keycloak #

Manage your Keycloak tokens in a Flutter app.

This plugin exposes some util methods to interact with [Keycloak][KeycloakHome] in order to handle the user session.

Documentation #

  • [Setup][SetupAnchor]
  • [API][APIAnchor]
  • [Utils][UtilsAnchor]

Setup #

App configuration #

Imports #

Import the library and initialize the plugin

import 'package:flutter_keycloak/flutter_keycloak.dart';

final FlutterKeycloak _flutterKeycloak = FlutterKeycloak();

API #

login #

void login() async {
  await _flutterKeycloak.login(
    _conf,
    _username,
    _password,
    scope: _scope,
  );
}

Sometimes you may need to re-login your user w/ Keycloak via the login process but, for some reason, you don't want / can't display the login page.
This method will re-login your user.

refreshLogin #

void refreshLogin() async {
  await _flutterKeycloak.refreshLogin(
    scope: 'offline_access',
  );
}

retrieveUserInfo #

void retrieveUserInfo() async {
  final userInfo = await _flutterKeycloak.retrieveUserInfo();
  setState(() {
    _currentPrefs = userInfo.toString();
  });
}

logout #

void logout() async {
  await _flutterKeycloak.logout();
  printStorage();
}

destroySession: Since the /openid-connect/token simply returns an access token and doesn't create any session on Keycloak side, if you used the login method you want to pass false.
Passing true tries to destroy the session: pay attention that on newer Keycloak versions this raises an error if no session is present, preventing the logout.

8
likes
120
pub points
83%
popularity

Publisher

verified publisherrollercoders.net

A Flutter Keycloak wrapper, to manage the authentication and tokens automatically

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

dio, flutter, flutter_secure_storage, get_storage

More

Packages that depend on flutter_keycloak