1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.AuthenticationHandler = void 0;
|
10 | var tslib_1 = require("tslib");
|
11 |
|
12 |
|
13 |
|
14 | var GraphRequestUtil_1 = require("../GraphRequestUtil");
|
15 | var MiddlewareControl_1 = require("./MiddlewareControl");
|
16 | var MiddlewareUtil_1 = require("./MiddlewareUtil");
|
17 | var AuthenticationHandlerOptions_1 = require("./options/AuthenticationHandlerOptions");
|
18 | var TelemetryHandlerOptions_1 = require("./options/TelemetryHandlerOptions");
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var AuthenticationHandler = (function () {
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function AuthenticationHandler(authenticationProvider) {
|
32 | this.authenticationProvider = authenticationProvider;
|
33 | }
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | AuthenticationHandler.prototype.execute = function (context) {
|
42 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
43 | var url, options, authenticationProvider, authenticationProviderOptions, token, bearerKey;
|
44 | return tslib_1.__generator(this, function (_a) {
|
45 | switch (_a.label) {
|
46 | case 0:
|
47 | url = typeof context.request === "string" ? context.request : context.request.url;
|
48 | if (!((0, GraphRequestUtil_1.isGraphURL)(url) || (context.customHosts && (0, GraphRequestUtil_1.isCustomHost)(url, context.customHosts)))) return [3 , 2];
|
49 | options = void 0;
|
50 | if (context.middlewareControl instanceof MiddlewareControl_1.MiddlewareControl) {
|
51 | options = context.middlewareControl.getMiddlewareOptions(AuthenticationHandlerOptions_1.AuthenticationHandlerOptions);
|
52 | }
|
53 | authenticationProvider = void 0;
|
54 | authenticationProviderOptions = void 0;
|
55 | if (options) {
|
56 | authenticationProvider = options.authenticationProvider;
|
57 | authenticationProviderOptions = options.authenticationProviderOptions;
|
58 | }
|
59 | if (!authenticationProvider) {
|
60 | authenticationProvider = this.authenticationProvider;
|
61 | }
|
62 | return [4 , authenticationProvider.getAccessToken(authenticationProviderOptions)];
|
63 | case 1:
|
64 | token = _a.sent();
|
65 | bearerKey = "Bearer ".concat(token);
|
66 | (0, MiddlewareUtil_1.appendRequestHeader)(context.request, context.options, AuthenticationHandler.AUTHORIZATION_HEADER, bearerKey);
|
67 | TelemetryHandlerOptions_1.TelemetryHandlerOptions.updateFeatureUsageFlag(context, TelemetryHandlerOptions_1.FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED);
|
68 | return [3 , 3];
|
69 | case 2:
|
70 | if (context.options.headers) {
|
71 | delete context.options.headers[AuthenticationHandler.AUTHORIZATION_HEADER];
|
72 | }
|
73 | _a.label = 3;
|
74 | case 3: return [4 , this.nextMiddleware.execute(context)];
|
75 | case 4: return [2 , _a.sent()];
|
76 | }
|
77 | });
|
78 | });
|
79 | };
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | AuthenticationHandler.prototype.setNext = function (next) {
|
87 | this.nextMiddleware = next;
|
88 | };
|
89 | |
90 |
|
91 |
|
92 |
|
93 | AuthenticationHandler.AUTHORIZATION_HEADER = "Authorization";
|
94 | return AuthenticationHandler;
|
95 | }());
|
96 | exports.AuthenticationHandler = AuthenticationHandler;
|
97 |
|
\ | No newline at end of file |