-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonBehalfOfClient.js
41 lines (36 loc) · 1.06 KB
/
onBehalfOfClient.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
const msal = require('@azure/msal-node');
const config = require('../authConfig');
const msalConfig = {
auth: {
clientId: config.credentials.clientID,
authority: `https://${config.metadata.authority}/${config.credentials.tenantID}`,
clientSecret: config.credentials.clientSecret,
clientCapabilities: ['CP1'],
},
system: {
loggerOptions: {
loggerCallback(loglevel, message, containsPii) {
console.log(message);
},
piiLoggingEnabled: false,
logLevel: msal.LogLevel.Info,
},
},
};
// Create msal application object
const cca = new msal.ConfidentialClientApplication(msalConfig);
const getOboToken = async (oboAssertion) => {
const oboRequest = {
oboAssertion: oboAssertion,
scopes: config.protectedResources.graphApi.scopes
};
try {
const response = await cca.acquireTokenOnBehalfOf(oboRequest);
return response.accessToken;
} catch (error) {
throw error;
}
};
module.exports = {
getOboToken,
};