Frontend Application: https://github.com/komarov-ui/react-oidc-prototype
Backend Service: https://github.com/komarov-ui/nodejs-oidc-prototype
-
Go to
https://slproweb.com/products/Win32OpenSSL.html.NOTE: OpenSSL Light is enough for our purposes.
-
Download OpenSSL for Windows x64 and install it.
-
Update your PATH env variable in Windows. Add new row with value:
<Path to OpenSSL>/bin. Save.NOTE: Replace
<Path to OpenSSL>with path to folder where OpenSSL installed on your computer. -
Do checking in PowerShell:
opensll version. If there is an OpenSSL version - it's OK, keep going. -
Go to folder
create-ssl-certs(previously, you have to clone project or download it as ZIP-archive). -
Open PowerShell in this folder and run
./generate-cert.ps1.NOTE: If you are not allowed to run, you may try following command in the same folder:
powershell -ExecutionPolicy Bypass -File .\generate-cert.ps1 -
If there are 2 files
server.keyandserver.crt- it`s OK, keep going. -
Double-click on
server.crtto install certificate.-
Click "Install certificate" button.
-
Select "Current user".
-
"Place all certificates in the following store".
-
Click on "Browse" and select "Trusted Root Certification Authorities".
-
Click on "Next" and then click on "Finish".
-
Allow Windows to install self-signed certificate.
-
-
Create folder
sslin root of projectsreact-oidc-prototypeandnodejs-oidc-prototype. Putserver.keyandserver.crtin there (copy them there).OR you can go with alternative way and just change paths to certs in these projects.
- vite.config.ts - in
react-oidc-prototype - app.js - in
nodejs-oidc-prototype(almost end of the file)
- vite.config.ts - in
Before running frontend and backend service, you must raise up Keycloak Server.
It's really simple to do with following Docker command in Windows PowerShell.
NOTE: Replace <path_to_folder_with_certs> to appropriate path in commands.
docker run `
-p 8443:8443 `
-p 9000:9000 `
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin `
-e KC_BOOTSTRAP_ADMIN_PASSWORD=change_me `
-e KC_HTTPS_CERTIFICATE_FILE=/opt/keycloak/conf/server.crt `
-e KC_HTTPS_CERTIFICATE_KEY_FILE=/opt/keycloak/conf/server.key `
-v C:/<path_to_folder_with_certs>/server.crt:/opt/keycloak/conf/server.crt `
-v C:/<path_to_folder_with_certs>/server.key:/opt/keycloak/conf/server.key `
quay.io/keycloak/keycloak:26.1.2 `
start `
--hostname=localhostIf you use Podman instead of Docker, command will be almost the same:
podman run `
-p 8443:8443 `
-p 9000:9000 `
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin `
-e KC_BOOTSTRAP_ADMIN_PASSWORD=change_me `
-e KC_HTTPS_CERTIFICATE_FILE=/opt/keycloak/conf/server.crt `
-e KC_HTTPS_CERTIFICATE_KEY_FILE=/opt/keycloak/conf/server.key `
-v C:/<path_to_folder_with_certs>/server.crt:/opt/keycloak/conf/server.crt `
-v C:/<path_to_folder_with_certs>/server.key:/opt/keycloak/conf/server.key `
quay.io/keycloak/keycloak:26.1.2 `
start `
--hostname=localhostIt will run your Keycloak Server on address: https://localhost:8443
Path to Admin Console: https://localhost:8443/admin/master/console/
Credentials for Admin Console:
- Username:
admin - Password:
change_me
This instance of Keycloak Server is run in production mode with enabled HTTPS.
After first starting up Keycloak Server you will be able to configure it Admin Console and save changes by commiting changed container as image by command:
docker commit <CONTAINER_ID> <IMAGE_NAME>:<IMAGE_TAG>
If you use Podman instead of Docker, command will be almost the same:
podman commit <CONTAINER_ID> <IMAGE_NAME>:<IMAGE_TAG>
You can use this image instead of quay.io/keycloak/keycloak:26.1.2 and use flag --optimized.
Go to Admin Console ( https://localhost:8443/admin/master/console/).
-
Sign In with provided default credentials.
-
Click on realms dropdown at the top-left corner.
-
Click on "Create realm".
-
Put "oidc-app" in "Realm name" and click "Create".
-
Select "oidc-app" in realms dropdown.
-
Go to "Users" tab in menu.
-
Click on "Add user".
-
Put any username, email, first name, last name.
-
Click on "Create".
-
After navigation to user page, go to "Credentials" tab.
-
Click on "Set password".
-
Disable "Temporary" flag, set password and repeat password. Click on "Save".
-
Select "oidc-app" in realms dropdown.
-
Go to "Clients" tab in menu.
-
Click on "Create client".
-
Client ID: "test-oidc-client".
-
Click on "Next".
-
Enable "Client authentication".
-
Authentication flow: must be only enabled "Standard flow".
-
Valid Redirect URLs:
https://localhost:5173/*
- Valid post logout redirect URIs:
https://localhost:5173/*
- Web Origins:
https://localhost:5173
-
Click on "Save".
-
After navigating to client page, go to tab "Credentials".
-
Copy "Client secret" and put it into .env file in backend service in appropriate variable (KEYCLOAK_HTTPS_CLIENT_SECRET).
-
Go to your GitHub account.
-
Go to "Settings" -> "Developer Settings" -> "OAuth Apps".
-
Click on "New OAuth App".
-
Set any available application name (is not used in the prototype).
-
Set "Homepage URL" as
https://localhost:5173. -
Set "Authorization callback URL" as
https://localhost:8443/realms/oidc-app/broker/github/endpoint. -
Click on "Register application".
-
After navigation to app page, save "Client ID" and "Client secret" values.
-
Go to Keycloak Admin Console.
-
Select "oidc-app" in realms dropdown.
-
Go to "Identity providers" tab.
-
Click on "GitHub provider".
-
Set "Client ID" and "Client secret" into values saved from GitHub app page.
-
Click on "Add".
-
Select "oidc-app" in realms dropdown.
-
Go to "Realms settings".
-
Go to tab "Sessions".
-
Set "SSO Session Idle" into 2 minutes.
It may be your time, just remember it and pay attention that session idle time must be more than access token lifespan.
-
Go to tab "Tokens".
-
Set "Access Token Lifespan" into 1 minute.
It may be your time, just remember it and pay attention that access token lifespan must be less than session idle time.
Test case
-
Go to "Protcted Page".
-
Login in prototype from Frontend side.
-
Copy access token from cookies into some text file.
-
Wait for
<Access Token Lifespan>. -
Refresh page "Protected Page".
-
Copy access token from cookies AGAIN into some text file.
-
Compare it with previous token: they must be different.
-
Wait for
<SSO Session Idle>. -
Refresh page "Protected Page". You must be redirected into Keycloak Login Page.