# Configure Keycloak Authentication Provider for User Log in

This document provides instructions on how to configure Keycloak Authentication Provider in PBMS to help the end-users to utilise the Keycloak option to log into PBMS.

## Prerequisites

* Create a Keycloak client for PBMS/Social Registry as given in [Keycloak Client Creation](https://docs.openg2p.org/1.3/deployment/deployment-guide/keycloak-client-creation) guide.
* Install the OpenID Connect Authentication module.

Note:

* OAuth providers can be created from Odoo Settings (debug mode).
* For configuration reference refer the [OpenID Connect Authentication](https://docs.openg2p.org/1.3/pbms/developer-zone/odoo-modules/openid-connect-authentication) documentation.

## Procedure

1. Click the main menu icon ![](https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-1b48611b7e3fc05b72b589735073c90404ac05ef%2Fmain-menu.png?alt=media) and select ***Settings***.

<figure><img src="https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-9ff7a502b45ca2df16b0377cee4062860c55bdb4%2Fpbms-settings.png?alt=media" alt=""><figcaption></figcaption></figure>

The ***Settings*** screen is displayed.

2. Select the tab ***Users & Companies***, and click the option ***OAUTH Providers***.

<figure><img src="https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-ba0a0030e198098742d2a32427d1cacb696aaa49%2Fpbms-settings-oauth.png?alt=media" alt=""><figcaption></figcaption></figure>

***Providers*** screen is displayed.

<figure><img src="https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-d6b8548e364ad849299cfd1b4ad7282545e9ca69%2Fproviders-pbms.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Click the ***New*** button.

***Providers New*** screen is displayed.

<figure><img src="https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-fb0ad62c16b43d5070bd0c18404ccab1a5d7a4ee%2Fproviders-new-pbms.png?alt=media" alt=""><figcaption></figcaption></figure>

4. Enter the values in the respective fields.

For example, the fields, their descriptions, and sample values are given below.

<table><thead><tr><th width="230">Feature</th><th width="281">Description</th><th>Value</th></tr></thead><tbody><tr><td>Provider name</td><td>Enter the provider name.</td><td>For example: Keycloak for PBMS Login</td></tr><tr><td>Auth Flow</td><td>Select the option <em><strong>OpenID Connect Authorization Code Flow</strong></em> from the drop-down.</td><td></td></tr><tr><td>Token Map</td><td>You can find a default value. In the default value change <code>groups:groups</code> to <code>client_roles:groups</code> .</td><td></td></tr><tr><td>Client ID</td><td><p>The ID of the Keycloak client.</p><p>To learn more refer to <a href="../../../../../deployment/deployment-guide/keycloak-client-creation">Keycloak Client Creation</a>.</p></td><td></td></tr><tr><td>Client Authentication Method</td><td>Select the option <em><strong>Client Secret (Post)</strong></em> from the drop-down.</td><td></td></tr><tr><td>Client Secret</td><td>The <em><strong>Client Secret</strong></em> of the Keycloak client. To learn more, refer to <a href="https://docs.openg2p.org/deployment/deployment-guide/keycloak-client-creation">Keycloak Client Creation</a>.</td><td></td></tr><tr><td>Allowed</td><td>Check the box to enable the option <em><strong>Allowed</strong></em>.</td><td></td></tr><tr><td>Allowed in Self Service Portal</td><td>Uncheck the box.</td><td></td></tr><tr><td>Allowed in Service Provider Portal</td><td>Uncheck the box.</td><td></td></tr><tr><td>Login button label</td><td>Enter the label name for the Keycloak Login button.</td><td><p>For example: <code>Login with Keycloak.</code></p><p>Note: This text with the button name will appear on login page.</p></td></tr><tr><td>Image Icon URL</td><td>Enter the URL of an image for the Keycloak Login button.</td><td></td></tr><tr><td>Authorization URL, Userinfo URL, Token Endpoint, JWKS URL</td><td><p>These are to be configured as available in the well-known config of Keycloak.</p><p>Note:</p><p>Keycloak OIDC well-known configuration can be found in Keycloak Admin Console -> Realm Settings -> (Bottom of Page) Endpoints -> OIDC Endpoint Configuration)</p></td><td></td></tr><tr><td>Verify Access Token Hash</td><td>Check the box to enable the option <em><strong>Verify Access Token</strong></em>.</td><td></td></tr><tr><td>Allow Signup</td><td>Select the option <em><strong>Allows user signup</strong></em> from the drop-down.</td><td></td></tr><tr><td>Signup Default Groups</td><td>Select the option <em><strong>User types/Portal</strong></em> from the drop-down.</td><td></td></tr><tr><td>Sync User Groups</td><td>Select the option <em><strong>On every Login</strong></em> from the drop-down.</td><td></td></tr></tbody></table>

Note:

The rest of the fields have the default values.

5. Click the icon ![](https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-0082283cd63edf1a7973f4cf04936f150b6aed9d%2Fsave-button.png?alt=media) to save the changes.

If you have configured the ***Keycloak Authentication Provider*** successfully, you can find the ***Log in Keycloak*** button in the PBMS log in page.

Before log in using the option Keycloak in PBMS, ensure the following:

* Create client roles on Keycloak application for the client. The client roles can be
  * Administrator/Settings.
  * OpenG2P Module Access/Administrator.
  * OpenG2P Module Access/Registrar.

<figure><img src="https://1895884874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKdOHLbjDdIln1QDNwSx%2Fuploads%2Fgit-blob-da3709372ac670c4cfc2105e7fddba9f9ca8404d%2Flogin-page.png?alt=media" alt=""><figcaption></figcaption></figure>

This completes the configuration of ***Keycloak Authentication Provider*** in PBMS for user log in.
