/
get-profile.js
107 lines (80 loc) · 2.79 KB
/
get-profile.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
module.exports = {
friendlyName: 'Get Profile',
description: 'Return profile information for a specified end-point',
extendedDescription: 'Clients access protected data by making API calls with the access token for a given user. Please see the OAuth Implementation page for instructions on how to retrieve an access token. The ID.me server will validate the access token to ensure it has not expired and that its scope covers the requested resource.',
inputs: {
access_token : {
description : 'Access code requested from and OAuth response. See Get-Auth-Token',
example: '3b57cc74ec7f1cf3e32527b1fa47e842a00755d643695a3dcbd0ee85885adb5c',
required: true
},
end_point : {
description: 'The specified group affiliation',
example: 'military,student,responder,teacher,government',
required: true
}
},
defaultExit: 'success',
exits: {
error: {
description: 'Unexpected error occurred.',
},
success: {
description: 'User Profile information:',
example: {
id: 'c34a81aa25e2a3d0402806',
verified: true,
affiliation: 'Veteran',
email: 'partner+military_veteran_1@id.me',
fname: 'Franc',
lname: 'Footer',
phone: '555-555-5555'
}
},
},
fn: function (inputs,exits) {
var Http = require('machinepack-http');
Http.sendHttpRequest({
baseUrl:'https://api.id.me',
url: '/api/public/v2/'+inputs.end_point+'.json',
method:'get',
params:{
access_token : inputs.access_token
},
headers: {
'Accept':'application/json'
}
}).exec({
error: function (err){
return exits.error(err);
},
// 404 status code returned from server
notFound: function (result){
return exits.error(result);
},
// 400 status code returned from server
badRequest: function (result){
return exits.error(JSON.parse(result.body).error_description);
},
// 403 status code returned from server
forbidden: function (result){
return exits.error(result);
},
// 401 status code returned from server
unauthorized: function (result){
return exits.error(JSON.parse(result.body).message);
},
// 5xx status code returned from server (this usually means something went wrong on the other end)
serverError: function (result){
return exits.error(result);
},
// Unexpected connection error: could not send or receive HTTP request.
requestFailed: function (){
return exits.error('Unexpected connection error: could not send or receive HTTP request.');
},
success: function(result){
return exits.success(JSON.parse(result.body));
}
});
},
};