keycloak integration Flutter

Abhishek
3 min readJul 2, 2021
keycloak login page

i am gonna tell you the steps to authenticate your flutter through Keycloak (Keycloak is an open source software product to allow single sign-on with Identity and Access Management aimed at modern applications and services). Steps to run keycloak’s docker image image on local and connect .

  1. Install Docker in you system .
  2. Run the command as documented .

docker pull jboss/keycloak

docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -p 8080:8080 jboss/keycloak

3.Go to ur browser and open http://localhost:8080/auth/ . You get something like this page .click on Administration console link.

4) On login page put username and password as per docker run command (i.e admin /admin ) .

5) click on Add realm .

6)Give name to you realm ex.flutter-app

7) Add new client detials ex .flutter-client

once saved out Standard Flow Enabled as False in settings of flutter-client.

8)Create a new user with details

If you have reached to this then Congratulation!!, your Keycloak all running fine with new user .Now let’s Move to Flutter App.As of now we don’t have any library to support Keycloak flutter/dart, so we will have to write code for the same.I have written the code in in bloc pattern to handle all the state ,But for this Article i show you only service calling part in next part of this article i will show you detail explanation in bloc to communicate to keycloak.

1) let’s create a env.dart like to keep our url and client ID

2) lets create Repository service to call keycloak as rest api .

we need to connect with OpenId to get Token .

String url = Environement.SSO_URL + ‘/protocol/openid-connect/token’;

We will see detail code in next article .Bye bye.

“Lets Make the world a better place”

--

--