1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.AuthCodeMSALBrowserAuthenticationProvider = void 0;
|
10 | var tslib_1 = require("tslib");
|
11 |
|
12 |
|
13 |
|
14 | var msal_browser_1 = require("@azure/msal-browser");
|
15 | var GraphClientError_1 = require("../../GraphClientError");
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var AuthCodeMSALBrowserAuthenticationProvider = (function () {
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function AuthCodeMSALBrowserAuthenticationProvider(publicClientApplication, options) {
|
32 | this.publicClientApplication = publicClientApplication;
|
33 | this.options = options;
|
34 | if (!options || !publicClientApplication) {
|
35 | throw new GraphClientError_1.GraphClientError("Please pass valid PublicClientApplication instance and AuthCodeMSALBrowserAuthenticationProviderOptions instance to instantiate MSALBrowserAuthenticationProvider");
|
36 | }
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | AuthCodeMSALBrowserAuthenticationProvider.prototype.getAccessToken = function () {
|
45 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
46 | var scopes, account, error, response, error_1, response;
|
47 | return tslib_1.__generator(this, function (_a) {
|
48 | switch (_a.label) {
|
49 | case 0:
|
50 | scopes = this.options && this.options.scopes;
|
51 | account = this.options && this.options.account;
|
52 | error = new GraphClientError_1.GraphClientError();
|
53 | if (!scopes || scopes.length === 0) {
|
54 | error.name = "Empty Scopes";
|
55 | error.message = "Scopes cannot be empty, Please provide scopes";
|
56 | throw error;
|
57 | }
|
58 | _a.label = 1;
|
59 | case 1:
|
60 | _a.trys.push([1, 3, , 9]);
|
61 | return [4 , this.publicClientApplication.acquireTokenSilent({
|
62 | scopes: scopes,
|
63 | account: account,
|
64 | })];
|
65 | case 2:
|
66 | response = _a.sent();
|
67 | if (!response || !response.accessToken) {
|
68 | error.name = "Access token is undefined";
|
69 | error.message = "Received empty access token from PublicClientApplication";
|
70 | throw error;
|
71 | }
|
72 | return [2 , response.accessToken];
|
73 | case 3:
|
74 | error_1 = _a.sent();
|
75 | if (!(error_1 instanceof msal_browser_1.InteractionRequiredAuthError)) return [3 , 7];
|
76 | if (!(this.options.interactionType === msal_browser_1.InteractionType.Redirect)) return [3 , 4];
|
77 | this.publicClientApplication.acquireTokenRedirect({ scopes: scopes });
|
78 | return [3 , 6];
|
79 | case 4:
|
80 | if (!(this.options.interactionType === msal_browser_1.InteractionType.Popup)) return [3 , 6];
|
81 | return [4 , this.publicClientApplication.acquireTokenPopup({ scopes: scopes })];
|
82 | case 5:
|
83 | response = _a.sent();
|
84 | return [2 , response.accessToken];
|
85 | case 6: return [3 , 8];
|
86 | case 7: throw error_1;
|
87 | case 8: return [3 , 9];
|
88 | case 9: return [2 ];
|
89 | }
|
90 | });
|
91 | });
|
92 | };
|
93 | return AuthCodeMSALBrowserAuthenticationProvider;
|
94 | }());
|
95 | exports.AuthCodeMSALBrowserAuthenticationProvider = AuthCodeMSALBrowserAuthenticationProvider;
|
96 |
|
\ | No newline at end of file |