dataverse-utils 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auth.js +22 -14
- package/package.json +1 -1
package/lib/auth.js
CHANGED
|
@@ -45,23 +45,31 @@ const getAccessToken = async (tenant, url) => {
|
|
|
45
45
|
});
|
|
46
46
|
// Try to get token silently
|
|
47
47
|
if (accounts.length > 0) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
try {
|
|
49
|
+
const silentToken = await pca.acquireTokenSilent({
|
|
50
|
+
account: accounts[0],
|
|
51
|
+
scopes: [`${url}/.default`]
|
|
52
|
+
});
|
|
53
|
+
if (silentToken) {
|
|
54
|
+
return silentToken;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (ex) {
|
|
58
|
+
if (ex.message.indexOf('The refresh token has expired due to inactivity') === -1) {
|
|
59
|
+
throw new Error(ex.message);
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
// Acquire token by device code
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
try {
|
|
65
|
+
const token = await pca.acquireTokenByDeviceCode({
|
|
66
|
+
scopes: [`${url}/.default`],
|
|
67
|
+
deviceCodeCallback: (response) => logger_1.logger.info(response.message)
|
|
68
|
+
});
|
|
69
|
+
return token;
|
|
70
|
+
}
|
|
71
|
+
catch (ex) {
|
|
63
72
|
throw new Error(ex.message);
|
|
64
|
-
}
|
|
65
|
-
return token;
|
|
73
|
+
}
|
|
66
74
|
};
|
|
67
75
|
exports.getAccessToken = getAccessToken;
|