Skip to content

ssc3/keycloak-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Keycloak Example

This is a simple example of using keycloak to build an authentication system for a python flask application

How to run?

git clone this repo

To start keycloak service

./run_keycloak.sh

Keycloak server should be visible at http://localhost:8080/auth/admin

To start flask server, start another terminal

cd api
python -m venv venv
source venv/bin/activate
python -m pip install -r requirements.txt
cd ..
./run_api_server.sh

Python flask server should be visible at http://localhost:5000/

How to enable authentication?

Visit keycloak at http://localhost:8080/auth/admin Enter the username and password from ./run_keycloak.sh You should now be able to see the realm Master.

Screen Shot 2021-09-04 at 9 48 31 PM

Create a new realm for your app called hello-world and hit Create Screen Shot 2021-09-04 at 9 51 05 PM

Enable User Registration and Email as username

Screen Shot 2021-09-04 at 10 05 47 PM

In this new realm, create a new client with the name hello-world-app Screen Shot 2021-09-04 at 9 51 54 PM

Screen Shot 2021-09-04 at 9 53 00 PM

Make access type confidential for this client

Screen Shot 2021-09-04 at 9 53 45 PM

Set Root URL, Valid Redirect URIs and Web Origins to appropriate urls

Screen Shot 2021-09-04 at 10 02 49 PM

Don't forget to click Save at the bottom

Get the client id and secret for hello-world-app. The client id is exactly the name of the client hello-world-app. The client secret is generated as shown in the screenshot below.

Screen Shot 2021-09-04 at 9 57 22 PM

Open the file client_secrets.json in an editor. Insert the client id and secret into this file.

Screen Shot 2021-09-04 at 9 59 00 PM

Rerun ./run_api_server.sh. Now visit localhost:5000 and click on Log in

Screen Shot 2021-09-04 at 10 01 34 PM

You should now be able to register and user and log in with that user

Screen Shot 2021-09-04 at 10 07 16 PM

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors