keycloak-api-manager 2.0.5 → 2.0.7

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.
@@ -79,7 +79,7 @@
79
79
  <option name="presentableId" value="Default" />
80
80
  <updated>1759849149064</updated>
81
81
  <workItem from="1759849150239" duration="1214000" />
82
- <workItem from="1759917554117" duration="56831000" />
82
+ <workItem from="1759917554117" duration="63852000" />
83
83
  </task>
84
84
  <servers />
85
85
  </component>
@@ -557,3 +557,4 @@ exports.updateCredentialLabel=function(){
557
557
  }
558
558
 
559
559
 
560
+
package/README.md CHANGED
@@ -100,7 +100,7 @@ await KeycloakManager.configure({
100
100
  username: 'admin', // Admin username
101
101
  password: 'admin', // Admin password
102
102
  grantType: 'password', // Type of authentication
103
- tokenLifeSpan: 120 // access_token Lifetime in seconds
103
+ tokenLifeSpan: 120 // access_token Lifetime in seconds
104
104
  });
105
105
 
106
106
 
@@ -185,13 +185,13 @@ Parameters:
185
185
  If this parameter is not provided, it will not be possible to use the administrative functions of Keycloak
186
186
  exposed by this adapter, so any attempt to call KeycloakManager.{function} will result in a runtime error due to access on an undefined object
187
187
  Main supported options:
188
+ - baseUrl: [required] Keycloak base Url
189
+ - realmName: [required] A String that specifies the realm to authenticate against, if different from the "keyCloakConfig.realm" parameter. If you intend to use Keycloak administrator credentials, this should be set to 'master'.
188
190
  - grantType: [required] The OAuth2 grant type used for authentication. example "password". Possible values: 'password', 'client_credentials', 'refresh_token', etc.
189
191
  - clientId: [required] string containing the client ID configured in Keycloak. Required for all grant types.
190
- - tokenLifeSpan: [required] Lifetime of an access token expressed in seconds. It indicates how often the access token should be renewed. If set incorrectly and the Keycloak token expires before the renewal interval defined by this parameter, errors and exceptions may occur
192
+ - tokenLifeSpan: [required] Numeric Lifetime of an access token expressed in seconds. It indicates how often the access token should be renewed. If set incorrectly and the Keycloak token expires before the renewal interval defined by this parameter, errors and exceptions may occur
191
193
  - username: [optional] string username. Required when using the password grant type.
192
194
  - password: [optional] string password. Required when using the password grant type.
193
- - baseUrl: [Optional] Keycloak base Url
194
- - realmName: [Optional] A String that specifies the realm to authenticate against, if different from the "keyCloakConfig.realm" parameter. If you intend to use Keycloak administrator credentials, this should be set to 'master'.
195
195
  - scope: [Optional] A string that specifies The OAuth2 scope requested during authentication (optional). Typically, not required for administrative clients. example:openid profile
196
196
  - requestOptions: [Optional] JSON parameters to configure HTTP requests (such as custom headers, timeouts, etc.). It is compatible with the Fetch API standard. Fetch request options https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
197
197
  - clientSecret: [Optional] string containing the client secret of the client. Required for client_credentials or confidential clients.
package/index.js CHANGED
@@ -1,13 +1,5 @@
1
1
  var express = require('express');
2
- var conf=require('./config').conf;
3
- var responseinterceptor = require('responseinterceptor');
4
- var Keycloak =require('keycloak-connect');
5
- var session=require('express-session');
6
- //const {default: KcAdminClient} = require("@keycloak/keycloak-admin-client");
7
2
  var keycloakAdminClient=require('@keycloak/keycloak-admin-client').default;
8
- var keycloak = null;
9
- var ready=false;
10
- var readyQueue=[];
11
3
  var kcAdminClient=null;
12
4
  var realmHandler=require('./Handlers/realmsHandler');
13
5
  var usersHandler=require('./Handlers/usersHandler');
@@ -18,7 +10,9 @@ var groupsHandler=require('./Handlers/groupsHandler');
18
10
  var rolesHandler=require('./Handlers/rolesHandler');
19
11
  var componentsHandler=require('./Handlers/componentsHandler');
20
12
  var authenticationManagementHandler=require('./Handlers/authenticationManagementHandler');
13
+ var request=require('request');
21
14
 
15
+ let configAdminclient=null;
22
16
 
23
17
  /**
24
18
  * ***************************** - ENGLISH - *******************************
@@ -44,12 +38,13 @@ var authenticationManagementHandler=require('./Handlers/authenticationManagement
44
38
  * - refreshToken: [Optional] string containing a valid refresh token to request a new access token when using the refresh_token grant type.
45
39
  */
46
40
  exports.configure=async function(adminClientCredentials){
47
- let configAdminclient={
41
+ configAdminclient={
48
42
  baseUrl:adminClientCredentials.baseUrl,
49
43
  realmName:adminClientCredentials.realmName
50
44
  }
45
+
51
46
  kcAdminClient= new keycloakAdminClient(configAdminclient);
52
- let tokenLifeSpan= adminClientCredentials.tokenLifeSpan *1000;
47
+ let tokenLifeSpan= (adminClientCredentials.tokenLifeSpan *1000)/2;
53
48
  delete adminClientCredentials.baseUrl;
54
49
  delete adminClientCredentials.realmName;
55
50
  delete adminClientCredentials.tokenLifeSpan;
@@ -96,6 +91,7 @@ exports.setConfig=function(configToOverride){
96
91
  return(kcAdminClient.setConfig(configToOverride));
97
92
  }
98
93
  //TODO: Remove da documentare
94
+ // restituisce il token utilizzato dalla libreria per comunicare con la keycloak API
99
95
  exports.getToken=function(configToOverride){
100
96
  return({
101
97
  accessToken:kcAdminClient.accessToken,
@@ -103,6 +99,27 @@ exports.getToken=function(configToOverride){
103
99
  });
104
100
  }
105
101
 
102
+ //TODO: Remove da documentare
103
+ //permette ad un utente o un client di autenticarsi su keycloack ed oottenere un token
104
+ exports.auth=async function(credentials){
105
+ let options={
106
+ url: `${configAdminclient.baseUrl}/realms/${configAdminclient.realmName}/protocol/openid-connect/token` ,
107
+ headers: {'Authorization': 'Bearer ' + kcAdminClient.accessToken},
108
+ contentType: 'application/www-form-urlencoded',
109
+ body: credentials
110
+ }
111
+
112
+ request.post(options, function (error, response, body) {
113
+ if(error){
114
+ console.log("Internal Server Error:", error);
115
+ }else{
116
+ return(body);
117
+ }
118
+ });
119
+ }
120
+
121
+
122
+
106
123
 
107
124
  /*
108
125
  <table><tbody>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keycloak-api-manager",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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": {
@@ -43,7 +43,6 @@
43
43
  ],
44
44
  "author": "aromanino (Crs4)",
45
45
  "license": "MIT",
46
- "devDependencies": {},
47
46
  "repository": {
48
47
  "type": "git",
49
48
  "url": "git+https://github.com/smartenv-crs4/keycloak-api-manager.git"