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