@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
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import * as tslib_1 from "tslib";
|
|
4
|
+
import qs from "qs";
|
|
5
|
+
import { RestError } from "@azure/core-http";
|
|
4
6
|
import { IdentityClient } from "../client/identityClient";
|
|
7
|
+
const DefaultScopeSuffix = "/.default";
|
|
8
|
+
export const ImdsEndpoint = "http://169.254.169.254/metadata/identity/oauth2/token";
|
|
9
|
+
export const ImdsApiVersion = "2018-02-01";
|
|
10
|
+
export const AppServiceMsiApiVersion = "2017-09-01";
|
|
5
11
|
/**
|
|
6
12
|
* Attempts authentication using a managed identity that has been assigned
|
|
7
13
|
* to the deployment environment. This authentication type works in Azure VMs,
|
|
@@ -15,7 +21,143 @@ export class ManagedIdentityCredential {
|
|
|
15
21
|
constructor(clientId, options) {
|
|
16
22
|
this.isEndpointUnavailable = null;
|
|
17
23
|
this.identityClient = new IdentityClient(options);
|
|
18
|
-
this.
|
|
24
|
+
this.clientId = clientId;
|
|
25
|
+
}
|
|
26
|
+
mapScopesToResource(scopes) {
|
|
27
|
+
let scope = "";
|
|
28
|
+
if (Array.isArray(scopes)) {
|
|
29
|
+
if (scopes.length !== 1) {
|
|
30
|
+
throw "To convert to a resource string the specified array must be exactly length 1";
|
|
31
|
+
}
|
|
32
|
+
scope = scopes[0];
|
|
33
|
+
}
|
|
34
|
+
else if (typeof scopes === "string") {
|
|
35
|
+
scope = scopes;
|
|
36
|
+
}
|
|
37
|
+
if (!scope.endsWith(DefaultScopeSuffix)) {
|
|
38
|
+
return scope;
|
|
39
|
+
}
|
|
40
|
+
return scope.substr(0, scope.lastIndexOf(DefaultScopeSuffix));
|
|
41
|
+
}
|
|
42
|
+
createImdsAuthRequest(resource, clientId) {
|
|
43
|
+
const queryParameters = {
|
|
44
|
+
resource,
|
|
45
|
+
"api-version": ImdsApiVersion
|
|
46
|
+
};
|
|
47
|
+
if (clientId) {
|
|
48
|
+
queryParameters.client_id = clientId;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
url: ImdsEndpoint,
|
|
52
|
+
method: "GET",
|
|
53
|
+
queryParameters,
|
|
54
|
+
headers: {
|
|
55
|
+
Accept: "application/json",
|
|
56
|
+
Metadata: true
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
createAppServiceMsiAuthRequest(resource, clientId) {
|
|
61
|
+
const queryParameters = {
|
|
62
|
+
resource,
|
|
63
|
+
"api-version": AppServiceMsiApiVersion,
|
|
64
|
+
};
|
|
65
|
+
if (clientId) {
|
|
66
|
+
queryParameters.client_id = clientId;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
url: process.env.MSI_ENDPOINT,
|
|
70
|
+
method: "GET",
|
|
71
|
+
queryParameters,
|
|
72
|
+
headers: {
|
|
73
|
+
Accept: "application/json",
|
|
74
|
+
secret: process.env.MSI_SECRET
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
createCloudShellMsiAuthRequest(resource, clientId) {
|
|
79
|
+
const body = {
|
|
80
|
+
resource
|
|
81
|
+
};
|
|
82
|
+
if (clientId) {
|
|
83
|
+
body.client_id = clientId;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
url: process.env.MSI_ENDPOINT,
|
|
87
|
+
method: "POST",
|
|
88
|
+
body: qs.stringify(body),
|
|
89
|
+
headers: {
|
|
90
|
+
Accept: "application/json",
|
|
91
|
+
Metadata: true,
|
|
92
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
pingImdsEndpoint(resource, clientId) {
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const request = this.createImdsAuthRequest(resource, clientId);
|
|
99
|
+
// This will always be populated, but let's make TypeScript happy
|
|
100
|
+
if (request.headers) {
|
|
101
|
+
// Remove the Metadata header to invoke a request error from
|
|
102
|
+
// IMDS endpoint
|
|
103
|
+
delete request.headers.Metadata;
|
|
104
|
+
}
|
|
105
|
+
// Create a request with a 500 msec timeout since we expect that
|
|
106
|
+
// not having a "Metadata" header should cause an error to be
|
|
107
|
+
// returned quickly from the endpoint, proving its availability.
|
|
108
|
+
const webResource = this.identityClient.createWebResource(request);
|
|
109
|
+
webResource.timeout = 500;
|
|
110
|
+
try {
|
|
111
|
+
yield this.identityClient.sendRequest(webResource);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
if (err instanceof RestError && err.code === RestError.REQUEST_SEND_ERROR) {
|
|
115
|
+
// Either request failed or IMDS endpoint isn't available
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// If we received any response, the endpoint is available
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
authenticateManagedIdentity(scopes, checkIfImdsEndpointAvailable, clientId, getTokenOptions) {
|
|
124
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
let authRequestOptions;
|
|
126
|
+
const resource = this.mapScopesToResource(scopes);
|
|
127
|
+
let expiresInParser;
|
|
128
|
+
// Detect which type of environment we are running in
|
|
129
|
+
if (process.env.MSI_ENDPOINT) {
|
|
130
|
+
if (process.env.MSI_SECRET) {
|
|
131
|
+
// Running in App Service
|
|
132
|
+
authRequestOptions = this.createAppServiceMsiAuthRequest(resource, clientId);
|
|
133
|
+
expiresInParser = (requestBody) => {
|
|
134
|
+
// Parse a date format like "06/20/2019 02:57:58 +00:00" and
|
|
135
|
+
// convert it into a JavaScript-formatted date
|
|
136
|
+
const m = requestBody.expires_on.match(/(\d\d)\/(\d\d)\/(\d\d\d\d) (\d\d):(\d\d):(\d\d) (\+|-)(\d\d):(\d\d)/);
|
|
137
|
+
return Date.parse(`${m[3]}-${m[1]}-${m[2]}T${m[4]}:${m[5]}:${m[6]}${m[7]}${m[8]}:${m[9]}`);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// Running in Cloud Shell
|
|
142
|
+
authRequestOptions = this.createCloudShellMsiAuthRequest(resource, clientId);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// Ping the IMDS endpoint to see if it's available
|
|
147
|
+
if (!checkIfImdsEndpointAvailable || (yield this.pingImdsEndpoint(resource, clientId))) {
|
|
148
|
+
// Running in an Azure VM
|
|
149
|
+
authRequestOptions = this.createImdsAuthRequest(resource, clientId);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
// Returning null tells the ManagedIdentityCredential that
|
|
153
|
+
// no MSI authentication endpoints are available
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const webResource = this.identityClient.createWebResource(Object.assign({ disableJsonStringifyOnBody: true, deserializationMapper: undefined, abortSignal: getTokenOptions && getTokenOptions.abortSignal }, authRequestOptions));
|
|
158
|
+
const tokenResponse = yield this.identityClient.sendTokenRequest(webResource, expiresInParser);
|
|
159
|
+
return (tokenResponse && tokenResponse.accessToken) || null;
|
|
160
|
+
});
|
|
19
161
|
}
|
|
20
162
|
/**
|
|
21
163
|
* Authenticates with Azure Active Directory and returns an {@link AccessToken} if
|
|
@@ -35,7 +177,7 @@ export class ManagedIdentityCredential {
|
|
|
35
177
|
// the endpoint is available and need to check for it.
|
|
36
178
|
if (this.isEndpointUnavailable !== true) {
|
|
37
179
|
result =
|
|
38
|
-
yield this.
|
|
180
|
+
yield this.authenticateManagedIdentity(scopes, this.isEndpointUnavailable === null, this.clientId, options);
|
|
39
181
|
// If authenticateManagedIdentity returns null, it means no MSI
|
|
40
182
|
// endpoints are available. In this case, don't try them in future
|
|
41
183
|
// requests.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"managedIdentityCredential.js","sourceRoot":"","sources":["../../../src/credentials/managedIdentityCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;
|
|
1
|
+
{"version":3,"file":"managedIdentityCredential.js","sourceRoot":"","sources":["../../../src/credentials/managedIdentityCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAIL,SAAS,EAEV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAyB,cAAc,EAAE,MAAM,0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AAC,QAAQ,EACb,OAAO,CAAC,CAAC;gBAEb,+DAA+D;gBAC/D,mEAAmE;gBACnE,YAAY;gBACZ,IAAI,CAAC,qBAAqB,GAAG,MAAM,KAAK,IAAI,CAAC;aAC9C;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
|
|
2
|
+
import { IdentityClientOptions } from "../client/identityClient";
|
|
3
|
+
/**
|
|
4
|
+
* Enables authentication to Azure Active Directory with a user's
|
|
5
|
+
* username and password. This credential requires a high degree of
|
|
6
|
+
* trust so you should only use it when other, more secure credential
|
|
7
|
+
* types can't be used.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UsernamePasswordCredential implements TokenCredential {
|
|
10
|
+
private identityClient;
|
|
11
|
+
private tenantId;
|
|
12
|
+
private clientId;
|
|
13
|
+
private username;
|
|
14
|
+
private password;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of the UsernamePasswordCredential with the details
|
|
17
|
+
* needed to authenticate against Azure Active Directory with a username
|
|
18
|
+
* and password.
|
|
19
|
+
*
|
|
20
|
+
* @param tenantIdOrName The Azure Active Directory tenant (directory) ID or name.
|
|
21
|
+
* @param clientId The client (application) ID of an App Registration in the tenant.
|
|
22
|
+
* @param username The user account's e-mail address (user name).
|
|
23
|
+
* @param password The user account's account password
|
|
24
|
+
* @param options Options for configuring the client which makes the authentication request.
|
|
25
|
+
*/
|
|
26
|
+
constructor(tenantIdOrName: string, clientId: string, username: string, password: string, options?: IdentityClientOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Authenticates with Azure Active Directory and returns an {@link AccessToken} if
|
|
29
|
+
* successful. If authentication cannot be performed at this time, this method may
|
|
30
|
+
* return null. If an error occurs during authentication, an {@link AuthenticationError}
|
|
31
|
+
* containing failure details will be thrown.
|
|
32
|
+
*
|
|
33
|
+
* @param scopes The list of scopes for which the token will have access.
|
|
34
|
+
* @param options The options used to configure any requests this
|
|
35
|
+
* TokenCredential implementation might make.
|
|
36
|
+
*/
|
|
37
|
+
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=usernamePasswordCredential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usernamePasswordCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAkB,MAAM,0BAA0B,CAAC;AAEjF;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;;;;;;;;OAUG;gBAED,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB;IASjC;;;;;;;;;OASG;IACU,QAAQ,CACnB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAwB/B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import * as tslib_1 from "tslib";
|
|
4
|
+
import qs from "qs";
|
|
5
|
+
import { IdentityClient } from "../client/identityClient";
|
|
6
|
+
/**
|
|
7
|
+
* Enables authentication to Azure Active Directory with a user's
|
|
8
|
+
* username and password. This credential requires a high degree of
|
|
9
|
+
* trust so you should only use it when other, more secure credential
|
|
10
|
+
* types can't be used.
|
|
11
|
+
*/
|
|
12
|
+
export class UsernamePasswordCredential {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of the UsernamePasswordCredential with the details
|
|
15
|
+
* needed to authenticate against Azure Active Directory with a username
|
|
16
|
+
* and password.
|
|
17
|
+
*
|
|
18
|
+
* @param tenantIdOrName The Azure Active Directory tenant (directory) ID or name.
|
|
19
|
+
* @param clientId The client (application) ID of an App Registration in the tenant.
|
|
20
|
+
* @param username The user account's e-mail address (user name).
|
|
21
|
+
* @param password The user account's account password
|
|
22
|
+
* @param options Options for configuring the client which makes the authentication request.
|
|
23
|
+
*/
|
|
24
|
+
constructor(tenantIdOrName, clientId, username, password, options) {
|
|
25
|
+
this.identityClient = new IdentityClient(options);
|
|
26
|
+
this.tenantId = tenantIdOrName;
|
|
27
|
+
this.clientId = clientId;
|
|
28
|
+
this.username = username;
|
|
29
|
+
this.password = password;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Authenticates with Azure Active Directory and returns an {@link AccessToken} if
|
|
33
|
+
* successful. If authentication cannot be performed at this time, this method may
|
|
34
|
+
* return null. If an error occurs during authentication, an {@link AuthenticationError}
|
|
35
|
+
* containing failure details will be thrown.
|
|
36
|
+
*
|
|
37
|
+
* @param scopes The list of scopes for which the token will have access.
|
|
38
|
+
* @param options The options used to configure any requests this
|
|
39
|
+
* TokenCredential implementation might make.
|
|
40
|
+
*/
|
|
41
|
+
getToken(scopes, options) {
|
|
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: "password",
|
|
51
|
+
client_id: this.clientId,
|
|
52
|
+
username: this.username,
|
|
53
|
+
password: this.password,
|
|
54
|
+
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
|
|
55
|
+
}),
|
|
56
|
+
headers: {
|
|
57
|
+
Accept: "application/json",
|
|
58
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
59
|
+
},
|
|
60
|
+
abortSignal: options && options.abortSignal
|
|
61
|
+
});
|
|
62
|
+
const tokenResponse = yield this.identityClient.sendTokenRequest(webResource);
|
|
63
|
+
return (tokenResponse && tokenResponse.accessToken) || null;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=usernamePasswordCredential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usernamePasswordCredential.js","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAyB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IAOrC;;;;;;;;;;OAUG;IACH,YACE,cAAsB,EACtB,QAAgB,EAChB,QAAgB,EAChB,QAAgB,EAChB,OAA+B;QAE/B,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;;OASG;IACU,QAAQ,CACnB,MAAyB,EACzB,OAAyB;;YAEzB,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC;gBACxD,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,IAAI,IAAI,CAAC,QAAQ,oBAAoB;gBAC9E,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,UAAU;oBACtB,SAAS,EAAE,IAAI,CAAC,QAAQ;oBACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,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"}
|
package/dist-esm/src/index.d.ts
CHANGED
|
@@ -4,8 +4,12 @@ export { IdentityClientOptions } from "./client/identityClient";
|
|
|
4
4
|
export { EnvironmentCredential } from "./credentials/environmentCredential";
|
|
5
5
|
export { ClientSecretCredential } from "./credentials/clientSecretCredential";
|
|
6
6
|
export { ClientCertificateCredential } from "./credentials/clientCertificateCredential";
|
|
7
|
+
export { InteractiveBrowserCredential } from "./credentials/interactiveBrowserCredential";
|
|
8
|
+
export { InteractiveBrowserCredentialOptions, BrowserLoginStyle } from "./credentials/interactiveBrowserCredentialOptions";
|
|
7
9
|
export { ManagedIdentityCredential } from "./credentials/managedIdentityCredential";
|
|
10
|
+
export { DeviceCodeCredential } from "./credentials/deviceCodeCredential";
|
|
8
11
|
export { DefaultAzureCredential } from "./credentials/defaultAzureCredential";
|
|
12
|
+
export { UsernamePasswordCredential } from "./credentials/usernamePasswordCredential";
|
|
9
13
|
export { AuthenticationError, AggregateAuthenticationError } from "./client/errors";
|
|
10
14
|
export { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
|
|
11
15
|
export declare function getDefaultAzureCredential(): TokenCredential;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEjF,wBAAgB,yBAAyB,IAAI,eAAe,CAE3D"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC1F,OAAO,EAAE,mCAAmC,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAC3H,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEjF,wBAAgB,yBAAyB,IAAI,eAAe,CAE3D"}
|
package/dist-esm/src/index.js
CHANGED
|
@@ -5,8 +5,11 @@ export { ChainedTokenCredential } from "./credentials/chainedTokenCredential";
|
|
|
5
5
|
export { EnvironmentCredential } from "./credentials/environmentCredential";
|
|
6
6
|
export { ClientSecretCredential } from "./credentials/clientSecretCredential";
|
|
7
7
|
export { ClientCertificateCredential } from "./credentials/clientCertificateCredential";
|
|
8
|
+
export { InteractiveBrowserCredential } from "./credentials/interactiveBrowserCredential";
|
|
8
9
|
export { ManagedIdentityCredential } from "./credentials/managedIdentityCredential";
|
|
10
|
+
export { DeviceCodeCredential } from "./credentials/deviceCodeCredential";
|
|
9
11
|
export { DefaultAzureCredential } from "./credentials/defaultAzureCredential";
|
|
12
|
+
export { UsernamePasswordCredential } from "./credentials/usernamePasswordCredential";
|
|
10
13
|
export { AuthenticationError, AggregateAuthenticationError } from "./client/errors";
|
|
11
14
|
export function getDefaultAzureCredential() {
|
|
12
15
|
return new DefaultAzureCredential();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAIpF,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,sBAAsB,EAAE,CAAC;AACtC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAE1F,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAIpF,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,sBAAsB,EAAE,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/identity",
|
|
3
3
|
"sdk-type": "client",
|
|
4
|
-
"version": "1.0.0-preview.
|
|
4
|
+
"version": "1.0.0-preview.2",
|
|
5
5
|
"description": "Provides credential implementations for Azure SDK libraries that can authenticate with Azure Active Directory",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist-esm/src/index.js",
|
|
8
8
|
"types": "dist-esm/src/index.d.ts",
|
|
9
9
|
"browser": {
|
|
10
10
|
"stream": "./node_modules/stream-browserify/index.js",
|
|
11
|
+
"./dist-esm/src/credentials/environmentCredential.js": "./dist-esm/src/credentials/environmentCredential.browser.js",
|
|
12
|
+
"./dist-esm/src/credentials/managedIdentityCredential.js": "./dist-esm/src/credentials/managedIdentityCredential.browser.js",
|
|
13
|
+
"./dist-esm/src/credentials/clientCertificateCredential.js": "./dist-esm/src/credentials/clientCertificateCredential.browser.js",
|
|
14
|
+
"./dist-esm/src/credentials/deviceCodeCredential.js": "./dist-esm/src/credentials/deviceCodeCredential.browser.js",
|
|
15
|
+
"./dist-esm/src/credentials/interactiveBrowserCredential.js": "./dist-esm/src/credentials/interactiveBrowserCredential.browser.js",
|
|
11
16
|
"./dist/index.js": "./browser/index.js"
|
|
12
17
|
},
|
|
13
18
|
"scripts": {
|
|
@@ -17,10 +22,10 @@
|
|
|
17
22
|
"build:samples": "cd samples && tsc -p .",
|
|
18
23
|
"build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1",
|
|
19
24
|
"build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1",
|
|
20
|
-
"build:test": "
|
|
21
|
-
"build": "
|
|
25
|
+
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
|
|
26
|
+
"build": "tsc -p . && rollup -c 2>&1",
|
|
22
27
|
"check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
23
|
-
"clean": "rimraf dist dist-esm test-dist typings *.tgz *.log",
|
|
28
|
+
"clean": "rimraf dist dist-esm browser test-dist test-browser typings *.tgz *.log",
|
|
24
29
|
"format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
25
30
|
"integration-test:browser": "echo skipped",
|
|
26
31
|
"integration-test:node": "echo skipped",
|
|
@@ -32,7 +37,7 @@
|
|
|
32
37
|
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
|
|
33
38
|
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
|
|
34
39
|
"test": "npm run build:test && npm run unit-test && npm run integration-test",
|
|
35
|
-
"unit-test:browser": "
|
|
40
|
+
"unit-test:browser": "karma start",
|
|
36
41
|
"unit-test:node": "mocha test-dist/**/*.js --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
|
|
37
42
|
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
|
|
38
43
|
},
|
|
@@ -62,43 +67,56 @@
|
|
|
62
67
|
"engine": {
|
|
63
68
|
"node": ">=6.0.0"
|
|
64
69
|
},
|
|
65
|
-
"homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/
|
|
70
|
+
"homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/identity/identity",
|
|
66
71
|
"sideEffects": false,
|
|
67
72
|
"dependencies": {
|
|
68
|
-
"@azure/core-http": "
|
|
73
|
+
"@azure/core-http": "1.0.0-preview.2",
|
|
69
74
|
"events": "^3.0.0",
|
|
70
75
|
"jws": "~3.2.2",
|
|
76
|
+
"msal": "~1.0.2",
|
|
71
77
|
"qs": "6.7.0",
|
|
72
78
|
"tslib": "^1.9.3",
|
|
73
79
|
"uuid": "^3.3.2"
|
|
74
80
|
},
|
|
75
81
|
"devDependencies": {
|
|
82
|
+
"@azure/abort-controller": "1.0.0-preview.1",
|
|
76
83
|
"@types/jws": "~3.2.0",
|
|
77
84
|
"@types/mocha": "^5.2.5",
|
|
78
85
|
"@types/node": "^8.0.0",
|
|
79
86
|
"@types/qs": "~6.5.3",
|
|
80
87
|
"@types/uuid": "^3.4.3",
|
|
81
|
-
"@typescript-eslint/eslint-plugin": "
|
|
82
|
-
"@typescript-eslint/parser": "^1.
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^1.11.0",
|
|
89
|
+
"@typescript-eslint/parser": "^1.11.0",
|
|
83
90
|
"assert": "^1.4.1",
|
|
84
91
|
"cross-env": "^5.2.0",
|
|
85
92
|
"eslint": "^5.16.0",
|
|
86
93
|
"inherits": "^2.0.3",
|
|
94
|
+
"karma": "^4.0.1",
|
|
95
|
+
"karma-chrome-launcher": "^3.0.0",
|
|
96
|
+
"karma-coverage": "^1.1.2",
|
|
97
|
+
"karma-env-preprocessor": "^0.1.1",
|
|
98
|
+
"karma-json-preprocessor": "^0.3.3",
|
|
99
|
+
"karma-json-to-file-reporter": "^1.0.1",
|
|
100
|
+
"karma-junit-reporter": "^1.2.0",
|
|
101
|
+
"karma-mocha": "^1.3.0",
|
|
102
|
+
"karma-mocha-reporter": "^2.2.5",
|
|
103
|
+
"karma-remap-coverage": "^0.1.5",
|
|
87
104
|
"mocha": "^5.2.0",
|
|
88
105
|
"mocha-junit-reporter": "^1.18.0",
|
|
89
106
|
"mocha-multi": "^1.0.1",
|
|
90
107
|
"prettier": "^1.16.4",
|
|
108
|
+
"puppeteer": "^1.11.0",
|
|
91
109
|
"rimraf": "^2.6.2",
|
|
92
|
-
"rollup": "
|
|
110
|
+
"rollup": "^1.16.3",
|
|
93
111
|
"rollup-plugin-commonjs": "^10.0.0",
|
|
94
|
-
"rollup-plugin-json": "^
|
|
112
|
+
"rollup-plugin-json": "^4.0.0",
|
|
95
113
|
"rollup-plugin-multi-entry": "^2.1.0",
|
|
96
114
|
"rollup-plugin-node-resolve": "^5.0.2",
|
|
97
115
|
"rollup-plugin-replace": "^2.1.0",
|
|
98
116
|
"rollup-plugin-sourcemaps": "^0.4.2",
|
|
99
|
-
"rollup-plugin-
|
|
100
|
-
"rollup-plugin-visualizer": "^
|
|
117
|
+
"rollup-plugin-terser": "^5.1.1",
|
|
118
|
+
"rollup-plugin-visualizer": "^2.0.0",
|
|
101
119
|
"typescript": "^3.2.2",
|
|
102
|
-
"util": "^0.
|
|
120
|
+
"util": "^0.12.1"
|
|
103
121
|
}
|
|
104
122
|
}
|
package/src/client/errors.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* See the official documentation for more details:
|
|
6
6
|
*
|
|
7
7
|
* https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code#error-response-1
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* NOTE: This documentation is for v1 OAuth support but the same error
|
|
10
10
|
* response details still apply to v2.
|
|
11
11
|
*/
|
|
@@ -18,6 +18,12 @@ export interface ErrorResponse {
|
|
|
18
18
|
correlation_id?: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function isErrorResponse(errorResponse: any): errorResponse is ErrorResponse {
|
|
22
|
+
return errorResponse &&
|
|
23
|
+
typeof errorResponse.error === "string" &&
|
|
24
|
+
typeof errorResponse.error_description === "string";
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* Provides details about a failure to authenticate with Azure Active
|
|
23
29
|
* Directory. The `errorResponse` field contains more details about
|
|
@@ -27,13 +33,15 @@ export class AuthenticationError extends Error {
|
|
|
27
33
|
public readonly statusCode: number;
|
|
28
34
|
public readonly errorResponse: ErrorResponse;
|
|
29
35
|
|
|
30
|
-
constructor(statusCode: number, errorBody: string | undefined | null) {
|
|
36
|
+
constructor(statusCode: number, errorBody: object | string | undefined | null) {
|
|
31
37
|
let errorResponse = {
|
|
32
38
|
error: "unknown",
|
|
33
39
|
error_description: "An unknown error occurred and no additional details are available."
|
|
34
40
|
};
|
|
35
41
|
|
|
36
|
-
if (errorBody) {
|
|
42
|
+
if (isErrorResponse(errorBody)) {
|
|
43
|
+
errorResponse = errorBody;
|
|
44
|
+
} else if (typeof errorBody === "string") {
|
|
37
45
|
try {
|
|
38
46
|
// Most error responses will contain JSON-formatted error details
|
|
39
47
|
// in the response body
|