Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mohido/keycloak_client
An abstraction over the functionalities provided by a keycloak client
https://github.com/mohido/keycloak_client
keycloak keycloak-spi node nodejs npm npm-package typescript
Last synced: 26 days ago
JSON representation
An abstraction over the functionalities provided by a keycloak client
- Host: GitHub
- URL: https://github.com/mohido/keycloak_client
- Owner: Mohido
- License: mit
- Created: 2022-07-25T01:41:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-08-05T19:59:02.000Z (over 2 years ago)
- Last Synced: 2024-10-09T13:19:39.460Z (about 1 month ago)
- Topics: keycloak, keycloak-spi, node, nodejs, npm, npm-package, typescript
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Keycloak-Client
This **Keycloak-Client** is an npm package responsible to handle the communication to a `keycloak` authentication server through one of the realm's clients. In any project, the developer can define 1+ clients, and use them to alter the realm or view some related data. Note: A `client` in keycloak terminology refers to an application representation inside the realm.# How to Build:
Building the source code to produce the package is quite straight forward:
* first make sure to have `node` and `npm` installed on your machine.
* on the root directory of the project, type the following commands in the terminal: `npm install`, then `npm run build`.
* the latter command will produce a new directory called `dist/` which encapsulates all the transpiled code (from typescript to javascript).
* the `dist/` folder can be coppied and used anywhere (It is a javascript module after all).# How to Use:
* First of all the package module must be integrated to the desired project. This can be done in two ways:
* 1) The developer may build the package from the source code, then copy the output folder (`dist/`) or its modules to their projects.
* 2) The developer download the package from the *npm registry* through the following command: `npm install mohido-keycloak-client`, or by adding the `mohido-keycloak-client` to the `package.json` file in their project (don't forget to run `npm install` afterwards ;)).
* After a successfull merging of the package modules, the developer may use the package directly as shown in the `tests/test1.js` file. The file encapsulates a simple use case of the *KeycloakClient` object.
* To initialize a `KeycloakClient` object, the developer must first create a keycloak connection object through the *keycloak-connect* package as shown in the code:```
const KeycloakConnect = require('keycloak-connect');
const {MemoryStore} = require('express-session');
const {KeycloakClientAPI} = require('../dist/index');const kc_config = {
'confidential-port': ,
'auth-server-url': ,
'resource': "",
'ssl-required': "",
'bearer-only': true,
realm:
};const memoryStore = new MemoryStore();
const keycloak = new KeycloakConnect({ store: memoryStore }, kc_config);
```
* The previous code illustrates the creation of a `KeycloakConnect` object to a keycloak server. After connecting successfully to a keycloak server, the developer may use the `KeycloakClient` class to create a client object. The `KeycloakClient` is defined in a `KeycloakClientAPI` namespace, thus, can be written as follows:
```
const some_cool_client = new KeycloakClientAPI.KeycloakClient(keycloak, , );
```# Requirements:
1) Make sure the given client has *direct access* mode enabled (can be done through the keycloak UI).
2) Some functionalities (e.g: `KeycloakClient.getUsers()`) depend on the roles assigned to the client. Therefore, the client must have a valid role to view the users in keycloak. Since this package is a lightweight package, it does not bother to check for client missconfigurations.