-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
64 lines (55 loc) · 1.62 KB
/
Copy pathtest.js
File metadata and controls
64 lines (55 loc) · 1.62 KB
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
require('dotenv').config()
const request = require('request-promise')
const btoa = require('btoa')
const { ISSUER, TEST_CLIENT_ID, TEST_CLIENT_SECRET, DEFAULT_SCOPE } = process.env
const test = async () => {
const token = btoa(`${TEST_CLIENT_ID}:${TEST_CLIENT_SECRET}`)
try {
const { token_type, access_token,id_token } = await request({
uri: `${ISSUER}/v1/token`,
json: true,
method: 'POST',
headers: {
authorization: `Basic ${token}`,
},
form: {
grant_type: 'password',
username: 'rchinta@mailinator.com',
password: 'Pass@word1',
scope: DEFAULT_SCOPE
},
})
console.log(" Start Access Token ")
console.log(" ___________________")
console.log(access_token)
console.log(" ___________________")
console.log(" End Access Token ")
console.log(" Start Get UserInfo " )
console.log(" ___________________")
const userinforesponse = await request({
uri: `${ISSUER}/v1/userinfo`,
json: true,
method: 'POST',
headers: {
authorization: [token_type, access_token].join(' '),
},
})
console.log(userinforesponse)
console.log(" ___________________")
console.log(" End Get UserInfo " )
console.log(" Start Secure Info " )
const response = await request({
uri: 'http://localhost:3000/secure',
json: true,
headers: {
authorization: [token_type, access_token].join(' '),
'id_token': id_token,
},
})
console.log(response)
console.log(" End Secure Info " )
} catch (error) {
console.log(`Error: ${error.message}`)
}
}
test()