- Go to GitHub profile settings and create a new OAuth app.
- Generate client secret
- Set authorization callback URL to:
http://localhost:8080/realms/demo/broker/github/endpoint, and home page URL to:http://localhost:3000 - Rename the
.example.envfile to.env - Copy
Client IDas set it asGITHUB_APP_CLIENT_IDin the.envfile - Click on
Generate a new client secretcopy the secret and set asGITHUB_APP_CLIENT_SECRETin the.envfile
Run keycloak:
docker compose up -d --waitInstall the dependencies and run the complete example in one command:
npm install && npm startOn the NextJS frontend, click the "Login" button. Once the login is complete, the Frontend will automatically fetch the data and inject the bearer token into the origin request.
http://localhost:8080/- user name: admin
- password: admin
By default, Keycloak roles are exposed through realm_access.roles and resource_access.<client_id>.roles claims. If you wish to populate the User.roles field with these roles, you will need to configure Keycloak's mapper settings accordingly.
Follow these steps to achieve this configuration:
- Open the Keycloak admin console and select the
demorealm. - Navigate to
Clients Scope>roles>Mappers>realm rolesand perform the following configuration:- Set Token Claim Name to
roles. - Ensure all switch prefixed with Add to ... are enabled.
- Set Token Claim Name to
- Do the same for
client rolesunder the same Mappers tab.
Read the Docs.
Join us on Discord!