keycloak-api-manager 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -85,6 +85,16 @@ exports.configure=async function(adminClientCredentials){
85
85
  }
86
86
 
87
87
  kcAdminClient= new keycloakAdminClient(configAdminclient);
88
+ const originalSetRefreshToken = kcAdminClient.setRefreshToken?.bind(kcAdminClient);
89
+ if (originalSetRefreshToken) {
90
+ kcAdminClient.setRefreshToken = (token) => {
91
+ if (!token) {
92
+ kcAdminClient.refreshToken = undefined;
93
+ return;
94
+ }
95
+ return originalSetRefreshToken(token);
96
+ };
97
+ }
88
98
  configAdminclient.clientId=adminClientCredentials.clientId;
89
99
  configAdminclient.clientSecret=adminClientCredentials.clientSecret;
90
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keycloak-api-manager",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Keycloak-api-manager is a lightweight Node.js wrapper for the Keycloak Admin REST API. It provides an easy-to-use functional methods and functions to manage realms, users, roles, clients, groups, and permissions directly from your application code — just like you would from the Keycloak admin console.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,76 @@
1
+ const path = require('path');
2
+ const { expect } = require('chai');
3
+
4
+ process.env.NODE_ENV = process.env.NODE_ENV || 'test';
5
+ process.env.PROPERTIES_PATH = path.join(__dirname, '..', 'config');
6
+
7
+ const keycloakManager = require('keycloak-api-manager');
8
+ const { KEYCLOAK_CONFIG, TEST_CLIENT_ID, TEST_REALM } = require('../testConfig');
9
+
10
+ function buildConfig(overrides = {}) {
11
+ return {
12
+ ...KEYCLOAK_CONFIG,
13
+ ...overrides,
14
+ };
15
+ }
16
+
17
+ describe('Authentication - client_credentials grant', function () {
18
+ this.timeout(20000);
19
+
20
+ let testClientId = null;
21
+ let testClientSecret = null;
22
+
23
+ before(async function () {
24
+ const clients = await keycloakManager.clients.find({ clientId: TEST_CLIENT_ID });
25
+ const testClient = clients.find((client) => client.clientId === TEST_CLIENT_ID);
26
+
27
+ if (!testClient) {
28
+ this.skip();
29
+ return;
30
+ }
31
+
32
+ testClientId = testClient.clientId;
33
+ const secret = await keycloakManager.clients.getClientSecret({ id: testClient.id });
34
+ testClientSecret = secret?.value;
35
+
36
+ if (!testClientSecret) {
37
+ this.skip();
38
+ }
39
+ });
40
+
41
+ after(async function () {
42
+ if (!KEYCLOAK_CONFIG?.username || !KEYCLOAK_CONFIG?.password) {
43
+ return;
44
+ }
45
+
46
+ await keycloakManager.configure(
47
+ buildConfig({
48
+ grantType: KEYCLOAK_CONFIG.grantType || 'password',
49
+ tokenLifeSpan: KEYCLOAK_CONFIG.tokenLifeSpan || 60,
50
+ })
51
+ );
52
+ });
53
+
54
+ it('authenticates without refresh token errors', async function () {
55
+ if (!testClientId || !testClientSecret) {
56
+ this.skip();
57
+ return;
58
+ }
59
+
60
+ await keycloakManager.configure(
61
+ buildConfig({
62
+ realmName: TEST_REALM,
63
+ clientId: testClientId,
64
+ clientSecret: testClientSecret,
65
+ grantType: 'client_credentials',
66
+ tokenLifeSpan: 60,
67
+ username: undefined,
68
+ password: undefined,
69
+ })
70
+ );
71
+
72
+ const token = keycloakManager.getToken();
73
+ expect(token).to.have.property('accessToken');
74
+ expect(token.accessToken).to.be.a('string').and.to.have.length.greaterThan(0);
75
+ });
76
+ });