1 |
|
2 |
|
3 | import { __awaiter, __generator } from "tslib";
|
4 | import { Constants as MSRestConstants } from "../util/constants";
|
5 | var DEFAULT_AUTHORIZATION_SCHEME = "Bearer";
|
6 |
|
7 |
|
8 |
|
9 | export var azureResourceManagerEndpoints = [
|
10 | "https://management.windows.net",
|
11 | "https://management.chinacloudapi.cn",
|
12 | "https://management.usgovcloudapi.net",
|
13 | "https://management.cloudapi.de",
|
14 | ];
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var AzureIdentityCredentialAdapter = (function () {
|
20 | function AzureIdentityCredentialAdapter(azureTokenCredential, scopes) {
|
21 | if (scopes === void 0) { scopes = "https://management.azure.com/.default"; }
|
22 | this.azureTokenCredential = azureTokenCredential;
|
23 | this.scopes = scopes;
|
24 | }
|
25 | AzureIdentityCredentialAdapter.prototype.getToken = function () {
|
26 | return __awaiter(this, void 0, void 0, function () {
|
27 | var accessToken, result;
|
28 | return __generator(this, function (_a) {
|
29 | switch (_a.label) {
|
30 | case 0: return [4 , this.azureTokenCredential.getToken(this.scopes)];
|
31 | case 1:
|
32 | accessToken = _a.sent();
|
33 | if (accessToken !== null) {
|
34 | result = {
|
35 | accessToken: accessToken.token,
|
36 | tokenType: DEFAULT_AUTHORIZATION_SCHEME,
|
37 | expiresOn: accessToken.expiresOnTimestamp,
|
38 | };
|
39 | return [2 , result];
|
40 | }
|
41 | else {
|
42 | throw new Error("Could find token for scope");
|
43 | }
|
44 | return [2 ];
|
45 | }
|
46 | });
|
47 | });
|
48 | };
|
49 | AzureIdentityCredentialAdapter.prototype.signRequest = function (webResource) {
|
50 | return __awaiter(this, void 0, void 0, function () {
|
51 | var tokenResponse;
|
52 | return __generator(this, function (_a) {
|
53 | switch (_a.label) {
|
54 | case 0: return [4 , this.getToken()];
|
55 | case 1:
|
56 | tokenResponse = _a.sent();
|
57 | webResource.headers.set(MSRestConstants.HeaderConstants.AUTHORIZATION, tokenResponse.tokenType + " " + tokenResponse.accessToken);
|
58 | return [2 , Promise.resolve(webResource)];
|
59 | }
|
60 | });
|
61 | });
|
62 | };
|
63 | return AzureIdentityCredentialAdapter;
|
64 | }());
|
65 | export { AzureIdentityCredentialAdapter };
|
66 |
|
\ | No newline at end of file |