Skip to content

Commit fa1528c

Browse files
committed
Formatting cleanup.
1 parent 2d9533a commit fa1528c

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

quickstart.js

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,69 +20,70 @@ async function getFromApi(accessToken, resourceUrl, queryParams = {}) {
2020
baseURL: baseApiUri,
2121
headers: {
2222
"Authorization": `Bearer ${accessToken}`,
23-
"Accept": "application/json",
23+
"Accept": "application/json",
2424
"Content-Type": "application/json; charset=utf-8"
2525
}
2626
});
27-
27+
2828
await api.get(resourceUrl, { params: queryParams })
2929
.then(function (apiResponse) {
3030
if (apiResponse.status != '200') {
3131
logResponse(apiResponse);
3232
}
3333
else {
3434
data = apiResponse.data;
35-
}})
35+
}
36+
})
3637
.catch(function (error) {
3738
logResponse(error);
3839
});
3940
return data;
4041
}
4142

4243
async function getAccessToken() {
43-
const audienceString = `${baseApiUri}/identityserver/connect/token`;
44-
45-
const assertion = {
46-
"iss": rksServiceAccount,
47-
"sub": rksServiceAccount,
48-
"aud": audienceString,
49-
"exp": Math.floor(new Date().getTime() / 1000) + 200,
50-
"jti": uuidv4()
51-
};
44+
const audienceString = `${baseApiUri}/identityserver/connect/token`;
5245

53-
var signedAssertion;
54-
try {
55-
signedAssertion = jwt.sign(assertion, privateKey, { algorithm: 'RS256' });
56-
}
57-
catch(err) {
58-
console.log(`Error signing JWT. Check your private key. Error: ${err}`);
59-
return null;
60-
}
61-
62-
const payload = {
63-
scope: "api",
64-
grant_type: "client_credentials",
65-
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
66-
client_assertion: signedAssertion
67-
};
46+
const assertion = {
47+
"iss": rksServiceAccount,
48+
"sub": rksServiceAccount,
49+
"aud": audienceString,
50+
"exp": Math.floor(new Date().getTime() / 1000) + 200,
51+
"jti": uuidv4()
52+
};
6853

69-
const tokenResponse = await makeAccessTokenRequest(payload);
70-
if (!tokenResponse || !tokenResponse.access_token) {
71-
return null;
72-
}
73-
return tokenResponse.access_token;
54+
var signedAssertion;
55+
try {
56+
signedAssertion = jwt.sign(assertion, privateKey, { algorithm: 'RS256' });
57+
}
58+
catch(err) {
59+
console.log(`Error signing JWT. Check your private key. Error: ${err}`);
60+
return null;
61+
}
62+
63+
const payload = {
64+
scope: "api",
65+
grant_type: "client_credentials",
66+
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
67+
client_assertion: signedAssertion
68+
};
69+
70+
const tokenResponse = await makeAccessTokenRequest(payload);
71+
if (!tokenResponse || !tokenResponse.access_token) {
72+
return null;
73+
}
74+
return tokenResponse.access_token;
7475
}
7576

7677

7778
async function makeAccessTokenRequest(payload) {
7879
return axios.post(`${baseApiUri}/identityserver/connect/token`, querystring.stringify(payload))
7980
.then(function (response) {
80-
return response.data;
81-
})
82-
.catch(function (error) {
83-
console.log(error);
84-
return null;
85-
});
81+
return response.data;
82+
})
83+
.catch(function (error) {
84+
console.log(error);
85+
return null;
86+
});
8687
}
8788

8889
function logResponse(response) {
@@ -96,17 +97,17 @@ getAccessToken().then( token => {
9697

9798
const participantResourceUrl = `/api/v1/administration/projects/` + rksProjectId + '/participants';
9899
getFromApi(token, participantResourceUrl)
99-
.then(data => {
100-
if (data) {
101-
// Uncomment this to print out the full response to the console.
102-
// logResponse(data);
103-
console.log(`\nTotal Participants: ${data.totalParticipants}`);
104-
} else {
105-
console.log("Error when accessing the API.");
106-
}
107-
});
108-
}
109-
else {
110-
console.log("Error obtaining access token.");
111-
}
112-
});
100+
.then(data => {
101+
if (data) {
102+
// Uncomment this to print out the full response to the console.
103+
// logResponse(data);
104+
console.log(`\nTotal Participants: ${data.totalParticipants}`);
105+
} else {
106+
console.log("Error when accessing the API.");
107+
}
108+
});
109+
}
110+
else {
111+
console.log("Error obtaining access token.");
112+
}
113+
});

0 commit comments

Comments
 (0)