Setup Guide for Keycloak as an OAuth Server



  • Install Keycloak: Download Keycloak and install it.
  • Start Server: Start the keycloak server by running the _standalone.sh_ file.
  • Root Directory of keycloak bin standalone.sh
  • Add Realm : Now login to keycloak administration console and navigate to your desired realm. You can add new realm by selecting Add Realm option.
  • ss
  • Create realm: Enter Realm Name and click on CREATE to add realm.
  • Create ROLE: The Role will be used by your applications to define which users will be authorized to access the application. Click on the Roles and choose Add Role.
  • ss1
  • Add User: We need to add users to realm who will be able to access the resources of realm. Click on the Users and choose to Add a new User.
  • ss2
  • User Configuration: After user is created following action needs to be performed on it.
    • 1) Setting a password for it so click on Credentials and set a new Password for the user.

    ss3

    NOTE : Disabling Temporary will make user password permanent.

  • Map User: We need to map user to a role. Click on Role Mappings and assign the user desired role from available roles and clicking on add selected.
  • ss
  • Create groups: Click on the Groups and choose New to create a new group.
  • ss
  • Assign user to group: Select the user whom you want to add in group. Choose Groups option from tab and then select the group-name and click on join.
  • ss
  • Create OpenID client: Click on the Clients and choose create to create a new client. Enter client id and select client protocol openeid-connect and select Save.
  • ss
  • Change Access type: After client is created change its access type to confidential.
  • ss
  • Enter Valid Redirect URIs: Copy callback URL from plugin and then click on SAVE. Ex -- https:///oauth/callback
  • Keycloak Group Mapper: Now to get group details we need to perform its client mapping with group membership else group details will not be fetched. So in client select Mappers and then click on create. Select mapper type Group Membership and enter name and token claim-name i.e the attribute name corresponding which groups will be fetched and click on Save.
  • ss

    Note: -- If full path is on group path will be fetched else group name will be fetched.

  • Get Client Secret: Now we need to get client secret. So select Clients and select credentials and copy your secret from here.
  • ss
  • Plugin Configuration: Enter copied Client Secret here Client ID will be your client name and the URL are given below.
  • Scope: email profile
    Authorization Endpoint: <Keycloak base URL>/realms/{realm-name}/protocol/openid-connect/auth
    Token Endpoint: <Keycloak base URL>/realms/{realm-name}/protocol/openid-connect/token
    UseInfo Endpoint: <Keycloak base URL>/realms/{realm-name}/protocol/openid-connect/userinfo
    ss
  • Test Configuration
  • ss