forked from GluuFederation/SCIM-Node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
130 lines (119 loc) · 4.39 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; // For self-signed certificate.
var config = {
keyAlg: 'XXXXX', // Algorithm type.
domain: 'https://example.com/', // Gluu server URL.
privateKey: 'value', // Value can be buffer or path of private key.
clientId: '@!XXXX.XXXX.XXXX.XXXX!XXXX!XXXX.XXXX!XXXX!XXXX.XXXX', // UMA client id.
keyId: '000xx0x0-xx00-00xx-xx00-0x000x0x000x', // oxAuth JWKS key id.
};
var scim = require('./index')(config);
/**
* There are 2 ways to process the response of every methods.
* 1) Using callback function.
* 2) Using promise. Do not pass callback function in argument.
*/
// region "getUsersCount": To get total count of users.
// Process data or handle error in callback function.
scim.scim2.getUsersCount(callback);
function callback(error, data) {
if (error) {
// Handle error here.
} else {
// Process data here.
}
}
// Process data or handle error using promise.
scim.scim2.getUsersCount().then(function (data) {
// Process data here.
}).catch(function (error) {
// Handle error here.
});
// endregion
// region "getUsers": To get collection of users.
// "startIndex" is page index.
// "count" is number of users to be returned.
scim.scim2.getUsers(startIndex, count, callback);
// endregion
// region "getUser": To get user object using id attribute of type inum.
// "id" is inum of user.
scim.scim2.getUser(id, callback);
// endregion
// region "addUser": To insert new user to SCIM.
// 'userSampleData' can be object or json ('username' attribute is required. 'meta' attribute is readonly).
var userSampleData =
{
'externalId': 'scimTest',
'userName': 'test',
'name': {
'givenName': 'json',
'familyName': 'json',
'middleName': 'N/A',
'honorificPrefix': 'N/A',
'honorificSuffix': 'N/A'
},
'displayName': 'json json',
'nickName': 'json',
'profileUrl': 'http://www.gluu.org/',
'emails': [{
'value': '[email protected]',
'type': 'work',
'primary': 'true'
}, {
'value': '[email protected]',
'type': 'home',
'primary': 'false'
}
],
'addresses': [{
'type': 'work',
'streetAddress': 'street 1 address',
'locality': 'Austin',
'region': 'TX',
'postalCode': '78701',
'country': 'US',
'formatted': 'street 1 address Austin , TX 78701 US',
'primary': 'true'
}
],
'phoneNumbers': [{
'value': '000-000-0000',
'type': 'work'
}
],
'ims': [{
'value': 'test_user',
'type': 'Skype'
}
],
'userType': 'CEO',
'title': 'CEO',
'preferredLanguage': 'en-us',
'locale': 'en_US',
'active': 'true',
'password': 'passw0rd',
'roles': [{
'value': 'Owner'
}
],
'entitlements': [{
'value': 'full access'
}
],
'x509Certificates': [{
'value': 'MIIDQzCCAqygAwIBAgICEAAxxxx00000xx000QEFBQAwTjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFDASBgNVBAoMC2V4YW1wbGUuY29tMRQwEgYDVQQDDAtleGFtcGxlLmNvbTAeFw0xMTEwMjIwNjI0MzFaFw0xMjEwMDQwNjI0MzFa MH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRQwEgYDVQQKDAtleGFtcGxlLmNvbTEhMB8GA1UEAwwYTXMuIEJhcmJhcmEgSiBKZW5zZW4gSUlJMSIwIAYJKoZIhvcNAQkBFhNiamVuc2VuQGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7Kr+Dcds/JQ5GwejJFcBIP682X3xpjis56AK02bc1FLgzdLI8auoR+cC9/Vrh5t66HkQIOdA4unHh0AaZ4xL5PhVbXIPMB5vAPKpzz5iPSi8xO8SL7I7SDhcBVJhqVqr3HgllEG6UClDdHO7nkLuwXq8HcISKkbT5WFTVfFZzidPl8HZ7DhXkZIRtJwBweq4bvm3hM1Os7UQH05ZS6cVDgweKNwdLLrT51ikSQG3DYrl+ft781UQRIqxgwqCfXEuDiinPh0kkvIi5jivVu1Z9QiwlYEdRbLJ4zJQBmDrSGTMYn4lRc2HgHO4DqB/bnMVorHB0CC6AV1QoFK4GPe1LwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU8pD0U0vsZIsaA16lL8En8bx0F/gwHwYDVR0jBBgwFoAUdGeKitcaF7gnzsNwDx708kqaVt0wDQYJKoZIhvcNAQEFBQADgYEAA81SsFnOdYJtNg5Tcq+/ByEDrBgnusx0jloUhByPMEVkoMZ3J7j1ZgI8rAbOkNngX8+pKfTiDz1RC4+dx8oU6Za+4NJXUjlL5CvV6BEYb1+QAEJwitTVvxB/A67g42/vzgAtoRUeDov1+GFiBZ+GNF/cAYKcMtGcrs2i97ZkJMo='
}
],
'meta': {
'created': '2010-01-23T04:56:22Z',
'lastModified': '2011-05-13T04:42:34Z',
'version': 'aversion',
'location': 'http://localhost:8080/identity/seam/resource/restv1/Users/0x0x0x00-xxxx-0000-xxxx-x0000x0xx0x0'
}
};
scim.scim2.addUser(userSampleData, callback);
// endregion
// region "removeUser": To delete user from SCIM using id attribute of type inum.
// "id" is inum of user.
scim.scim2.removeUser(id, callback);
// endregion