@azure/identity 1.0.0-preview.1 → 1.0.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/CHANGELOG.md +24 -0
- package/README.md +50 -23
- package/browser/identity.js +9828 -0
- package/browser/identity.js.map +1 -0
- package/browser/identity.min.js +2 -0
- package/browser/identity.min.js.map +1 -0
- package/dist/index.js +475 -205
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/errors.d.ts +1 -1
- package/dist-esm/src/client/errors.d.ts.map +1 -1
- package/dist-esm/src/client/errors.js +9 -1
- package/dist-esm/src/client/errors.js.map +1 -1
- package/dist-esm/src/client/identityClient.d.ts +20 -17
- package/dist-esm/src/client/identityClient.d.ts.map +1 -1
- package/dist-esm/src/client/identityClient.js +42 -206
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.d.ts +7 -0
- package/dist-esm/src/credentials/clientCertificateCredential.browser.d.ts.map +1 -0
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js +12 -0
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/clientCertificateCredential.d.ts +5 -5
- package/dist-esm/src/credentials/clientCertificateCredential.d.ts.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.js +59 -5
- package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.d.ts +3 -3
- package/dist-esm/src/credentials/clientSecretCredential.d.ts.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.js +27 -4
- package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.d.ts +7 -0
- package/dist-esm/src/credentials/deviceCodeCredential.browser.d.ts.map +1 -0
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js +12 -0
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/deviceCodeCredential.d.ts +67 -0
- package/dist-esm/src/credentials/deviceCodeCredential.d.ts.map +1 -0
- package/dist-esm/src/credentials/deviceCodeCredential.js +139 -0
- package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -0
- package/dist-esm/src/credentials/environmentCredential.browser.d.ts +7 -0
- package/dist-esm/src/credentials/environmentCredential.browser.d.ts.map +1 -0
- package/dist-esm/src/credentials/environmentCredential.browser.js +12 -0
- package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/environmentCredential.d.ts.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.js +0 -4
- package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.d.ts +32 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.d.ts.map +1 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +112 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.d.ts +12 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.d.ts.map +1 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.js +17 -0
- package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -0
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.d.ts +24 -0
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.d.ts.map +1 -0
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js +3 -0
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -0
- package/dist-esm/src/credentials/managedIdentityCredential.browser.d.ts +7 -0
- package/dist-esm/src/credentials/managedIdentityCredential.browser.d.ts.map +1 -0
- package/dist-esm/src/credentials/managedIdentityCredential.browser.js +15 -0
- package/dist-esm/src/credentials/managedIdentityCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/managedIdentityCredential.d.ts +10 -1
- package/dist-esm/src/credentials/managedIdentityCredential.d.ts.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential.js +144 -2
- package/dist-esm/src/credentials/managedIdentityCredential.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.d.ts +39 -0
- package/dist-esm/src/credentials/usernamePasswordCredential.d.ts.map +1 -0
- package/dist-esm/src/credentials/usernamePasswordCredential.js +67 -0
- package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -0
- package/dist-esm/src/index.d.ts +4 -0
- package/dist-esm/src/index.d.ts.map +1 -1
- package/dist-esm/src/index.js +3 -0
- package/dist-esm/src/index.js.map +1 -1
- package/package.json +32 -14
- package/src/client/errors.ts +11 -3
- package/src/client/identityClient.ts +64 -246
- package/src/credentials/clientCertificateCredential.browser.ts +27 -0
- package/src/credentials/clientCertificateCredential.ts +72 -22
- package/src/credentials/clientSecretCredential.ts +32 -17
- package/src/credentials/deviceCodeCredential.browser.ts +27 -0
- package/src/credentials/deviceCodeCredential.ts +203 -0
- package/src/credentials/environmentCredential.browser.ts +19 -0
- package/src/credentials/environmentCredential.ts +5 -9
- package/src/credentials/interactiveBrowserCredential.browser.ts +134 -0
- package/src/credentials/interactiveBrowserCredential.ts +31 -0
- package/src/credentials/interactiveBrowserCredentialOptions.ts +30 -0
- package/src/credentials/managedIdentityCredential.browser.ts +22 -0
- package/src/credentials/managedIdentityCredential.ts +179 -8
- package/src/credentials/usernamePasswordCredential.ts +83 -0
- package/src/index.ts +4 -0
|
@@ -2,21 +2,17 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import * as tslib_1 from "tslib";
|
|
4
4
|
import qs from "qs";
|
|
5
|
-
import
|
|
6
|
-
import uuid from "uuid";
|
|
7
|
-
import { ServiceClient, WebResource, RestError } from "@azure/core-http";
|
|
5
|
+
import { ServiceClient, WebResource } from "@azure/core-http";
|
|
8
6
|
import { AuthenticationError } from "./errors";
|
|
9
|
-
const SelfSignedJwtLifetimeMins = 10;
|
|
10
7
|
const DefaultAuthorityHost = "https://login.microsoftonline.com";
|
|
11
|
-
const DefaultScopeSuffix = "/.default";
|
|
12
|
-
export const ImdsEndpoint = "http://169.254.169.254/metadata/identity/oauth2/token";
|
|
13
|
-
export const ImdsApiVersion = "2018-02-01";
|
|
14
|
-
export const AppServiceMsiApiVersion = "2017-09-01";
|
|
15
8
|
export class IdentityClient extends ServiceClient {
|
|
16
9
|
constructor(options) {
|
|
17
10
|
options = options || IdentityClient.getDefaultOptions();
|
|
18
11
|
super(undefined, options);
|
|
19
|
-
this.baseUri = options.authorityHost;
|
|
12
|
+
this.baseUri = this.authorityHost = options.authorityHost || DefaultAuthorityHost;
|
|
13
|
+
if (!this.baseUri.startsWith("https:")) {
|
|
14
|
+
throw new Error("The authorityHost address must use the 'https' protocol.");
|
|
15
|
+
}
|
|
20
16
|
}
|
|
21
17
|
createWebResource(requestOptions) {
|
|
22
18
|
const webResource = new WebResource();
|
|
@@ -31,219 +27,59 @@ export class IdentityClient extends ServiceClient {
|
|
|
31
27
|
});
|
|
32
28
|
if (response.status === 200 || response.status === 201) {
|
|
33
29
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
accessToken: {
|
|
31
|
+
token: response.parsedBody.access_token,
|
|
32
|
+
expiresOnTimestamp: expiresOnParser(response.parsedBody)
|
|
33
|
+
},
|
|
34
|
+
refreshToken: response.parsedBody.refresh_token,
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
else {
|
|
39
|
-
throw new AuthenticationError(response.status, response.bodyAsText);
|
|
38
|
+
throw new AuthenticationError(response.status, response.parsedBody || response.bodyAsText);
|
|
40
39
|
}
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
let scope = "";
|
|
45
|
-
if (Array.isArray(scopes)) {
|
|
46
|
-
if (scopes.length !== 1) {
|
|
47
|
-
throw "To convert to a resource string the specified array must be exactly length 1";
|
|
48
|
-
}
|
|
49
|
-
scope = scopes[0];
|
|
50
|
-
}
|
|
51
|
-
else if (typeof scopes === "string") {
|
|
52
|
-
scope = scopes;
|
|
53
|
-
}
|
|
54
|
-
if (!scope.endsWith(DefaultScopeSuffix)) {
|
|
55
|
-
return scope;
|
|
56
|
-
}
|
|
57
|
-
return scope.substr(0, scope.lastIndexOf(DefaultScopeSuffix));
|
|
58
|
-
}
|
|
59
|
-
dateInSeconds(date) {
|
|
60
|
-
return Math.floor(date.getTime() / 1000);
|
|
61
|
-
}
|
|
62
|
-
addMinutes(date, minutes) {
|
|
63
|
-
date.setMinutes(date.getMinutes() + minutes);
|
|
64
|
-
return date;
|
|
65
|
-
}
|
|
66
|
-
createImdsAuthRequest(resource, clientId) {
|
|
67
|
-
const queryParameters = {
|
|
68
|
-
resource,
|
|
69
|
-
"api-version": ImdsApiVersion
|
|
70
|
-
};
|
|
71
|
-
if (clientId) {
|
|
72
|
-
queryParameters.client_id = clientId;
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
url: ImdsEndpoint,
|
|
76
|
-
method: "GET",
|
|
77
|
-
queryParameters,
|
|
78
|
-
headers: {
|
|
79
|
-
Accept: "application/json",
|
|
80
|
-
Metadata: true
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
createAppServiceMsiAuthRequest(resource, clientId) {
|
|
85
|
-
const queryParameters = {
|
|
86
|
-
resource,
|
|
87
|
-
"api-version": AppServiceMsiApiVersion,
|
|
88
|
-
};
|
|
89
|
-
if (clientId) {
|
|
90
|
-
queryParameters.client_id = clientId;
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
url: process.env.MSI_ENDPOINT,
|
|
94
|
-
method: "GET",
|
|
95
|
-
queryParameters,
|
|
96
|
-
headers: {
|
|
97
|
-
Accept: "application/json",
|
|
98
|
-
secret: process.env.MSI_SECRET
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
createCloudShellMsiAuthRequest(resource, clientId) {
|
|
103
|
-
const body = {
|
|
104
|
-
resource
|
|
105
|
-
};
|
|
106
|
-
if (clientId) {
|
|
107
|
-
body.client_id = clientId;
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
url: process.env.MSI_ENDPOINT,
|
|
111
|
-
method: "POST",
|
|
112
|
-
body: qs.stringify(body),
|
|
113
|
-
headers: {
|
|
114
|
-
Accept: "application/json",
|
|
115
|
-
Metadata: true,
|
|
116
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
pingImdsEndpoint(resource, clientId) {
|
|
42
|
+
refreshAccessToken(tenantId, clientId, scopes, refreshToken, clientSecret, expiresOnParser, options) {
|
|
121
43
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
44
|
+
if (refreshToken === undefined) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const refreshParams = {
|
|
48
|
+
grant_type: "refresh_token",
|
|
49
|
+
client_id: clientId,
|
|
50
|
+
refresh_token: refreshToken,
|
|
51
|
+
scope: scopes
|
|
52
|
+
};
|
|
53
|
+
if (clientSecret !== undefined) {
|
|
54
|
+
refreshParams.client_secret = clientSecret;
|
|
128
55
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
56
|
+
const webResource = this.createWebResource({
|
|
57
|
+
url: `${this.authorityHost}/${tenantId}/oauth2/v2.0/token`,
|
|
58
|
+
method: "POST",
|
|
59
|
+
disableJsonStringifyOnBody: true,
|
|
60
|
+
deserializationMapper: undefined,
|
|
61
|
+
body: qs.stringify(refreshParams),
|
|
62
|
+
headers: {
|
|
63
|
+
Accept: "application/json",
|
|
64
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
65
|
+
},
|
|
66
|
+
abortSignal: options && options.abortSignal
|
|
67
|
+
});
|
|
134
68
|
try {
|
|
135
|
-
yield this.
|
|
69
|
+
return yield this.sendTokenRequest(webResource, expiresOnParser);
|
|
136
70
|
}
|
|
137
71
|
catch (err) {
|
|
138
|
-
if (err instanceof
|
|
139
|
-
//
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// If we received any response, the endpoint is available
|
|
144
|
-
return true;
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
authenticateClientSecret(tenantId, clientId, clientSecret, scopes, getTokenOptions) {
|
|
148
|
-
const webResource = this.createWebResource({
|
|
149
|
-
url: `${this.baseUri}/${tenantId}/oauth2/v2.0/token`,
|
|
150
|
-
method: "POST",
|
|
151
|
-
disableJsonStringifyOnBody: true,
|
|
152
|
-
deserializationMapper: undefined,
|
|
153
|
-
body: qs.stringify({
|
|
154
|
-
response_type: "token",
|
|
155
|
-
grant_type: "client_credentials",
|
|
156
|
-
client_id: clientId,
|
|
157
|
-
client_secret: clientSecret,
|
|
158
|
-
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
|
|
159
|
-
}),
|
|
160
|
-
headers: {
|
|
161
|
-
Accept: "application/json",
|
|
162
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
163
|
-
},
|
|
164
|
-
abortSignal: getTokenOptions && getTokenOptions.abortSignal
|
|
165
|
-
});
|
|
166
|
-
return this.sendTokenRequest(webResource);
|
|
167
|
-
}
|
|
168
|
-
authenticateManagedIdentity(scopes, checkIfImdsEndpointAvailable, clientId, getTokenOptions) {
|
|
169
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
let authRequestOptions;
|
|
171
|
-
const resource = this.mapScopesToResource(scopes);
|
|
172
|
-
let expiresInParser;
|
|
173
|
-
// Detect which type of environment we are running in
|
|
174
|
-
if (process.env.MSI_ENDPOINT) {
|
|
175
|
-
if (process.env.MSI_SECRET) {
|
|
176
|
-
// Running in App Service
|
|
177
|
-
authRequestOptions = this.createAppServiceMsiAuthRequest(resource, clientId);
|
|
178
|
-
expiresInParser = (requestBody) => {
|
|
179
|
-
// Parse a date format like "06/20/2019 02:57:58 +00:00" and
|
|
180
|
-
// convert it into a JavaScript-formatted date
|
|
181
|
-
const m = requestBody.expires_on.match(/(\d\d)\/(\d\d)\/(\d\d\d\d) (\d\d):(\d\d):(\d\d) (\+|-)(\d\d):(\d\d)/);
|
|
182
|
-
return Date.parse(`${m[3]}-${m[1]}-${m[2]}T${m[4]}:${m[5]}:${m[6]}${m[7]}${m[8]}:${m[9]}`);
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
// Running in Cloud Shell
|
|
187
|
-
authRequestOptions = this.createCloudShellMsiAuthRequest(resource, clientId);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
// Ping the IMDS endpoint to see if it's available
|
|
192
|
-
if (!checkIfImdsEndpointAvailable || (yield this.pingImdsEndpoint(resource, clientId))) {
|
|
193
|
-
// Running in an Azure VM
|
|
194
|
-
authRequestOptions = this.createImdsAuthRequest(resource, clientId);
|
|
72
|
+
if (err instanceof AuthenticationError && err.errorResponse.error === "interaction_required") {
|
|
73
|
+
// It's likely that the refresh token has expired, so
|
|
74
|
+
// return null so that the credential implementation will
|
|
75
|
+
// initiate the authentication flow again.
|
|
76
|
+
return null;
|
|
195
77
|
}
|
|
196
78
|
else {
|
|
197
|
-
|
|
198
|
-
// no MSI authentication endpoints are available
|
|
199
|
-
return null;
|
|
79
|
+
throw err;
|
|
200
80
|
}
|
|
201
81
|
}
|
|
202
|
-
const webResource = this.createWebResource(Object.assign({ disableJsonStringifyOnBody: true, deserializationMapper: undefined, abortSignal: getTokenOptions && getTokenOptions.abortSignal }, authRequestOptions));
|
|
203
|
-
return this.sendTokenRequest(webResource, expiresInParser);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
authenticateClientCertificate(tenantId, clientId, certificateString, certificateX5t, scopes, getTokenOptions) {
|
|
207
|
-
const tokenId = uuid.v4();
|
|
208
|
-
const audienceUrl = `${this.baseUri}/${tenantId}/oauth2/v2.0/token`;
|
|
209
|
-
const header = {
|
|
210
|
-
typ: "JWT",
|
|
211
|
-
alg: "RS256",
|
|
212
|
-
x5t: certificateX5t
|
|
213
|
-
};
|
|
214
|
-
const payload = {
|
|
215
|
-
iss: clientId,
|
|
216
|
-
sub: clientId,
|
|
217
|
-
aud: audienceUrl,
|
|
218
|
-
jti: tokenId,
|
|
219
|
-
nbf: this.dateInSeconds(new Date()),
|
|
220
|
-
exp: this.dateInSeconds(this.addMinutes(new Date(), SelfSignedJwtLifetimeMins))
|
|
221
|
-
};
|
|
222
|
-
const clientAssertion = jws.sign({
|
|
223
|
-
header,
|
|
224
|
-
payload,
|
|
225
|
-
secret: certificateString
|
|
226
|
-
});
|
|
227
|
-
const webResource = this.createWebResource({
|
|
228
|
-
url: audienceUrl,
|
|
229
|
-
method: "POST",
|
|
230
|
-
disableJsonStringifyOnBody: true,
|
|
231
|
-
deserializationMapper: undefined,
|
|
232
|
-
body: qs.stringify({
|
|
233
|
-
response_type: "token",
|
|
234
|
-
grant_type: "client_credentials",
|
|
235
|
-
client_id: clientId,
|
|
236
|
-
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
|
237
|
-
client_assertion: clientAssertion,
|
|
238
|
-
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
|
|
239
|
-
}),
|
|
240
|
-
headers: {
|
|
241
|
-
Accept: "application/json",
|
|
242
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
243
|
-
},
|
|
244
|
-
abortSignal: getTokenOptions && getTokenOptions.abortSignal
|
|
245
82
|
});
|
|
246
|
-
return this.sendTokenRequest(webResource);
|
|
247
83
|
}
|
|
248
84
|
static getDefaultOptions() {
|
|
249
85
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identityClient.js","sourceRoot":"","sources":["../../../src/client/identityClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"identityClient.js","sourceRoot":"","sources":["../../../src/client/identityClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAEL,aAAa,EAEb,WAAW,EAGZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,oBAAoB,GAAG,mCAAmC,CAAC;AAkBjE,MAAM,OAAO,cAAe,SAAQ,aAAa;IAG/C,YAAY,OAA+B;QACzC,OAAO,GAAG,OAAO,IAAI,cAAc,CAAC,iBAAiB,EAAE,CAAC;QACxD,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,oBAAoB,CAAC;QAElF,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC7E;IACH,CAAC;IAED,iBAAiB,CAAC,cAAqC;QACrD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;QACtC,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACpC,OAAO,WAAW,CAAC;IACrB,CAAC;IAEK,gBAAgB,CACpB,WAAwB,EACxB,eAA+C;;YAE/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YAErD,eAAe,GAAG,eAAe,IAAI,CAAC,CAAC,YAAiB,EAAE,EAAE;gBAC1D,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,CAAC,UAAU,GAAG,IAAI,CAAA;YAC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OAAO,CAAC,WAAW;aAC5C,CAAC,CAAC;YAEH,IAAI;gBACF,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;aAClE;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,GAAG,YAAY,mBAAmB,IAAI,GAAG,CAAC,aAAa,CAAC,KAAK,KAAK,sBAAsB,EAAE;oBAC5F,qDAAqD;oBACrD,yDAAyD;oBACzD,0CAA0C;oBAC1C,OAAO,IAAI,CAAC;iBACb;qBAAM;oBACL,MAAM,GAAG,CAAC;iBACX;aACF;QACH,CAAC;KAAA;IAED,MAAM,CAAC,iBAAiB;QACtB,OAAO;YACL,aAAa,EAAE,oBAAoB;SACpC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
|
|
2
|
+
import { IdentityClientOptions } from "../client/identityClient";
|
|
3
|
+
export declare class ClientCertificateCredential implements TokenCredential {
|
|
4
|
+
constructor(tenantId: string, clientId: string, certificatePath: string, options?: IdentityClientOptions);
|
|
5
|
+
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=clientCertificateCredential.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientCertificateCredential.browser.d.ts","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.browser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAIjE,qBAAa,2BAA4B,YAAW,eAAe;gBAE/D,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,qBAAqB;IAK1B,QAAQ,CACb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAG/B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
const BrowserNotSupportedError = new Error("ClientCertificateCredential is not supported in the browser.");
|
|
4
|
+
export class ClientCertificateCredential {
|
|
5
|
+
constructor(tenantId, clientId, certificatePath, options) {
|
|
6
|
+
throw BrowserNotSupportedError;
|
|
7
|
+
}
|
|
8
|
+
getToken(scopes, options) {
|
|
9
|
+
throw BrowserNotSupportedError;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=clientCertificateCredential.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientCertificateCredential.browser.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAOlC,MAAM,wBAAwB,GAAG,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;AAE3G,MAAM,OAAO,2BAA2B;IACtC,YACE,QAAgB,EAChB,QAAgB,EAChB,eAAuB,EACvB,OAA+B;QAE/B,MAAM,wBAAwB,CAAC;IACjC,CAAC;IAEM,QAAQ,CACb,MAAyB,EACzB,OAAyB;QAEzB,MAAM,wBAAwB,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -10,11 +10,11 @@ import { IdentityClientOptions } from "../client/identityClient";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class ClientCertificateCredential implements TokenCredential {
|
|
12
12
|
private identityClient;
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
certificateThumbprint
|
|
17
|
-
certificateX5t
|
|
13
|
+
private tenantId;
|
|
14
|
+
private clientId;
|
|
15
|
+
private certificateString;
|
|
16
|
+
private certificateThumbprint;
|
|
17
|
+
private certificateX5t;
|
|
18
18
|
/**
|
|
19
19
|
* Creates an instance of the ClientCertificateCredential with the details
|
|
20
20
|
* needed to authenticate against Azure Active Directory with a certificate.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCertificateCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clientCertificateCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAkB,MAAM,0BAA0B,CAAC;AAajF;;;;;;;GAOG;AACH,qBAAa,2BAA4B,YAAW,eAAe;IACjE,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,cAAc,CAAS;IAE/B;;;;;;;;OAQG;gBAED,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,qBAAqB;IAyBjC;;;;;;;;;OASG;IACU,QAAQ,CACnB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CA+C/B"}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
+
import * as tslib_1 from "tslib";
|
|
4
|
+
import qs from "qs";
|
|
5
|
+
import jws from "jws";
|
|
6
|
+
import uuid from "uuid";
|
|
3
7
|
import { readFileSync } from "fs";
|
|
4
8
|
import { createHash } from "crypto";
|
|
5
9
|
import { IdentityClient } from "../client/identityClient";
|
|
10
|
+
const SelfSignedJwtLifetimeMins = 10;
|
|
11
|
+
function timestampInSeconds(date) {
|
|
12
|
+
return Math.floor(date.getTime() / 1000);
|
|
13
|
+
}
|
|
14
|
+
function addMinutes(date, minutes) {
|
|
15
|
+
date.setMinutes(date.getMinutes() + minutes);
|
|
16
|
+
return date;
|
|
17
|
+
}
|
|
6
18
|
/**
|
|
7
19
|
* Enables authentication to Azure Active Directory using a PEM-encoded
|
|
8
20
|
* certificate that is assigned to an App Registration. More information
|
|
@@ -23,11 +35,11 @@ export class ClientCertificateCredential {
|
|
|
23
35
|
*/
|
|
24
36
|
constructor(tenantId, clientId, certificatePath, options) {
|
|
25
37
|
this.identityClient = new IdentityClient(options);
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
38
|
+
this.tenantId = tenantId;
|
|
39
|
+
this.clientId = clientId;
|
|
40
|
+
this.certificateString = readFileSync(certificatePath, "utf8");
|
|
29
41
|
const certificatePattern = /(-+BEGIN CERTIFICATE-+)(\n\r?|\r\n?)([A-Za-z0-9+/\n\r]+=*)(\n\r?|\r\n?)(-+END CERTIFICATE-+)/;
|
|
30
|
-
const matchCert = this.
|
|
42
|
+
const matchCert = this.certificateString.match(certificatePattern);
|
|
31
43
|
const publicKey = matchCert ? matchCert[3] : "";
|
|
32
44
|
if (!publicKey) {
|
|
33
45
|
throw new Error("The file at the specified path does not contain a PEM-encoded certificate.");
|
|
@@ -49,7 +61,49 @@ export class ClientCertificateCredential {
|
|
|
49
61
|
* TokenCredential implementation might make.
|
|
50
62
|
*/
|
|
51
63
|
getToken(scopes, options) {
|
|
52
|
-
return
|
|
64
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const tokenId = uuid.v4();
|
|
66
|
+
const audienceUrl = `${this.identityClient.authorityHost}/${this.tenantId}/oauth2/v2.0/token`;
|
|
67
|
+
const header = {
|
|
68
|
+
typ: "JWT",
|
|
69
|
+
alg: "RS256",
|
|
70
|
+
x5t: this.certificateX5t
|
|
71
|
+
};
|
|
72
|
+
const payload = {
|
|
73
|
+
iss: this.clientId,
|
|
74
|
+
sub: this.clientId,
|
|
75
|
+
aud: audienceUrl,
|
|
76
|
+
jti: tokenId,
|
|
77
|
+
nbf: timestampInSeconds(new Date()),
|
|
78
|
+
exp: timestampInSeconds(addMinutes(new Date(), SelfSignedJwtLifetimeMins))
|
|
79
|
+
};
|
|
80
|
+
const clientAssertion = jws.sign({
|
|
81
|
+
header,
|
|
82
|
+
payload,
|
|
83
|
+
secret: this.certificateString
|
|
84
|
+
});
|
|
85
|
+
const webResource = this.identityClient.createWebResource({
|
|
86
|
+
url: audienceUrl,
|
|
87
|
+
method: "POST",
|
|
88
|
+
disableJsonStringifyOnBody: true,
|
|
89
|
+
deserializationMapper: undefined,
|
|
90
|
+
body: qs.stringify({
|
|
91
|
+
response_type: "token",
|
|
92
|
+
grant_type: "client_credentials",
|
|
93
|
+
client_id: this.clientId,
|
|
94
|
+
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
|
95
|
+
client_assertion: clientAssertion,
|
|
96
|
+
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
|
|
97
|
+
}),
|
|
98
|
+
headers: {
|
|
99
|
+
Accept: "application/json",
|
|
100
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
101
|
+
},
|
|
102
|
+
abortSignal: options && options.abortSignal
|
|
103
|
+
});
|
|
104
|
+
const tokenResponse = yield this.identityClient.sendTokenRequest(webResource);
|
|
105
|
+
return (tokenResponse && tokenResponse.accessToken) || null;
|
|
106
|
+
});
|
|
53
107
|
}
|
|
54
108
|
}
|
|
55
109
|
//# sourceMappingURL=clientCertificateCredential.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCertificateCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"clientCertificateCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAyB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEjF,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,SAAS,kBAAkB,CAAC,IAAU;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,UAAU,CAAC,IAAU,EAAE,OAAe;IAC7C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA2B;IAQtC;;;;;;;;OAQG;IACH,YACE,QAAgB,EAChB,QAAgB,EAChB,eAAuB,EACvB,OAA+B;QAE/B,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAE/D,MAAM,kBAAkB,GAAG,8FAA8F,CAAC;QAC1H,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,kBAAkB,CAAC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AM;gBACN,OAAO;gBACP,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC;gBACxD,GAAG,EAAE,WAAW;gBAChB,MAAM,EAAE,MAAM;gBACd,0BAA0B,EAAE,IAAI;gBAChC,qBAAqB,EAAE,SAAS;gBAChC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC;oBACjB,aAAa,EAAE,OAAO;oBACtB,UAAU,EAAE,oBAAoB;oBAChC,SAAS,EAAE,IAAI,CAAC,QAAQ;oBACxB,qBAAqB,EAAE,wDAAwD;oBAC/E,gBAAgB,EAAE,eAAe;oBACjC,KAAK,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;iBAC9D,CAAC;gBACF,OAAO,EAAE;oBACP,MAAM,EAAE,kBAAkB;oBAC1B,cAAc,EAAE,mCAAmC;iBACpD;gBACD,WAAW,EAAE,OAAO,IAAI,OAAO,CAAC,WAAW;aAC5C,CAAC,CAAC;YAEH,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAC9E,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;QAC9D,CAAC;KAAA;CACF"}
|
|
@@ -10,9 +10,9 @@ import { IdentityClientOptions } from "../client/identityClient";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class ClientSecretCredential implements TokenCredential {
|
|
12
12
|
private identityClient;
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
13
|
+
private tenantId;
|
|
14
|
+
private clientId;
|
|
15
|
+
private clientSecret;
|
|
16
16
|
/**
|
|
17
17
|
* Creates an instance of the ClientSecretCredential with the details
|
|
18
18
|
* needed to authenticate against Azure Active Directory with a client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientSecretCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clientSecretCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAkB,MAAM,0BAA0B,CAAC;AAEjF;;;;;;;GAOG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;;;;;OASG;gBAED,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,qBAAqB;IAQjC;;;;;;;;;OASG;IACU,QAAQ,CACnB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAuB/B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
+
import * as tslib_1 from "tslib";
|
|
4
|
+
import qs from "qs";
|
|
3
5
|
import { IdentityClient } from "../client/identityClient";
|
|
4
6
|
/**
|
|
5
7
|
* Enables authentication to Azure Active Directory using a client secret
|
|
@@ -22,9 +24,9 @@ export class ClientSecretCredential {
|
|
|
22
24
|
*/
|
|
23
25
|
constructor(tenantId, clientId, clientSecret, options) {
|
|
24
26
|
this.identityClient = new IdentityClient(options);
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
27
|
+
this.tenantId = tenantId;
|
|
28
|
+
this.clientId = clientId;
|
|
29
|
+
this.clientSecret = clientSecret;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Authenticates with Azure Active Directory and returns an {@link AccessToken} if
|
|
@@ -37,7 +39,28 @@ export class ClientSecretCredential {
|
|
|
37
39
|
* TokenCredential implementation might make.
|
|
38
40
|
*/
|
|
39
41
|
getToken(scopes, options) {
|
|
40
|
-
return
|
|
42
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const webResource = this.identityClient.createWebResource({
|
|
44
|
+
url: `${this.identityClient.authorityHost}/${this.tenantId}/oauth2/v2.0/token`,
|
|
45
|
+
method: "POST",
|
|
46
|
+
disableJsonStringifyOnBody: true,
|
|
47
|
+
deserializationMapper: undefined,
|
|
48
|
+
body: qs.stringify({
|
|
49
|
+
response_type: "token",
|
|
50
|
+
grant_type: "client_credentials",
|
|
51
|
+
client_id: this.clientId,
|
|
52
|
+
client_secret: this.clientSecret,
|
|
53
|
+
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
|
|
54
|
+
}),
|
|
55
|
+
headers: {
|
|
56
|
+
Accept: "application/json",
|
|
57
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
58
|
+
},
|
|
59
|
+
abortSignal: options && options.abortSignal
|
|
60
|
+
});
|
|
61
|
+
const tokenResponse = yield this.identityClient.sendTokenRequest(webResource);
|
|
62
|
+
return (tokenResponse && tokenResponse.accessToken) || null;
|
|
63
|
+
});
|
|
41
64
|
}
|
|
42
65
|
}
|
|
43
66
|
//# sourceMappingURL=clientSecretCredential.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientSecretCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"clientSecretCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.ts"],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a,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAC9E,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;QAC9D,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
|
|
2
|
+
import { IdentityClientOptions } from "../client/identityClient";
|
|
3
|
+
export declare class DeviceCodeCredential implements TokenCredential {
|
|
4
|
+
constructor(tenantId: string, clientId: string, userPromptCallback: (details: any) => void, options?: IdentityClientOptions);
|
|
5
|
+
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=deviceCodeCredential.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceCodeCredential.browser.d.ts","sourceRoot":"","sources":["../../../src/credentials/deviceCodeCredential.browser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAIjE,qBAAa,oBAAqB,YAAW,eAAe;gBAExD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,EAC1C,OAAO,CAAC,EAAE,qBAAqB;IAK1B,QAAQ,CACb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAG/B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
const BrowserNotSupportedError = new Error("DeviceCodeCredential is not supported in the browser.");
|
|
4
|
+
export class DeviceCodeCredential {
|
|
5
|
+
constructor(tenantId, clientId, userPromptCallback, options) {
|
|
6
|
+
throw BrowserNotSupportedError;
|
|
7
|
+
}
|
|
8
|
+
getToken(scopes, options) {
|
|
9
|
+
throw BrowserNotSupportedError;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=deviceCodeCredential.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceCodeCredential.browser.js","sourceRoot":"","sources":["../../../src/credentials/deviceCodeCredential.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAOlC,MAAM,wBAAwB,GAAG,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;AAEpG,MAAM,OAAO,oBAAoB;IAC/B,YACE,QAAgB,EAChB,QAAgB,EAChB,kBAA0C,EAC1C,OAA+B;QAE/B,MAAM,wBAAwB,CAAC;IACjC,CAAC;IAEM,QAAQ,CACb,MAAyB,EACzB,OAAyB;QAEzB,MAAM,wBAAwB,CAAC;IACjC,CAAC;CACF"}
|