Update Authenticator implementation in KeyVaultFactory (#23)

* Update Authenticator implementation in KeyVaultFactory

* Return promise early
This commit is contained in:
Kamil Pajdzik 2018-10-02 10:23:15 -07:00 коммит произвёл GitHub
Родитель ac18671465
Коммит 4745cab4ce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 13 добавлений и 13 удалений

Просмотреть файл

@ -39,21 +39,21 @@ function _convert(credentials: MSITokenCredentials): MSITokenCredentials {
}
function _createAuthenticatorMapper(credentials: MSITokenCredentials): Authenticator {
return function (challenge: any, callback: (error?: Error, authorizationValue?: string) => void) {
return (challenge: any) => new Promise((resolve, reject) => {
// Function to take token Response and format a authorization value
const _formAuthorizationValue = (err: Error, tokenResponse: TokenResponse | ErrorResponse) => {
if (err) {
return callback(err, undefined);
return reject(err);
}
if (tokenResponse.error) {
return callback(tokenResponse.error, undefined);
return reject(tokenResponse.error);
}
tokenResponse = tokenResponse as TokenResponse;
// Calculate the value to be set in the request's Authorization header and resume the call.
const authorizationValue = tokenResponse.tokenType + " " + tokenResponse.accessToken;
return callback(undefined, authorizationValue);
return resolve(authorizationValue);
};
// Create a new authentication context.
@ -72,8 +72,8 @@ function _createAuthenticatorMapper(credentials: MSITokenCredentials): Authentic
} else if (credentials instanceof MSITokenCredentials) {
return credentials.getToken();
} else {
callback(new Error("credentials must be one of: ApplicationTokenCredentials, UserTokenCredentials, " +
"DeviceTokenCredentials, MSITokenCredentials"), undefined);
return reject(new Error("credentials must be one of: ApplicationTokenCredentials, UserTokenCredentials, " +
"DeviceTokenCredentials, MSITokenCredentials"));
}
};
});
}

10
package-lock.json сгенерированный
Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "ms-rest-nodeauth",
"version": "0.5.3",
"version": "0.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -1181,11 +1181,11 @@
"integrity": "sha512-nM/wIKKo0HcG1Q9+9yJ7uevnSASIuDVlUI2rOOSL5bJDOACn3sKq4fTVeSFBOn277mZ64U+YqG0MxZMA4TIRfw=="
},
"ms-rest-js": {
"version": "0.22.426",
"resolved": "https://registry.npmjs.org/ms-rest-js/-/ms-rest-js-0.22.426.tgz",
"integrity": "sha512-6x7BNpQNIQ5nUNTROCa26bCWmtMYneoVSXXrregdgmZx+JPrKj/wdmGcX2odaelxoskAPLPmsp+5bf3ikiB5gA==",
"version": "0.22.434",
"resolved": "https://registry.npmjs.org/ms-rest-js/-/ms-rest-js-0.22.434.tgz",
"integrity": "sha512-clxRfE0SnYegdWZoFMWcp9mq9ru3gRnJxa1R58jYApKh8qjrSO56PVOhdTum/qaEMy+LiBszaPCCO0+UrYYCDw==",
"requires": {
"@types/express": "^4.11.1",
"@types/express": "^4.16.0",
"@types/form-data": "^2.2.1",
"@types/node": "^9.4.6",
"@types/uuid": "^3.4.3",

Просмотреть файл

@ -30,7 +30,7 @@
"dependencies": {
"adal-node": "^0.1.22",
"ms-rest-azure-env": "^0.1.1",
"ms-rest-js": "^0.22.426"
"ms-rest-js": "^0.22.434"
},
"license": "MIT",
"devDependencies": {