ef-keycloak-connect 1.8.3 → 1.8.4
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/package.json +1 -1
- package/services/keycloakService.js +179 -181
package/package.json
CHANGED
|
@@ -6,11 +6,9 @@ const qrcode = require( "qrcode" );
|
|
|
6
6
|
const speakeasy = require( 'speakeasy' )
|
|
7
7
|
const parseXMLString = require( "xml2js" ).parseString;
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
let requestController = require( "../controller/requestController.js" );
|
|
11
10
|
let memory = new session.MemoryStore();
|
|
12
11
|
|
|
13
|
-
let keycloakConfig = null;
|
|
14
12
|
let realmRoles = [];
|
|
15
13
|
let previousEvents = []; // Store complete events instead of just IDs
|
|
16
14
|
let isFirstRun = true;
|
|
@@ -32,11 +30,11 @@ class KeycloakService extends Keycloak {
|
|
|
32
30
|
|
|
33
31
|
constructor ( config ) {
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if ( keycloakConfig.TWILIO_SID && keycloakConfig.TWILIO_AUTH_TOKEN ) {
|
|
39
|
-
twilioClient = twilio( keycloakConfig.TWILIO_SID, keycloakConfig.TWILIO_AUTH_TOKEN )
|
|
33
|
+
super( { store: memory }, { ...config } ); //initialising keycloak-connect //Keycloak = new Keycloak({store: memory}, config);
|
|
34
|
+
this.keycloakConfig = { ...config };
|
|
35
|
+
|
|
36
|
+
if ( this.keycloakConfig.TWILIO_SID && this.keycloakConfig.TWILIO_AUTH_TOKEN ) {
|
|
37
|
+
twilioClient = twilio( this.keycloakConfig.TWILIO_SID, this.keycloakConfig.TWILIO_AUTH_TOKEN )
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -79,7 +77,7 @@ class KeycloakService extends Keycloak {
|
|
|
79
77
|
else return Promise.reject( { error: 404, error_message: 'Error occurred while generating QR code.' } )
|
|
80
78
|
|
|
81
79
|
// getting admin access token to update the user attributes
|
|
82
|
-
const adminData = await this.getAccessToken( keycloakConfig.USERNAME_ADMIN, keycloakConfig.PASSWORD_ADMIN )
|
|
80
|
+
const adminData = await this.getAccessToken( this.keycloakConfig.USERNAME_ADMIN, this.keycloakConfig.PASSWORD_ADMIN )
|
|
83
81
|
const adminToken = adminData.access_token
|
|
84
82
|
|
|
85
83
|
//updating user attributes for 2FA
|
|
@@ -141,7 +139,7 @@ class KeycloakService extends Keycloak {
|
|
|
141
139
|
|
|
142
140
|
return new Promise( async ( resolve, reject ) => {
|
|
143
141
|
|
|
144
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
142
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
145
143
|
|
|
146
144
|
let config = {
|
|
147
145
|
method: "post",
|
|
@@ -154,9 +152,9 @@ class KeycloakService extends Keycloak {
|
|
|
154
152
|
data: {
|
|
155
153
|
username: user_name,
|
|
156
154
|
password: user_password,
|
|
157
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
158
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
159
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
155
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
156
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
157
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
160
158
|
},
|
|
161
159
|
};
|
|
162
160
|
|
|
@@ -182,7 +180,7 @@ class KeycloakService extends Keycloak {
|
|
|
182
180
|
|
|
183
181
|
return new Promise( async ( resolve, reject ) => {
|
|
184
182
|
|
|
185
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
183
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
186
184
|
|
|
187
185
|
let config = {
|
|
188
186
|
method: "post",
|
|
@@ -196,10 +194,10 @@ class KeycloakService extends Keycloak {
|
|
|
196
194
|
data: {
|
|
197
195
|
username: user_name,
|
|
198
196
|
password: user_password,
|
|
199
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
200
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
197
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
198
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
201
199
|
grant_type: "urn:ietf:params:oauth:grant-type:uma-ticket",
|
|
202
|
-
audience: keycloakConfig.CLIENT_ID
|
|
200
|
+
audience: this.keycloakConfig.CLIENT_ID
|
|
203
201
|
},
|
|
204
202
|
};
|
|
205
203
|
|
|
@@ -225,7 +223,7 @@ class KeycloakService extends Keycloak {
|
|
|
225
223
|
|
|
226
224
|
return new Promise( async ( resolve, reject ) => {
|
|
227
225
|
|
|
228
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig[ "realm" ] + "/protocol/openid-connect/token/introspect";
|
|
226
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig[ "realm" ] + "/protocol/openid-connect/token/introspect";
|
|
229
227
|
|
|
230
228
|
let config = {
|
|
231
229
|
method: "post",
|
|
@@ -236,9 +234,9 @@ class KeycloakService extends Keycloak {
|
|
|
236
234
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
237
235
|
},
|
|
238
236
|
data: {
|
|
239
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
240
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
241
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
237
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
238
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
239
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
242
240
|
token: access_token
|
|
243
241
|
},
|
|
244
242
|
};
|
|
@@ -263,7 +261,7 @@ class KeycloakService extends Keycloak {
|
|
|
263
261
|
|
|
264
262
|
// function for getting user details (and extracting attributes)
|
|
265
263
|
async getUserDetails( adminToken, username ) {
|
|
266
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/users?username=" + username + "&exact=true";
|
|
264
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/users?username=" + username + "&exact=true";
|
|
267
265
|
let config = {
|
|
268
266
|
method: "get",
|
|
269
267
|
url: URL,
|
|
@@ -304,7 +302,7 @@ class KeycloakService extends Keycloak {
|
|
|
304
302
|
|
|
305
303
|
// function for updating user attributes in KeyCloak for 2FA registration
|
|
306
304
|
async updateUserAttributes( adminToken, userId, attributesToUpdate ) {
|
|
307
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/users/" + userId;
|
|
305
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/users/" + userId;
|
|
308
306
|
let config = {
|
|
309
307
|
method: "put",
|
|
310
308
|
url: URL,
|
|
@@ -340,7 +338,7 @@ class KeycloakService extends Keycloak {
|
|
|
340
338
|
|
|
341
339
|
let userObjectToBeReturned = { username: username }
|
|
342
340
|
|
|
343
|
-
const adminData = await this.getAccessToken( keycloakConfig.USERNAME_ADMIN, keycloakConfig.PASSWORD_ADMIN )
|
|
341
|
+
const adminData = await this.getAccessToken( this.keycloakConfig.USERNAME_ADMIN, this.keycloakConfig.PASSWORD_ADMIN )
|
|
344
342
|
const adminToken = adminData.access_token
|
|
345
343
|
|
|
346
344
|
let userObject = await this.getUserDetails( adminToken, username )
|
|
@@ -408,7 +406,7 @@ class KeycloakService extends Keycloak {
|
|
|
408
406
|
}
|
|
409
407
|
|
|
410
408
|
try {
|
|
411
|
-
await twilioClient.verify.v2.services( keycloakConfig.TWILIO_VERIFY_SID )
|
|
409
|
+
await twilioClient.verify.v2.services( this.keycloakConfig.TWILIO_VERIFY_SID )
|
|
412
410
|
.verifications
|
|
413
411
|
.create( { to: phoneNumber, channel: 'sms' } );
|
|
414
412
|
} catch ( error ) {
|
|
@@ -423,7 +421,7 @@ class KeycloakService extends Keycloak {
|
|
|
423
421
|
|
|
424
422
|
// function for validating OTP sent through authenticator app or SMS - (callable from frontend)
|
|
425
423
|
async validateOTP( username, password, realm, otpToValidate ) {
|
|
426
|
-
const adminData = await this.getAccessToken( keycloakConfig.USERNAME_ADMIN, keycloakConfig.PASSWORD_ADMIN )
|
|
424
|
+
const adminData = await this.getAccessToken( this.keycloakConfig.USERNAME_ADMIN, this.keycloakConfig.PASSWORD_ADMIN )
|
|
427
425
|
const adminToken = adminData.access_token
|
|
428
426
|
|
|
429
427
|
// getting user details for fetching attributes and otpSecret or OTP validation
|
|
@@ -464,7 +462,7 @@ class KeycloakService extends Keycloak {
|
|
|
464
462
|
// running OTP validation flow for SMS
|
|
465
463
|
else if ( userAttributes.twoFAChannel[ 0 ] == 'sms' ) {
|
|
466
464
|
try {
|
|
467
|
-
let verificationStatus = await twilioClient.verify.v2.services( keycloakConfig.TWILIO_VERIFY_SID )
|
|
465
|
+
let verificationStatus = await twilioClient.verify.v2.services( this.keycloakConfig.TWILIO_VERIFY_SID )
|
|
468
466
|
.verificationChecks
|
|
469
467
|
.create( { to: userAttributes.phoneNumber[ 0 ], code: otpToValidate } );
|
|
470
468
|
|
|
@@ -514,9 +512,9 @@ class KeycloakService extends Keycloak {
|
|
|
514
512
|
let error;
|
|
515
513
|
let responseObject;
|
|
516
514
|
|
|
517
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + realm_name + "/protocol/openid-connect/token";
|
|
515
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + realm_name + "/protocol/openid-connect/token";
|
|
518
516
|
|
|
519
|
-
//keycloakConfig["auth-server-url"] +'realms
|
|
517
|
+
//this.keycloakConfig["auth-server-url"] +'realms
|
|
520
518
|
let config = {
|
|
521
519
|
|
|
522
520
|
method: "post",
|
|
@@ -529,9 +527,9 @@ class KeycloakService extends Keycloak {
|
|
|
529
527
|
data: {
|
|
530
528
|
username: user_name,
|
|
531
529
|
password: user_password,
|
|
532
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
533
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
534
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
530
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
531
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
532
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
535
533
|
},
|
|
536
534
|
|
|
537
535
|
};
|
|
@@ -562,11 +560,11 @@ class KeycloakService extends Keycloak {
|
|
|
562
560
|
try {
|
|
563
561
|
|
|
564
562
|
let config1 = { ...config };
|
|
565
|
-
config1.data.username = keycloakConfig.USERNAME_ADMIN;
|
|
566
|
-
config1.data.password = keycloakConfig.PASSWORD_ADMIN;
|
|
563
|
+
config1.data.username = this.keycloakConfig.USERNAME_ADMIN;
|
|
564
|
+
config1.data.password = this.keycloakConfig.PASSWORD_ADMIN;
|
|
567
565
|
delete config1.data.token;
|
|
568
566
|
|
|
569
|
-
config1.url = keycloakConfig[ "auth-server-url" ] + "realms/" + realm_name + "/protocol/openid-connect/token";
|
|
567
|
+
config1.url = this.keycloakConfig[ "auth-server-url" ] + "realms/" + realm_name + "/protocol/openid-connect/token";
|
|
570
568
|
|
|
571
569
|
let adminTokenResponse = await requestController.httpRequest( config1, true );
|
|
572
570
|
|
|
@@ -578,7 +576,7 @@ class KeycloakService extends Keycloak {
|
|
|
578
576
|
|
|
579
577
|
config1.headers.Authorization = "Bearer " + admin_token;
|
|
580
578
|
config1.method = "get";
|
|
581
|
-
config1.url = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + realm_name + "/users?username=" + user_name + "&exact=true";
|
|
579
|
+
config1.url = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + realm_name + "/users?username=" + user_name + "&exact=true";
|
|
582
580
|
delete config1.data;
|
|
583
581
|
|
|
584
582
|
let getuserDetails = await requestController.httpRequest( config1, true );
|
|
@@ -685,15 +683,15 @@ class KeycloakService extends Keycloak {
|
|
|
685
683
|
data: {
|
|
686
684
|
username: user_name,
|
|
687
685
|
password: user_password,
|
|
688
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
689
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
690
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
686
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
687
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
688
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
691
689
|
},
|
|
692
690
|
|
|
693
691
|
};
|
|
694
692
|
|
|
695
693
|
config.data.grant_type = "urn:ietf:params:oauth:grant-type:uma-ticket";
|
|
696
|
-
config.data.audience = keycloakConfig.CLIENT_ID;
|
|
694
|
+
config.data.audience = this.keycloakConfig.CLIENT_ID;
|
|
697
695
|
config.headers.Authorization = "Bearer " + token;
|
|
698
696
|
|
|
699
697
|
// T.O.K.E.N R.E.Q.U.E.S.T # 2 (A.C.C.E.S.S T.O.K.E.N W.I.T.H P.E.R.M.I.S.S.I.O.N.S)
|
|
@@ -706,7 +704,7 @@ class KeycloakService extends Keycloak {
|
|
|
706
704
|
refresh_token = rptResponse.data.refresh_token;
|
|
707
705
|
|
|
708
706
|
let userToken = token;
|
|
709
|
-
config.data.grant_type = keycloakConfig.GRANT_TYPE;
|
|
707
|
+
config.data.grant_type = this.keycloakConfig.GRANT_TYPE;
|
|
710
708
|
config.data.token = token;
|
|
711
709
|
URL = URL + "/introspect";
|
|
712
710
|
config.url = URL;
|
|
@@ -940,7 +938,7 @@ class KeycloakService extends Keycloak {
|
|
|
940
938
|
|
|
941
939
|
return new Promise( async ( resolve, reject ) => {
|
|
942
940
|
|
|
943
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token/introspect";
|
|
941
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token/introspect";
|
|
944
942
|
|
|
945
943
|
let config = {
|
|
946
944
|
|
|
@@ -953,8 +951,8 @@ class KeycloakService extends Keycloak {
|
|
|
953
951
|
},
|
|
954
952
|
data: {
|
|
955
953
|
username: username,
|
|
956
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
957
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
954
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
955
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
958
956
|
token: token,
|
|
959
957
|
},
|
|
960
958
|
|
|
@@ -997,7 +995,7 @@ class KeycloakService extends Keycloak {
|
|
|
997
995
|
|
|
998
996
|
return new Promise( async ( resolve, reject ) => {
|
|
999
997
|
|
|
1000
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/clients?clientId=" + keycloakConfig[ "CLIENT_ID" ];
|
|
998
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/clients?clientId=" + this.keycloakConfig[ "CLIENT_ID" ];
|
|
1001
999
|
|
|
1002
1000
|
let config = {
|
|
1003
1001
|
method: "get",
|
|
@@ -1034,11 +1032,11 @@ class KeycloakService extends Keycloak {
|
|
|
1034
1032
|
} );
|
|
1035
1033
|
}
|
|
1036
1034
|
|
|
1037
|
-
createResource( resource_name, resource_scope = keycloakConfig.SCOPE_NAME ) {
|
|
1035
|
+
createResource( resource_name, resource_scope = this.keycloakConfig.SCOPE_NAME ) {
|
|
1038
1036
|
|
|
1039
1037
|
return new Promise( async ( resolve, reject ) => {
|
|
1040
1038
|
|
|
1041
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1039
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1042
1040
|
|
|
1043
1041
|
let config = {
|
|
1044
1042
|
|
|
@@ -1050,9 +1048,9 @@ class KeycloakService extends Keycloak {
|
|
|
1050
1048
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1051
1049
|
},
|
|
1052
1050
|
data: {
|
|
1053
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1054
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1055
|
-
grant_type: keycloakConfig.GRANT_TYPE_PAT,
|
|
1051
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1052
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1053
|
+
grant_type: this.keycloakConfig.GRANT_TYPE_PAT,
|
|
1056
1054
|
},
|
|
1057
1055
|
|
|
1058
1056
|
};
|
|
@@ -1074,7 +1072,7 @@ class KeycloakService extends Keycloak {
|
|
|
1074
1072
|
config.data._id = resource_name;
|
|
1075
1073
|
config.data.resource_scopes = [ resource_scope ];
|
|
1076
1074
|
|
|
1077
|
-
config.url = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/authz/protection/resource_set";
|
|
1075
|
+
config.url = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/authz/protection/resource_set";
|
|
1078
1076
|
config.headers.Authorization = "Bearer " + token;
|
|
1079
1077
|
config.headers[ "Content-Type" ] = "application/json";
|
|
1080
1078
|
|
|
@@ -1117,7 +1115,7 @@ class KeycloakService extends Keycloak {
|
|
|
1117
1115
|
return new Promise( async ( resolve, reject ) => {
|
|
1118
1116
|
|
|
1119
1117
|
let token;
|
|
1120
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1118
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1121
1119
|
|
|
1122
1120
|
let config = {
|
|
1123
1121
|
|
|
@@ -1129,9 +1127,9 @@ class KeycloakService extends Keycloak {
|
|
|
1129
1127
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1130
1128
|
},
|
|
1131
1129
|
data: {
|
|
1132
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1133
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1134
|
-
grant_type: keycloakConfig.GRANT_TYPE_PAT,
|
|
1130
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1131
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1132
|
+
grant_type: this.keycloakConfig.GRANT_TYPE_PAT,
|
|
1135
1133
|
},
|
|
1136
1134
|
|
|
1137
1135
|
};
|
|
@@ -1145,7 +1143,7 @@ class KeycloakService extends Keycloak {
|
|
|
1145
1143
|
|
|
1146
1144
|
token = patToken.data.access_token;
|
|
1147
1145
|
// D.E.L.E.T.E R.E.S.O.U.R.C.E A.N.D P.E.R.M.I.S.S.I.O.N R.E.Q.U.E.S.T
|
|
1148
|
-
let URL1 = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/authz/protection/resource_set/" + resource_name;
|
|
1146
|
+
let URL1 = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/authz/protection/resource_set/" + resource_name;
|
|
1149
1147
|
|
|
1150
1148
|
config.url = URL1;
|
|
1151
1149
|
config.method = "delete";
|
|
@@ -1162,11 +1160,11 @@ class KeycloakService extends Keycloak {
|
|
|
1162
1160
|
config.method = "post";
|
|
1163
1161
|
config.url = URL;
|
|
1164
1162
|
delete config.headers[ "Authorization" ];
|
|
1165
|
-
config.data.client_id = keycloakConfig.CLIENT_ID;
|
|
1166
|
-
config.data.username = keycloakConfig.USERNAME_ADMIN;
|
|
1167
|
-
config.data.password = keycloakConfig.PASSWORD_ADMIN;
|
|
1168
|
-
config.data.grant_type = keycloakConfig.GRANT_TYPE;
|
|
1169
|
-
config.data.client_secret = keycloakConfig.credentials.secret;
|
|
1163
|
+
config.data.client_id = this.keycloakConfig.CLIENT_ID;
|
|
1164
|
+
config.data.username = this.keycloakConfig.USERNAME_ADMIN;
|
|
1165
|
+
config.data.password = this.keycloakConfig.PASSWORD_ADMIN;
|
|
1166
|
+
config.data.grant_type = this.keycloakConfig.GRANT_TYPE;
|
|
1167
|
+
config.data.client_secret = this.keycloakConfig.credentials.secret;
|
|
1170
1168
|
|
|
1171
1169
|
try {
|
|
1172
1170
|
|
|
@@ -1176,7 +1174,7 @@ class KeycloakService extends Keycloak {
|
|
|
1176
1174
|
// now deleting policy
|
|
1177
1175
|
config.method = "delete";
|
|
1178
1176
|
delete config.data;
|
|
1179
|
-
let URL6 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/clients/" + keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/user/" + resource_name + "-policy";
|
|
1177
|
+
let URL6 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/clients/" + this.keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/user/" + resource_name + "-policy";
|
|
1180
1178
|
config.url = URL6;
|
|
1181
1179
|
|
|
1182
1180
|
delete config.headers[ "Accept" ];
|
|
@@ -1242,7 +1240,7 @@ class KeycloakService extends Keycloak {
|
|
|
1242
1240
|
return new Promise( async ( resolve, reject ) => {
|
|
1243
1241
|
|
|
1244
1242
|
|
|
1245
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/clients/" + clientId + "/authz/resource-server/policy?name=" + policyName + "&exact=true";
|
|
1243
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/clients/" + clientId + "/authz/resource-server/policy?name=" + policyName + "&exact=true";
|
|
1246
1244
|
|
|
1247
1245
|
let config = {
|
|
1248
1246
|
|
|
@@ -1288,7 +1286,7 @@ class KeycloakService extends Keycloak {
|
|
|
1288
1286
|
return new Promise( async ( resolve, reject ) => {
|
|
1289
1287
|
|
|
1290
1288
|
let token;
|
|
1291
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1289
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1292
1290
|
|
|
1293
1291
|
let config = {
|
|
1294
1292
|
|
|
@@ -1300,11 +1298,11 @@ class KeycloakService extends Keycloak {
|
|
|
1300
1298
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1301
1299
|
},
|
|
1302
1300
|
data: {
|
|
1303
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1304
|
-
username: keycloakConfig.USERNAME_ADMIN,
|
|
1305
|
-
password: keycloakConfig.PASSWORD_ADMIN,
|
|
1306
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
1307
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1301
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1302
|
+
username: this.keycloakConfig.USERNAME_ADMIN,
|
|
1303
|
+
password: this.keycloakConfig.PASSWORD_ADMIN,
|
|
1304
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
1305
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1308
1306
|
},
|
|
1309
1307
|
|
|
1310
1308
|
};
|
|
@@ -1316,7 +1314,7 @@ class KeycloakService extends Keycloak {
|
|
|
1316
1314
|
|
|
1317
1315
|
// T.O.K.E.N R.E.Q.U.E.S.T (user with admin is already defined in keycloak with roles 'realm-management')
|
|
1318
1316
|
// // C.R.E.A.T.E U.S.E.R B.A.S.E.D P.O.L.I.C.Y
|
|
1319
|
-
let URL3 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/clients/" + keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/role";
|
|
1317
|
+
let URL3 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/clients/" + this.keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/role";
|
|
1320
1318
|
config.url = URL3;
|
|
1321
1319
|
config.headers[ "Content-Type" ] = "application/json";
|
|
1322
1320
|
config.headers.Authorization = "Bearer " + token;
|
|
@@ -1370,7 +1368,7 @@ class KeycloakService extends Keycloak {
|
|
|
1370
1368
|
|
|
1371
1369
|
|
|
1372
1370
|
let policyId = policyObj.id;
|
|
1373
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/clients/" + clientId + "/authz/resource-server/policy/user/" + policyId;
|
|
1371
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/clients/" + clientId + "/authz/resource-server/policy/user/" + policyId;
|
|
1374
1372
|
|
|
1375
1373
|
delete policyObj.id;
|
|
1376
1374
|
|
|
@@ -1417,7 +1415,7 @@ class KeycloakService extends Keycloak {
|
|
|
1417
1415
|
return new Promise( async ( resolve, reject ) => {
|
|
1418
1416
|
|
|
1419
1417
|
let token;
|
|
1420
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1418
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1421
1419
|
|
|
1422
1420
|
let config = {
|
|
1423
1421
|
|
|
@@ -1429,11 +1427,11 @@ class KeycloakService extends Keycloak {
|
|
|
1429
1427
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1430
1428
|
},
|
|
1431
1429
|
data: {
|
|
1432
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1433
|
-
username: keycloakConfig.USERNAME_ADMIN,
|
|
1434
|
-
password: keycloakConfig.PASSWORD_ADMIN,
|
|
1435
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
1436
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1430
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1431
|
+
username: this.keycloakConfig.USERNAME_ADMIN,
|
|
1432
|
+
password: this.keycloakConfig.PASSWORD_ADMIN,
|
|
1433
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
1434
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1437
1435
|
},
|
|
1438
1436
|
|
|
1439
1437
|
};
|
|
@@ -1445,7 +1443,7 @@ class KeycloakService extends Keycloak {
|
|
|
1445
1443
|
|
|
1446
1444
|
// T.O.K.E.N R.E.Q.U.E.S.T (user with admin is already defined in keycloak with roles 'realm-management')
|
|
1447
1445
|
// // C.R.E.A.T.E U.S.E.R B.A.S.E.D P.O.L.I.C.Y
|
|
1448
|
-
let URL3 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/clients/" + keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/permission/scope";
|
|
1446
|
+
let URL3 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/clients/" + this.keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/permission/scope";
|
|
1449
1447
|
config.url = URL3;
|
|
1450
1448
|
config.headers[ "Content-Type" ] = "application/json";
|
|
1451
1449
|
config.headers.Authorization = "Bearer " + token;
|
|
@@ -1512,11 +1510,11 @@ class KeycloakService extends Keycloak {
|
|
|
1512
1510
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1513
1511
|
},
|
|
1514
1512
|
data: {
|
|
1515
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1516
|
-
username: keycloakConfig.USERNAME_ADMIN,
|
|
1517
|
-
password: keycloakConfig.PASSWORD_ADMIN,
|
|
1518
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
1519
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1513
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1514
|
+
username: this.keycloakConfig.USERNAME_ADMIN,
|
|
1515
|
+
password: this.keycloakConfig.PASSWORD_ADMIN,
|
|
1516
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
1517
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1520
1518
|
},
|
|
1521
1519
|
|
|
1522
1520
|
};
|
|
@@ -1529,11 +1527,11 @@ class KeycloakService extends Keycloak {
|
|
|
1529
1527
|
// EVALUATION REQUEST
|
|
1530
1528
|
let data = JSON.stringify( {
|
|
1531
1529
|
resources: [ { _id: resource_name } ],
|
|
1532
|
-
clientId: keycloakConfig.CLIENT_DB_ID,
|
|
1530
|
+
clientId: this.keycloakConfig.CLIENT_DB_ID,
|
|
1533
1531
|
userId: keycloak_user_id,
|
|
1534
1532
|
} );
|
|
1535
1533
|
|
|
1536
|
-
config.data.clientId = keycloakConfig.CLIENT_DB_ID;
|
|
1534
|
+
config.data.clientId = this.keycloakConfig.CLIENT_DB_ID;
|
|
1537
1535
|
config.data.resources = [ { _id: resource_name } ];
|
|
1538
1536
|
config.data.userId = keycloak_user_id;
|
|
1539
1537
|
delete config.data[ "username" ];
|
|
@@ -1542,7 +1540,7 @@ class KeycloakService extends Keycloak {
|
|
|
1542
1540
|
delete config.data[ "client_secret" ];
|
|
1543
1541
|
delete config.data[ "client_id" ];
|
|
1544
1542
|
|
|
1545
|
-
let URL5 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/clients/" + keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/evaluate";
|
|
1543
|
+
let URL5 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/clients/" + this.keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/evaluate";
|
|
1546
1544
|
config.url = URL5;
|
|
1547
1545
|
config.headers[ "Content-Type" ] = "application/json";
|
|
1548
1546
|
( config.headers.Authorization = "Bearer " + token ), ( config.data = JSON.stringify( config.data ) );
|
|
@@ -1591,11 +1589,11 @@ class KeycloakService extends Keycloak {
|
|
|
1591
1589
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1592
1590
|
},
|
|
1593
1591
|
data: {
|
|
1594
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1595
|
-
username: keycloakConfig.USERNAME_ADMIN,
|
|
1596
|
-
password: keycloakConfig.PASSWORD_ADMIN,
|
|
1597
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
1598
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1592
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1593
|
+
username: this.keycloakConfig.USERNAME_ADMIN,
|
|
1594
|
+
password: this.keycloakConfig.PASSWORD_ADMIN,
|
|
1595
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
1596
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1599
1597
|
},
|
|
1600
1598
|
};
|
|
1601
1599
|
|
|
@@ -1606,7 +1604,7 @@ class KeycloakService extends Keycloak {
|
|
|
1606
1604
|
// now deleting policy
|
|
1607
1605
|
config.method = "delete";
|
|
1608
1606
|
delete config.data;
|
|
1609
|
-
let URL6 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/clients/" + keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/user/" + resource_name + "-policy";
|
|
1607
|
+
let URL6 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/clients/" + this.keycloakConfig.CLIENT_DB_ID + "/authz/resource-server/policy/user/" + resource_name + "-policy";
|
|
1610
1608
|
config.url = URL6;
|
|
1611
1609
|
delete config.headers[ "Accept" ];
|
|
1612
1610
|
delete config.headers[ "cache-control" ];
|
|
@@ -1661,7 +1659,7 @@ class KeycloakService extends Keycloak {
|
|
|
1661
1659
|
try {
|
|
1662
1660
|
|
|
1663
1661
|
// User Groups
|
|
1664
|
-
let URL = keycloakConfig[ "ef-server-url" ] + "team/user/" + userId;
|
|
1662
|
+
let URL = this.keycloakConfig[ "ef-server-url" ] + "team/user/" + userId;
|
|
1665
1663
|
config.url = URL;
|
|
1666
1664
|
|
|
1667
1665
|
try {
|
|
@@ -1692,7 +1690,7 @@ class KeycloakService extends Keycloak {
|
|
|
1692
1690
|
}
|
|
1693
1691
|
|
|
1694
1692
|
// User Groups from Keycloak
|
|
1695
|
-
let URL1 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/users/" + userId + "/groups";
|
|
1693
|
+
let URL1 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/users/" + userId + "/groups";
|
|
1696
1694
|
config.url = URL1;
|
|
1697
1695
|
config.headers.Authorization = "Bearer " + adminToken;
|
|
1698
1696
|
|
|
@@ -1743,7 +1741,7 @@ class KeycloakService extends Keycloak {
|
|
|
1743
1741
|
|
|
1744
1742
|
let token;
|
|
1745
1743
|
let message;
|
|
1746
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1744
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1747
1745
|
|
|
1748
1746
|
|
|
1749
1747
|
|
|
@@ -1787,11 +1785,11 @@ class KeycloakService extends Keycloak {
|
|
|
1787
1785
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1788
1786
|
},
|
|
1789
1787
|
data: {
|
|
1790
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1791
|
-
username: keycloakConfig.USERNAME_ADMIN,
|
|
1792
|
-
password: keycloakConfig.PASSWORD_ADMIN,
|
|
1793
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
1794
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1788
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1789
|
+
username: this.keycloakConfig.USERNAME_ADMIN,
|
|
1790
|
+
password: this.keycloakConfig.PASSWORD_ADMIN,
|
|
1791
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
1792
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1795
1793
|
},
|
|
1796
1794
|
|
|
1797
1795
|
};
|
|
@@ -1819,7 +1817,7 @@ class KeycloakService extends Keycloak {
|
|
|
1819
1817
|
//admin case
|
|
1820
1818
|
if ( "realm-management" in clientRoles ) {
|
|
1821
1819
|
|
|
1822
|
-
let URL2 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/groups";
|
|
1820
|
+
let URL2 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/groups";
|
|
1823
1821
|
config.url = URL2;
|
|
1824
1822
|
|
|
1825
1823
|
try {
|
|
@@ -1891,7 +1889,7 @@ class KeycloakService extends Keycloak {
|
|
|
1891
1889
|
}
|
|
1892
1890
|
}
|
|
1893
1891
|
|
|
1894
|
-
allUsers = await teamsService.getUsersOfGroups( groupsData, config, keycloakConfig );
|
|
1892
|
+
allUsers = await teamsService.getUsersOfGroups( groupsData, config, this.keycloakConfig );
|
|
1895
1893
|
resolve( allUsers );
|
|
1896
1894
|
|
|
1897
1895
|
} catch ( er ) {
|
|
@@ -1928,7 +1926,7 @@ class KeycloakService extends Keycloak {
|
|
|
1928
1926
|
|
|
1929
1927
|
let token;
|
|
1930
1928
|
let groupsData = [];
|
|
1931
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1929
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
1932
1930
|
|
|
1933
1931
|
let config = {
|
|
1934
1932
|
|
|
@@ -1940,11 +1938,11 @@ class KeycloakService extends Keycloak {
|
|
|
1940
1938
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
1941
1939
|
},
|
|
1942
1940
|
data: {
|
|
1943
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
1944
|
-
username: keycloakConfig.USERNAME_ADMIN,
|
|
1945
|
-
password: keycloakConfig.PASSWORD_ADMIN,
|
|
1946
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
1947
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
1941
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
1942
|
+
username: this.keycloakConfig.USERNAME_ADMIN,
|
|
1943
|
+
password: this.keycloakConfig.PASSWORD_ADMIN,
|
|
1944
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
1945
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
1948
1946
|
},
|
|
1949
1947
|
|
|
1950
1948
|
};
|
|
@@ -1967,7 +1965,7 @@ class KeycloakService extends Keycloak {
|
|
|
1967
1965
|
|
|
1968
1966
|
let groupData = {};
|
|
1969
1967
|
|
|
1970
|
-
let URL2 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/groups/" + groupIds[ i ] + "/";
|
|
1968
|
+
let URL2 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/groups/" + groupIds[ i ] + "/";
|
|
1971
1969
|
config.url = URL2;
|
|
1972
1970
|
let groupInfo = await requestController.httpRequest( config, true );
|
|
1973
1971
|
|
|
@@ -1988,7 +1986,7 @@ class KeycloakService extends Keycloak {
|
|
|
1988
1986
|
|
|
1989
1987
|
for ( let j = 0; j < supervisorList.length; j++ ) {
|
|
1990
1988
|
|
|
1991
|
-
let URL3 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/users?username=" + supervisorList[ j ] + "&exact=true";
|
|
1989
|
+
let URL3 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/users?username=" + supervisorList[ j ] + "&exact=true";
|
|
1992
1990
|
config.url = URL3;
|
|
1993
1991
|
|
|
1994
1992
|
try {
|
|
@@ -2019,7 +2017,7 @@ class KeycloakService extends Keycloak {
|
|
|
2019
2017
|
}
|
|
2020
2018
|
}
|
|
2021
2019
|
|
|
2022
|
-
let URL4 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/groups/" + groupIds[ i ] + "/members";
|
|
2020
|
+
let URL4 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/groups/" + groupIds[ i ] + "/members";
|
|
2023
2021
|
config.url = URL4;
|
|
2024
2022
|
let users = await requestController.httpRequest( config, true );
|
|
2025
2023
|
|
|
@@ -2106,7 +2104,7 @@ class KeycloakService extends Keycloak {
|
|
|
2106
2104
|
try {
|
|
2107
2105
|
|
|
2108
2106
|
//Fetching admin token, we pass it in our "Create User" API for authorization
|
|
2109
|
-
let keycloakAuthToken = await this.getAccessToken( keycloakConfig[ "USERNAME_ADMIN" ], keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
2107
|
+
let keycloakAuthToken = await this.getAccessToken( this.keycloakConfig[ "USERNAME_ADMIN" ], this.keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
2110
2108
|
|
|
2111
2109
|
if ( keycloakAuthToken.access_token ) {
|
|
2112
2110
|
|
|
@@ -2131,7 +2129,7 @@ class KeycloakService extends Keycloak {
|
|
|
2131
2129
|
|
|
2132
2130
|
try {
|
|
2133
2131
|
|
|
2134
|
-
config.url = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig.realm + "/roles/" + keycloak_roles[ i ] + "/users?max=100000";
|
|
2132
|
+
config.url = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig.realm + "/roles/" + keycloak_roles[ i ] + "/users?max=100000";
|
|
2135
2133
|
let getUsersfromRoles = await requestController.httpRequest( config, true );
|
|
2136
2134
|
userObject = getUsersfromRoles.data;
|
|
2137
2135
|
|
|
@@ -2199,7 +2197,7 @@ class KeycloakService extends Keycloak {
|
|
|
2199
2197
|
|
|
2200
2198
|
return new Promise( async ( resolve, reject ) => {
|
|
2201
2199
|
|
|
2202
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2200
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/roles`;
|
|
2203
2201
|
|
|
2204
2202
|
let config = {
|
|
2205
2203
|
method: "get",
|
|
@@ -2232,7 +2230,7 @@ class KeycloakService extends Keycloak {
|
|
|
2232
2230
|
|
|
2233
2231
|
return new Promise( async ( resolve, reject ) => {
|
|
2234
2232
|
|
|
2235
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2233
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/users/${userId}/role-mappings/realm`;
|
|
2236
2234
|
|
|
2237
2235
|
let config = {
|
|
2238
2236
|
method: "post",
|
|
@@ -2266,7 +2264,7 @@ class KeycloakService extends Keycloak {
|
|
|
2266
2264
|
|
|
2267
2265
|
return new Promise( async ( resolve, reject ) => {
|
|
2268
2266
|
|
|
2269
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2267
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/users/${userId}/groups/`;
|
|
2270
2268
|
|
|
2271
2269
|
let config = {
|
|
2272
2270
|
method: "get",
|
|
@@ -2305,7 +2303,7 @@ class KeycloakService extends Keycloak {
|
|
|
2305
2303
|
|
|
2306
2304
|
for ( let name of groupNames ) {
|
|
2307
2305
|
|
|
2308
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2306
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/groups?search=${name}`;
|
|
2309
2307
|
|
|
2310
2308
|
let config = {
|
|
2311
2309
|
method: "get",
|
|
@@ -2360,7 +2358,7 @@ class KeycloakService extends Keycloak {
|
|
|
2360
2358
|
|
|
2361
2359
|
return new Promise( async ( resolve, reject ) => {
|
|
2362
2360
|
|
|
2363
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2361
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/groups/${groupId}/`;
|
|
2364
2362
|
|
|
2365
2363
|
let config = {
|
|
2366
2364
|
method: "get",
|
|
@@ -2408,13 +2406,13 @@ class KeycloakService extends Keycloak {
|
|
|
2408
2406
|
|
|
2409
2407
|
for ( let group of groups ) {
|
|
2410
2408
|
|
|
2411
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2409
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/users/${userId}/groups/${group.id}`;
|
|
2412
2410
|
config.url = URL;
|
|
2413
2411
|
|
|
2414
2412
|
if ( method == 'put' ) {
|
|
2415
2413
|
|
|
2416
2414
|
config.data = {
|
|
2417
|
-
realm: keycloakConfig[ "realm" ],
|
|
2415
|
+
realm: this.keycloakConfig[ "realm" ],
|
|
2418
2416
|
userId: userId,
|
|
2419
2417
|
groupId: group.id
|
|
2420
2418
|
}
|
|
@@ -2466,7 +2464,7 @@ class KeycloakService extends Keycloak {
|
|
|
2466
2464
|
|
|
2467
2465
|
let rolesArr = realmRoles.filter( role => roles.includes( role.name ) );
|
|
2468
2466
|
|
|
2469
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2467
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/users/${userId}/role-mappings/realm`;
|
|
2470
2468
|
|
|
2471
2469
|
|
|
2472
2470
|
let config = {
|
|
@@ -2501,7 +2499,7 @@ class KeycloakService extends Keycloak {
|
|
|
2501
2499
|
|
|
2502
2500
|
return new Promise( async ( resolve, reject ) => {
|
|
2503
2501
|
|
|
2504
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2502
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/groups`;
|
|
2505
2503
|
|
|
2506
2504
|
let data = {
|
|
2507
2505
|
name: groupName,
|
|
@@ -2569,14 +2567,14 @@ class KeycloakService extends Keycloak {
|
|
|
2569
2567
|
try {
|
|
2570
2568
|
|
|
2571
2569
|
//Fetching admin token, we pass it in our "Create User" API for authorization
|
|
2572
|
-
keycloakAdminToken = await this.getAccessToken( keycloakConfig[ "USERNAME_ADMIN" ], keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
2570
|
+
keycloakAdminToken = await this.getAccessToken( this.keycloakConfig[ "USERNAME_ADMIN" ], this.keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
2573
2571
|
|
|
2574
2572
|
try {
|
|
2575
2573
|
|
|
2576
2574
|
//Checking whether finesse password is updated or not. If updated, update it on keycloak as well without halting login process
|
|
2577
2575
|
await this.checkPasswordUpdate( keycloakAdminToken.access_token, finesseLoginResponse.data.username, password );
|
|
2578
2576
|
//Checking whether finesse user already exist in keycloak and fetch its token
|
|
2579
|
-
keycloakAuthToken = await this.getAccessToken( finesseLoginResponse.data.username, password, keycloakConfig[ "realm" ] );
|
|
2577
|
+
keycloakAuthToken = await this.getAccessToken( finesseLoginResponse.data.username, password, this.keycloakConfig[ "realm" ] );
|
|
2580
2578
|
authenticatedByKeycloak = true;
|
|
2581
2579
|
|
|
2582
2580
|
if ( !updateUserPromise ) {
|
|
@@ -2585,7 +2583,7 @@ class KeycloakService extends Keycloak {
|
|
|
2585
2583
|
.then( async ( updatedUser ) => {
|
|
2586
2584
|
|
|
2587
2585
|
//Calling the Introspect function twice so all the asynchronous operations inside updateUser function are done
|
|
2588
|
-
keycloakAuthToken = await this.getKeycloakTokenWithIntrospect( finesseLoginResponse.data.username, password, keycloakConfig[ "realm" ], 'CISCO' );
|
|
2586
|
+
keycloakAuthToken = await this.getKeycloakTokenWithIntrospect( finesseLoginResponse.data.username, password, this.keycloakConfig[ "realm" ], 'CISCO' );
|
|
2589
2587
|
} )
|
|
2590
2588
|
.catch( ( err ) => {
|
|
2591
2589
|
|
|
@@ -2656,7 +2654,7 @@ class KeycloakService extends Keycloak {
|
|
|
2656
2654
|
if ( userCreated.status == 201 ) {
|
|
2657
2655
|
|
|
2658
2656
|
//Returning the token of recently created User
|
|
2659
|
-
keycloakAuthToken = await this.getKeycloakTokenWithIntrospect( ( finesseLoginResponse.data.username ).toLowerCase(), password, keycloakConfig[ "realm" ], 'CISCO' );
|
|
2657
|
+
keycloakAuthToken = await this.getKeycloakTokenWithIntrospect( ( finesseLoginResponse.data.username ).toLowerCase(), password, this.keycloakConfig[ "realm" ], 'CISCO' );
|
|
2660
2658
|
}
|
|
2661
2659
|
|
|
2662
2660
|
} catch ( err ) {
|
|
@@ -2702,7 +2700,7 @@ class KeycloakService extends Keycloak {
|
|
|
2702
2700
|
|
|
2703
2701
|
return new Promise( async ( resolve, reject ) => {
|
|
2704
2702
|
|
|
2705
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}
|
|
2703
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${this.keycloakConfig[ "realm" ]}/users`;
|
|
2706
2704
|
|
|
2707
2705
|
let data = {
|
|
2708
2706
|
|
|
@@ -2800,7 +2798,7 @@ class KeycloakService extends Keycloak {
|
|
|
2800
2798
|
let ciscoTeamId = userObject.group.id;
|
|
2801
2799
|
|
|
2802
2800
|
//Check whether team of Agent already exists in CX Core or not
|
|
2803
|
-
let URL1 = `${keycloakConfig[ "ef-server-url" ]}team?ids=${ciscoTeamId}`;
|
|
2801
|
+
let URL1 = `${this.keycloakConfig[ "ef-server-url" ]}team?ids=${ciscoTeamId}`;
|
|
2804
2802
|
|
|
2805
2803
|
let config1 = {
|
|
2806
2804
|
|
|
@@ -2836,7 +2834,7 @@ class KeycloakService extends Keycloak {
|
|
|
2836
2834
|
if ( getAgentCXTeam.data.length == 0 ) {
|
|
2837
2835
|
|
|
2838
2836
|
//Setting URL to Create CX team of Agent
|
|
2839
|
-
let URL2 = `${keycloakConfig[ "ef-server-url" ]}team`;
|
|
2837
|
+
let URL2 = `${this.keycloakConfig[ "ef-server-url" ]}team`;
|
|
2840
2838
|
|
|
2841
2839
|
let data = {
|
|
2842
2840
|
"team_Id": userObject.group.id,
|
|
@@ -2868,7 +2866,7 @@ class KeycloakService extends Keycloak {
|
|
|
2868
2866
|
}
|
|
2869
2867
|
|
|
2870
2868
|
//First send the newly created user to CX DB.
|
|
2871
|
-
let URL3 = `${keycloakConfig[ "ef-server-url" ]}users/`;
|
|
2869
|
+
let URL3 = `${this.keycloakConfig[ "ef-server-url" ]}users/`;
|
|
2872
2870
|
|
|
2873
2871
|
let data = {
|
|
2874
2872
|
"id": userId,
|
|
@@ -2897,7 +2895,7 @@ class KeycloakService extends Keycloak {
|
|
|
2897
2895
|
}
|
|
2898
2896
|
|
|
2899
2897
|
//Assign Agent to a team
|
|
2900
|
-
let URL4 = `${keycloakConfig[ "ef-server-url" ]}team/${userObject.group.id}/member`;
|
|
2898
|
+
let URL4 = `${this.keycloakConfig[ "ef-server-url" ]}team/${userObject.group.id}/member`;
|
|
2901
2899
|
|
|
2902
2900
|
data = {
|
|
2903
2901
|
"type": "agent",
|
|
@@ -2943,7 +2941,7 @@ class KeycloakService extends Keycloak {
|
|
|
2943
2941
|
let supervisorTeamId = supervisedGroup.id;
|
|
2944
2942
|
|
|
2945
2943
|
//Check whether team of Supervisor already exists in CX Core or not
|
|
2946
|
-
let URL5 = `${keycloakConfig[ "ef-server-url" ]}team?ids=${supervisorTeamId}`;
|
|
2944
|
+
let URL5 = `${this.keycloakConfig[ "ef-server-url" ]}team?ids=${supervisorTeamId}`;
|
|
2947
2945
|
|
|
2948
2946
|
config1.url = URL5;
|
|
2949
2947
|
|
|
@@ -2955,7 +2953,7 @@ class KeycloakService extends Keycloak {
|
|
|
2955
2953
|
if ( getSupervisorCXTeam.data.length == 0 ) {
|
|
2956
2954
|
|
|
2957
2955
|
//Creating or Updating Supervisor team in CX Core.
|
|
2958
|
-
let URL6 = `${keycloakConfig[ "ef-server-url" ]}team`;
|
|
2956
|
+
let URL6 = `${this.keycloakConfig[ "ef-server-url" ]}team`;
|
|
2959
2957
|
|
|
2960
2958
|
let data = {
|
|
2961
2959
|
"team_Id": supervisorTeamId,
|
|
@@ -2993,7 +2991,7 @@ class KeycloakService extends Keycloak {
|
|
|
2993
2991
|
if ( getSupervisorCXTeam.data[ 0 ].supervisor_Id != null ) {
|
|
2994
2992
|
|
|
2995
2993
|
//Assign Secondary Supervisor to a team
|
|
2996
|
-
let URL7 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}/member`;
|
|
2994
|
+
let URL7 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}/member`;
|
|
2997
2995
|
|
|
2998
2996
|
data = {
|
|
2999
2997
|
"type": "secondary-supervisor",
|
|
@@ -3025,7 +3023,7 @@ class KeycloakService extends Keycloak {
|
|
|
3025
3023
|
} else {
|
|
3026
3024
|
|
|
3027
3025
|
//Check whether team of Supervisor already exists in CX Core or not
|
|
3028
|
-
let URL8 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}`;
|
|
3026
|
+
let URL8 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}`;
|
|
3029
3027
|
|
|
3030
3028
|
let data = {
|
|
3031
3029
|
"team_name": getSupervisorCXTeam.data[ 0 ].team_name,
|
|
@@ -3134,7 +3132,7 @@ class KeycloakService extends Keycloak {
|
|
|
3134
3132
|
}
|
|
3135
3133
|
|
|
3136
3134
|
//get user attributes to check its user_name and extension
|
|
3137
|
-
let URL = `${keycloakConfig[ "auth-server-url" ]}${keycloakConfig[ "USERNAME_ADMIN" ]}/realms/${keycloakConfig[ "realm" ]}/users/${keyObj.id}`;
|
|
3135
|
+
let URL = `${this.keycloakConfig[ "auth-server-url" ]}${this.keycloakConfig[ "USERNAME_ADMIN" ]}/realms/${this.keycloakConfig[ "realm" ]}/users/${keyObj.id}`;
|
|
3138
3136
|
|
|
3139
3137
|
let config = {
|
|
3140
3138
|
|
|
@@ -3186,7 +3184,7 @@ class KeycloakService extends Keycloak {
|
|
|
3186
3184
|
if ( Object.keys( data ).length > 0 ) {
|
|
3187
3185
|
|
|
3188
3186
|
|
|
3189
|
-
let URL1 = `${keycloakConfig[ "auth-server-url" ]}${keycloakConfig[ "USERNAME_ADMIN" ]}/realms/${keycloakConfig[ "realm" ]}/users/${keyObj.id}`;
|
|
3187
|
+
let URL1 = `${this.keycloakConfig[ "auth-server-url" ]}${this.keycloakConfig[ "USERNAME_ADMIN" ]}/realms/${this.keycloakConfig[ "realm" ]}/users/${keyObj.id}`;
|
|
3190
3188
|
|
|
3191
3189
|
config.url = URL1;
|
|
3192
3190
|
config.method = 'put';
|
|
@@ -3298,7 +3296,7 @@ class KeycloakService extends Keycloak {
|
|
|
3298
3296
|
};
|
|
3299
3297
|
|
|
3300
3298
|
//User Groups
|
|
3301
|
-
let URL2 = keycloakConfig[ "ef-server-url" ] + "team/user/" + userId;
|
|
3299
|
+
let URL2 = this.keycloakConfig[ "ef-server-url" ] + "team/user/" + userId;
|
|
3302
3300
|
config1.url = URL2;
|
|
3303
3301
|
|
|
3304
3302
|
let config2 = {
|
|
@@ -3345,7 +3343,7 @@ class KeycloakService extends Keycloak {
|
|
|
3345
3343
|
|
|
3346
3344
|
//We have to both add agent to a team corresponding to Finesse and remove it from CX team.
|
|
3347
3345
|
//Removing agent from CX team first
|
|
3348
|
-
let URL3 = `${keycloakConfig[ "ef-server-url" ]}team/${userTeam.teamId}/member?type=agent&usernames=${finObj.username.toLowerCase()}`;
|
|
3346
|
+
let URL3 = `${this.keycloakConfig[ "ef-server-url" ]}team/${userTeam.teamId}/member?type=agent&usernames=${finObj.username.toLowerCase()}`;
|
|
3349
3347
|
|
|
3350
3348
|
config1.method = 'delete';
|
|
3351
3349
|
config1.url = URL3;
|
|
@@ -3366,7 +3364,7 @@ class KeycloakService extends Keycloak {
|
|
|
3366
3364
|
}
|
|
3367
3365
|
|
|
3368
3366
|
//Check whether team of Agent already exists in CX Core or not
|
|
3369
|
-
let URL4 = `${keycloakConfig[ "ef-server-url" ]}team?ids=${finObj.group.id}`;
|
|
3367
|
+
let URL4 = `${this.keycloakConfig[ "ef-server-url" ]}team?ids=${finObj.group.id}`;
|
|
3370
3368
|
|
|
3371
3369
|
config1.method = 'get';
|
|
3372
3370
|
config1.url = URL4;
|
|
@@ -3382,7 +3380,7 @@ class KeycloakService extends Keycloak {
|
|
|
3382
3380
|
if ( getAgentCXTeam.data.length == 0 ) {
|
|
3383
3381
|
|
|
3384
3382
|
//Setting URL to Create CX team of Agent
|
|
3385
|
-
let URL5 = `${keycloakConfig[ "ef-server-url" ]}team`;
|
|
3383
|
+
let URL5 = `${this.keycloakConfig[ "ef-server-url" ]}team`;
|
|
3386
3384
|
|
|
3387
3385
|
let data = {
|
|
3388
3386
|
"team_Id": finObj.group.id,
|
|
@@ -3414,7 +3412,7 @@ class KeycloakService extends Keycloak {
|
|
|
3414
3412
|
}
|
|
3415
3413
|
|
|
3416
3414
|
//Assign Agent to a team
|
|
3417
|
-
let URL6 = `${keycloakConfig[ "ef-server-url" ]}team/${finObj.group.id}/member`;
|
|
3415
|
+
let URL6 = `${this.keycloakConfig[ "ef-server-url" ]}team/${finObj.group.id}/member`;
|
|
3418
3416
|
|
|
3419
3417
|
data = {
|
|
3420
3418
|
"type": "agent",
|
|
@@ -3462,7 +3460,7 @@ class KeycloakService extends Keycloak {
|
|
|
3462
3460
|
if ( supervisedTeam.type === 'secondary supervisor' ) {
|
|
3463
3461
|
|
|
3464
3462
|
//Removing user from Secondary Supervisor in CX Core
|
|
3465
|
-
let URL13 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}/member?type=secondary-supervisor&usernames=${finObj.username.toLowerCase()}`;
|
|
3463
|
+
let URL13 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}/member?type=secondary-supervisor&usernames=${finObj.username.toLowerCase()}`;
|
|
3466
3464
|
|
|
3467
3465
|
config2.method = 'delete';
|
|
3468
3466
|
config2.url = URL13;
|
|
@@ -3487,7 +3485,7 @@ class KeycloakService extends Keycloak {
|
|
|
3487
3485
|
} else {
|
|
3488
3486
|
|
|
3489
3487
|
//Removing user from Supervising team in CX Core or not
|
|
3490
|
-
let URL7 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}`;
|
|
3488
|
+
let URL7 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}`;
|
|
3491
3489
|
|
|
3492
3490
|
let data = {
|
|
3493
3491
|
"team_name": supervisedTeam.teamName,
|
|
@@ -3539,7 +3537,7 @@ class KeycloakService extends Keycloak {
|
|
|
3539
3537
|
let supervisorTeamId = teamToAdd.id;
|
|
3540
3538
|
|
|
3541
3539
|
//Check whether team of Supervisor already exists in CX Core or not
|
|
3542
|
-
let URL8 = `${keycloakConfig[ "ef-server-url" ]}team?ids=${supervisorTeamId}`;
|
|
3540
|
+
let URL8 = `${this.keycloakConfig[ "ef-server-url" ]}team?ids=${supervisorTeamId}`;
|
|
3543
3541
|
|
|
3544
3542
|
config1.url = URL8;
|
|
3545
3543
|
|
|
@@ -3551,7 +3549,7 @@ class KeycloakService extends Keycloak {
|
|
|
3551
3549
|
if ( getSupervisorCXTeam.data.length == 0 ) {
|
|
3552
3550
|
|
|
3553
3551
|
//Creating or Updating Supervisor team in CX Core.
|
|
3554
|
-
let URL9 = `${keycloakConfig[ "ef-server-url" ]}team`;
|
|
3552
|
+
let URL9 = `${this.keycloakConfig[ "ef-server-url" ]}team`;
|
|
3555
3553
|
|
|
3556
3554
|
let data = {
|
|
3557
3555
|
"team_Id": supervisorTeamId,
|
|
@@ -3587,7 +3585,7 @@ class KeycloakService extends Keycloak {
|
|
|
3587
3585
|
if ( getSupervisorCXTeam.data[ 0 ].supervisor_Id != null ) {
|
|
3588
3586
|
|
|
3589
3587
|
//Assign Agent to a team
|
|
3590
|
-
let URL10 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}/member`;
|
|
3588
|
+
let URL10 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}/member`;
|
|
3591
3589
|
|
|
3592
3590
|
data = {
|
|
3593
3591
|
"type": "secondary-supervisor",
|
|
@@ -3617,7 +3615,7 @@ class KeycloakService extends Keycloak {
|
|
|
3617
3615
|
} else {
|
|
3618
3616
|
|
|
3619
3617
|
//Adding current user as Supervisor to team
|
|
3620
|
-
let URL11 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}`;
|
|
3618
|
+
let URL11 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisorTeamId}`;
|
|
3621
3619
|
|
|
3622
3620
|
let data = {
|
|
3623
3621
|
"team_name": getSupervisorCXTeam.data[ 0 ].team_name,
|
|
@@ -3679,7 +3677,7 @@ class KeycloakService extends Keycloak {
|
|
|
3679
3677
|
if ( supervisedTeam.type === 'secondary supervisor' ) {
|
|
3680
3678
|
|
|
3681
3679
|
//Removing user from Secondary Supervisor in CX Core
|
|
3682
|
-
let URL11 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}/member?type=secondary-supervisor&usernames=${finObj.username.toLowerCase()}`;
|
|
3680
|
+
let URL11 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}/member?type=secondary-supervisor&usernames=${finObj.username.toLowerCase()}`;
|
|
3683
3681
|
|
|
3684
3682
|
config2.method = 'delete';
|
|
3685
3683
|
config2.url = URL11;
|
|
@@ -3704,7 +3702,7 @@ class KeycloakService extends Keycloak {
|
|
|
3704
3702
|
} else {
|
|
3705
3703
|
|
|
3706
3704
|
//Removing user from Supervising team in CX Core
|
|
3707
|
-
let URL12 = `${keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}`;
|
|
3705
|
+
let URL12 = `${this.keycloakConfig[ "ef-server-url" ]}team/${supervisedTeam.teamId}`;
|
|
3708
3706
|
|
|
3709
3707
|
let data = {
|
|
3710
3708
|
"team_name": supervisedTeam.teamName,
|
|
@@ -3778,8 +3776,8 @@ class KeycloakService extends Keycloak {
|
|
|
3778
3776
|
|
|
3779
3777
|
try {
|
|
3780
3778
|
|
|
3781
|
-
let adminToken = await this.getAccessToken( keycloakConfig[ "USERNAME_ADMIN" ], keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
3782
|
-
let cxTeams = await ciscoSyncService.syncCiscoData( finesseAdministratorUsername, finesseAdministratorPassword, finesseURL, keycloakConfig, adminToken.access_token );
|
|
3779
|
+
let adminToken = await this.getAccessToken( this.keycloakConfig[ "USERNAME_ADMIN" ], this.keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
3780
|
+
let cxTeams = await ciscoSyncService.syncCiscoData( finesseAdministratorUsername, finesseAdministratorPassword, finesseURL, this.keycloakConfig, adminToken.access_token );
|
|
3783
3781
|
|
|
3784
3782
|
resolve( cxTeams );
|
|
3785
3783
|
|
|
@@ -3833,9 +3831,9 @@ class KeycloakService extends Keycloak {
|
|
|
3833
3831
|
let responseObject;
|
|
3834
3832
|
user_name = ( user_name ).toLowerCase();
|
|
3835
3833
|
|
|
3836
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
3834
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
3837
3835
|
|
|
3838
|
-
//keycloakConfig["auth-server-url"] +'realms
|
|
3836
|
+
//this.keycloakConfig["auth-server-url"] +'realms
|
|
3839
3837
|
let config = {
|
|
3840
3838
|
|
|
3841
3839
|
method: "post",
|
|
@@ -3847,10 +3845,10 @@ class KeycloakService extends Keycloak {
|
|
|
3847
3845
|
},
|
|
3848
3846
|
data: {
|
|
3849
3847
|
username: user_name,
|
|
3850
|
-
password: keycloakConfig[ "SYNC_AGENT_PASSWORD" ],
|
|
3851
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
3852
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
3853
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
3848
|
+
password: this.keycloakConfig[ "SYNC_AGENT_PASSWORD" ],
|
|
3849
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
3850
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
3851
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
3854
3852
|
},
|
|
3855
3853
|
|
|
3856
3854
|
};
|
|
@@ -3881,11 +3879,11 @@ class KeycloakService extends Keycloak {
|
|
|
3881
3879
|
try {
|
|
3882
3880
|
|
|
3883
3881
|
let config1 = { ...config };
|
|
3884
|
-
config1.data.username = keycloakConfig.USERNAME_ADMIN;
|
|
3885
|
-
config1.data.password = keycloakConfig.PASSWORD_ADMIN;
|
|
3882
|
+
config1.data.username = this.keycloakConfig.USERNAME_ADMIN;
|
|
3883
|
+
config1.data.password = this.keycloakConfig.PASSWORD_ADMIN;
|
|
3886
3884
|
delete config1.data.token;
|
|
3887
3885
|
|
|
3888
|
-
config1.url = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
3886
|
+
config1.url = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig[ "realm" ] + "/protocol/openid-connect/token";
|
|
3889
3887
|
|
|
3890
3888
|
let adminTokenResponse = await requestController.httpRequest( config1, true );
|
|
3891
3889
|
|
|
@@ -3897,7 +3895,7 @@ class KeycloakService extends Keycloak {
|
|
|
3897
3895
|
|
|
3898
3896
|
config1.headers.Authorization = "Bearer " + admin_token;
|
|
3899
3897
|
config1.method = "get";
|
|
3900
|
-
config1.url = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/users?username=" + user_name + "&exact=true";
|
|
3898
|
+
config1.url = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/users?username=" + user_name + "&exact=true";
|
|
3901
3899
|
delete config1.data;
|
|
3902
3900
|
|
|
3903
3901
|
let getuserDetails = await requestController.httpRequest( config1, true );
|
|
@@ -3911,7 +3909,7 @@ class KeycloakService extends Keycloak {
|
|
|
3911
3909
|
lastName: getuserDetails?.data[ 0 ]?.lastName ? getuserDetails?.data[ 0 ]?.lastName : "",
|
|
3912
3910
|
username: getuserDetails?.data[ 0 ]?.username,
|
|
3913
3911
|
roles: ( 'realm_access' in intro_token_response?.data && 'roles' in intro_token_response?.data?.realm_access ) ? intro_token_response?.data?.realm_access?.roles : [],
|
|
3914
|
-
realm: keycloakConfig[ "realm" ]
|
|
3912
|
+
realm: this.keycloakConfig[ "realm" ]
|
|
3915
3913
|
};
|
|
3916
3914
|
|
|
3917
3915
|
//Adding user custom attribute to our token object data.
|
|
@@ -4002,16 +4000,16 @@ class KeycloakService extends Keycloak {
|
|
|
4002
4000
|
},
|
|
4003
4001
|
data: {
|
|
4004
4002
|
username: user_name,
|
|
4005
|
-
password: keycloakConfig[ "SYNC_AGENT_PASSWORD" ],
|
|
4006
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
4007
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
4008
|
-
grant_type: keycloakConfig.GRANT_TYPE,
|
|
4003
|
+
password: this.keycloakConfig[ "SYNC_AGENT_PASSWORD" ],
|
|
4004
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
4005
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
4006
|
+
grant_type: this.keycloakConfig.GRANT_TYPE,
|
|
4009
4007
|
},
|
|
4010
4008
|
|
|
4011
4009
|
};
|
|
4012
4010
|
|
|
4013
4011
|
config.data.grant_type = "urn:ietf:params:oauth:grant-type:uma-ticket";
|
|
4014
|
-
config.data.audience = keycloakConfig.CLIENT_ID;
|
|
4012
|
+
config.data.audience = this.keycloakConfig.CLIENT_ID;
|
|
4015
4013
|
config.headers.Authorization = "Bearer " + token;
|
|
4016
4014
|
|
|
4017
4015
|
// T.O.K.E.N R.E.Q.U.E.S.T # 2 (A.C.C.E.S.S T.O.K.E.N W.I.T.H P.E.R.M.I.S.S.I.O.N.S)
|
|
@@ -4024,7 +4022,7 @@ class KeycloakService extends Keycloak {
|
|
|
4024
4022
|
refresh_token = rptResponse.data.refresh_token;
|
|
4025
4023
|
|
|
4026
4024
|
let userToken = token;
|
|
4027
|
-
config.data.grant_type = keycloakConfig.GRANT_TYPE;
|
|
4025
|
+
config.data.grant_type = this.keycloakConfig.GRANT_TYPE;
|
|
4028
4026
|
config.data.token = token;
|
|
4029
4027
|
URL = URL + "/introspect";
|
|
4030
4028
|
config.url = URL;
|
|
@@ -4119,7 +4117,7 @@ class KeycloakService extends Keycloak {
|
|
|
4119
4117
|
return new Promise( async ( resolve, reject ) => {
|
|
4120
4118
|
|
|
4121
4119
|
let passwordUpdate = false;
|
|
4122
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/users?search=" + userName + "&briefRepresentation=false&exact=true"
|
|
4120
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/users?search=" + userName + "&briefRepresentation=false&exact=true"
|
|
4123
4121
|
|
|
4124
4122
|
let config = {
|
|
4125
4123
|
method: "get",
|
|
@@ -4175,7 +4173,7 @@ class KeycloakService extends Keycloak {
|
|
|
4175
4173
|
let userId = userResponse.data[ 0 ].id;
|
|
4176
4174
|
|
|
4177
4175
|
//API URL used to update the password.
|
|
4178
|
-
let URL2 = keycloakConfig[ "auth-server-url" ] + "admin/realms/" + keycloakConfig[ "realm" ] + "/users/" + userId + "/reset-password"
|
|
4176
|
+
let URL2 = this.keycloakConfig[ "auth-server-url" ] + "admin/realms/" + this.keycloakConfig[ "realm" ] + "/users/" + userId + "/reset-password"
|
|
4179
4177
|
|
|
4180
4178
|
let data = {
|
|
4181
4179
|
"temporary": false,
|
|
@@ -4236,7 +4234,7 @@ class KeycloakService extends Keycloak {
|
|
|
4236
4234
|
async generateAccessTokenFromRefreshToken( refreshToken ) {
|
|
4237
4235
|
return new Promise( async ( resolve, reject ) => {
|
|
4238
4236
|
let accessToken;
|
|
4239
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/" + keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
4237
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/" + this.keycloakConfig.realm + "/protocol/openid-connect/token";
|
|
4240
4238
|
|
|
4241
4239
|
let config = {
|
|
4242
4240
|
method: "post",
|
|
@@ -4245,8 +4243,8 @@ class KeycloakService extends Keycloak {
|
|
|
4245
4243
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
4246
4244
|
},
|
|
4247
4245
|
data: {
|
|
4248
|
-
client_id: keycloakConfig.CLIENT_ID,
|
|
4249
|
-
client_secret: keycloakConfig.credentials.secret,
|
|
4246
|
+
client_id: this.keycloakConfig.CLIENT_ID,
|
|
4247
|
+
client_secret: this.keycloakConfig.credentials.secret,
|
|
4250
4248
|
grant_type: "refresh_token",
|
|
4251
4249
|
refresh_token: refreshToken,
|
|
4252
4250
|
},
|
|
@@ -4291,7 +4289,7 @@ class KeycloakService extends Keycloak {
|
|
|
4291
4289
|
let authzConfig = '';
|
|
4292
4290
|
|
|
4293
4291
|
let accessToken;
|
|
4294
|
-
let URL = keycloakConfig[ "auth-server-url" ] + "realms/master/protocol/openid-connect/token";
|
|
4292
|
+
let URL = this.keycloakConfig[ "auth-server-url" ] + "realms/master/protocol/openid-connect/token";
|
|
4295
4293
|
|
|
4296
4294
|
let config = {
|
|
4297
4295
|
method: "post",
|
|
@@ -4302,8 +4300,8 @@ class KeycloakService extends Keycloak {
|
|
|
4302
4300
|
data: {
|
|
4303
4301
|
client_id: "admin-cli",
|
|
4304
4302
|
grant_type: "password",
|
|
4305
|
-
username: keycloakConfig[ "MASTER_USERNAME" ],
|
|
4306
|
-
password: keycloakConfig[ "MASTER_PASSWORD" ]
|
|
4303
|
+
username: this.keycloakConfig[ "MASTER_USERNAME" ],
|
|
4304
|
+
password: this.keycloakConfig[ "MASTER_PASSWORD" ]
|
|
4307
4305
|
},
|
|
4308
4306
|
};
|
|
4309
4307
|
|
|
@@ -4313,7 +4311,7 @@ class KeycloakService extends Keycloak {
|
|
|
4313
4311
|
|
|
4314
4312
|
accessToken = adminAccessToken.data.access_token;
|
|
4315
4313
|
|
|
4316
|
-
let createRealmUrl = keycloakConfig[ "auth-server-url" ] + 'admin/realms';
|
|
4314
|
+
let createRealmUrl = this.keycloakConfig[ "auth-server-url" ] + 'admin/realms';
|
|
4317
4315
|
|
|
4318
4316
|
// 1. Read the realm configuration JSON file
|
|
4319
4317
|
console.log( `Reading realm configuration from: ${realmFile}` );
|
|
@@ -4422,7 +4420,7 @@ class KeycloakService extends Keycloak {
|
|
|
4422
4420
|
|
|
4423
4421
|
// 4. Get the internal UUID of the target client
|
|
4424
4422
|
console.log( `Fetching UUID for client '${targetClientIdForAuthz}' in realm '${tenantName}'...` );
|
|
4425
|
-
const getClientUrl = `${keycloakConfig[ "auth-server-url" ]}admin/realms/${tenantName}/clients`;
|
|
4423
|
+
const getClientUrl = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${tenantName}/clients`;
|
|
4426
4424
|
|
|
4427
4425
|
let config2 = {
|
|
4428
4426
|
|
|
@@ -4529,7 +4527,7 @@ class KeycloakService extends Keycloak {
|
|
|
4529
4527
|
// 6. Make the API call to Keycloak to import/update authorization settings
|
|
4530
4528
|
console.log( `Importing authorization settings for client UUID '${clientUuid}'...` );
|
|
4531
4529
|
|
|
4532
|
-
const importAuthzUrl = `${keycloakConfig[ "auth-server-url" ]}admin/realms/${tenantName}/clients/${clientUuid}/authz/resource-server/import`;
|
|
4530
|
+
const importAuthzUrl = `${this.keycloakConfig[ "auth-server-url" ]}admin/realms/${tenantName}/clients/${clientUuid}/authz/resource-server/import`;
|
|
4533
4531
|
|
|
4534
4532
|
let config3 = {
|
|
4535
4533
|
|
|
@@ -4658,7 +4656,7 @@ class KeycloakService extends Keycloak {
|
|
|
4658
4656
|
|
|
4659
4657
|
return new Promise( ( resolve, reject ) => {
|
|
4660
4658
|
|
|
4661
|
-
if ( !keycloakConfig[ "auth-server-url" ] || !keycloakConfig[ "realm" ] ) {
|
|
4659
|
+
if ( !this.keycloakConfig[ "auth-server-url" ] || !this.keycloakConfig[ "realm" ] ) {
|
|
4662
4660
|
reject( {
|
|
4663
4661
|
error_message: "Configuration Error: baseUrl and realm are required in config.",
|
|
4664
4662
|
error_detail: "Missing required configuration parameters"
|
|
@@ -4676,7 +4674,7 @@ class KeycloakService extends Keycloak {
|
|
|
4676
4674
|
|
|
4677
4675
|
try {
|
|
4678
4676
|
|
|
4679
|
-
const events = await fetchAdminEvents( keycloakConfig[ "auth-server-url" ], keycloakConfig[ "realm" ], keycloakConfig[ "USERNAME_ADMIN" ], keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
4677
|
+
const events = await fetchAdminEvents( this.keycloakConfig[ "auth-server-url" ], this.keycloakConfig[ "realm" ], this.keycloakConfig[ "USERNAME_ADMIN" ], this.keycloakConfig[ "PASSWORD_ADMIN" ] );
|
|
4680
4678
|
const newEvents = getNewEvents( events );
|
|
4681
4679
|
|
|
4682
4680
|
newEvents.forEach( event => {
|