forked from lholmquist/keycloak-admin-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-with-request.js
52 lines (42 loc) · 1.02 KB
/
example-with-request.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
var request = require('request');
var url = '/realms/master/protocol/openid-connect/token';
var baseUrl = 'http://192.168.99.100:8080/auth';
var config = {
username: 'admin',
password: 'admin',
grant_type: 'password',
client_id: 'admin-cli'
};
// First We need a token
request.post({url: baseUrl + url, form: config}, function (err, resp, body) {
if (err) {
console.log(err);
return;
}
var jsonBody = JSON.parse(body);
var accessToken = jsonBody.access_token;
var auth = {
bearer: accessToken
};
request({
url: `${baseUrl}/admin/realms`,
auth: auth
}, function (err, response, body) {
if (err) {
console.log(err);
return;
}
var realms = JSON.parse(body);
console.log('Got All Realms', realms);
request({
url: `${baseUrl}/admin/realms/${realms[0].realm}`,
auth: auth
}, function (err, response, body) {
if (err) {
console.log(err);
return;
}
console.log('Got First Realm', JSON.parse(body));
});
});
});