Keycloak Configuration Guide
At this point you should have a keycloak endpoint, next weâre going to configure it
Keycloak Overview
Realms
A keycloak realm specifies a grouping of users as well a configuration to determine how they login
Weâre going to have 3 realms
- master realm: This is the default realm, and it will contain the pool of keycloak administration users
- STAR Voting realm: The primary production realm, all users who login through the website will be stored in this realm
- STAR Voting Dev realm: This will be identical to the STAR Voting realm, except itâs intended for development puproses. Weâll use this realm to store mocked users and experiment with new keycloak features
Clients
Each realm can have multiple clients, and each client represents a login endpoint. For example the mobile and webapp could access the same realm through a different client
Weâll use just have one star_vote_web client per realm (excluding master) for now
Open ID Connect
The STAR Voting website will interact with Keycloak using the Open ID Connect protocol. Hereâs a good overview
https://www.youtube.com/watch?v=t18YB3xDfXI
Having a high level understanding of OIDC will make the setup process more clear
Update Admin password
We deployed the service with the password set to password, letâs change that
- Navigate to the keycloak endpoint (https://auth.star.vote:8443), and login using username: admin and password: password
- Click âUsersâ
- Click âView all usersâ and open the first one
- Go to âCredentialsâ tab, and reset the password
Create Admin users
We shouldnât ever need to use the root admin user, instead we should create seperate admin users for everyone who needs admin access
- Click âUsersâ
- Click âAdd Userâ
- Fill out all the fields
- Include âUpdate passwordâ in required user actions
- Hit âSaveâ
- Under âCredentialsâ specify a placeholder password
- Under âRole Mappingsâ add âadminâ to the assigned roles
- Repeat for all the users you want to add
Create New Realms
Repeat all the the following steps for the STAR Voting realm and the STAR Voting Dev realm
- Hover over âMasterâ in the top left, and click âAdd Realmâ
- Give it a name (STARVoting or STARVotingDev), and hit create
- Under âRealm Settingsâ
- Set the display name to include spaces
- Enable User-Managed Access
- Under âRealm Settingsâ > âLoginâ. Enable the following
- User Registration
- Forgot password
- Remember me
- Verify email
- Under âRealm Settingsâ > âEmailâ. Set the following (this assumes you setup sendgrid seperately)
- Host: smtp.sendgrid.net
- Port: 465
- From: elections@star.vote
- Enable SSL: ON
- Enable Authenticaion: ON
- Authentication Username: apikey
- Authentication Password: Use SENDGRID_API_KEY from drive
- Under âRealm Settingsâ > âToken Settingsâ. Set the following
- SSO Session Max: 10 Days
- Access Token Lifespan: 5 Days
- (there might be more, if user sessions are expiring too quickly you can come back to make tweaks)
- Under âClientsâ, select âCreateâ and specify the following and hit âSaveâ
- Client ID: star_vote_web
- Under âClientsâ > âstar_vote_webâ > âSettingsâ set the following and hit âSaveâ
- Name: Star Vote Website Client
- Access Type: confidential (public might be more correct? but our process is setup assuming confidential link)
- Service Accounts Enabled: OFF (this was ON in the previous setup but I donât think we need it?)
- Valid Redirect URISs: (these are all the websites that can use this login endpoint)
- https://bettervoting.com
- https://bettervoting.com/*
- http://localhost:3000 (this is useful for testing)
- Under âclientsâ > âstar_vote_webâ > âCredentialsâ set the following and hit âSaveâ
- Client Authenticator: Client Id and Secret
Add login with Google
We have all google api stuff under mike@equal.vote
Follow the guide here to set that up
https://keycloakthemes.com/blog/how-to-setup-sign-in-with-google-using-keycloak
Point website to new endpoint
The dev and production environments need to be updated to point to the new keycloak service. Youâll need the endpoint and secret for this
- endpoint: The OIDC endpoint would be https://auth.star.vote:8443/realms/STARVotingDev/protocol/openid-connect (remove the Dev for the production environment)
- secret: Copy this from âClientsâ > âstar_vote_webâ > âCredentialsâ
NOTE: Aside from the domain the endpoint structure is slightly different from the previous pattern due to a recent keycloak update more info
Dev Environment
For the development realm, update the credentials in drive
Production Environment
For production youâll need to access heroku and update the KEYCLOAK_SECRET and KEYCLOAK_URL environment variables
Frontend
For now the endpoint is still hardcoded on the front end side, youâll need to go into frontend/src/App.tsx
and apply the endpoint there
WARNING: The front end does not need the secret. This is by design. The front end code can be accessed by anyone, so OIDC is setup to only use the secret from the backend
Done
and youâre all set, congratulations!