UNPKG

3.4 kBJavaScriptView Raw
1"use strict";
2/**
3 * -------------------------------------------------------------------------------------------
4 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
5 * See License in the project root for license information.
6 * -------------------------------------------------------------------------------------------
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.CustomAuthenticationProvider = void 0;
10var tslib_1 = require("tslib");
11/**
12 * @module CustomAuthenticationProvider
13 */
14var GraphClientError_1 = require("./GraphClientError");
15/**
16 * @class
17 * Class representing CustomAuthenticationProvider
18 * @extends AuthenticationProvider
19 */
20var CustomAuthenticationProvider = /** @class */ (function () {
21 /**
22 * @public
23 * @constructor
24 * Creates an instance of CustomAuthenticationProvider
25 * @param {AuthProviderCallback} provider - An authProvider function
26 * @returns An instance of CustomAuthenticationProvider
27 */
28 function CustomAuthenticationProvider(provider) {
29 this.provider = provider;
30 }
31 /**
32 * @public
33 * @async
34 * To get the access token
35 * @returns The promise that resolves to an access token
36 */
37 CustomAuthenticationProvider.prototype.getAccessToken = function () {
38 return tslib_1.__awaiter(this, void 0, void 0, function () {
39 var _this = this;
40 return tslib_1.__generator(this, function (_a) {
41 return [2 /*return*/, new Promise(function (resolve, reject) {
42 _this.provider(function (error, accessToken) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
43 var invalidTokenMessage, err;
44 return tslib_1.__generator(this, function (_a) {
45 switch (_a.label) {
46 case 0:
47 if (!accessToken) return [3 /*break*/, 1];
48 resolve(accessToken);
49 return [3 /*break*/, 3];
50 case 1:
51 if (!error) {
52 invalidTokenMessage = "Access token is undefined or empty.\
53 Please provide a valid token.\
54 For more help - https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/CustomAuthenticationProvider.md";
55 error = new GraphClientError_1.GraphClientError(invalidTokenMessage);
56 }
57 return [4 /*yield*/, GraphClientError_1.GraphClientError.setGraphClientError(error)];
58 case 2:
59 err = _a.sent();
60 reject(err);
61 _a.label = 3;
62 case 3: return [2 /*return*/];
63 }
64 });
65 }); });
66 })];
67 });
68 });
69 };
70 return CustomAuthenticationProvider;
71}());
72exports.CustomAuthenticationProvider = CustomAuthenticationProvider;
73//# sourceMappingURL=CustomAuthenticationProvider.js.map
\No newline at end of file