@aws-amplify/auth
Advanced tools
Comparing version 1.0.5-unstable.4 to 1.0.5-unstable.5
@@ -6,10 +6,13 @@ # Change Log | ||
<a name="1.0.5-unstable.4"></a> | ||
## [1.0.5-unstable.4](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.5-unstable.3...@aws-amplify/auth@1.0.5-unstable.4) (2018-07-31) | ||
<a name="1.0.5-unstable.5"></a> | ||
## [1.0.5-unstable.5](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.5-unstable.3...@aws-amplify/auth@1.0.5-unstable.5) (2018-08-06) | ||
### Bug Fixes | ||
* **@aws-amplify/auth:** fix getPreferredMfa and setPreferredMFA ([c5785b0](https://github.com/aws/aws-amplify/commit/c5785b0)) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.5-unstable.3"></a> | ||
@@ -16,0 +19,0 @@ ## [1.0.5-unstable.3](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.5-unstable.2...@aws-amplify/auth@1.0.5-unstable.3) (2018-07-31) |
@@ -83,2 +83,4 @@ import { AuthOptions, FederatedResponse, ConfirmSignUpOptions } from './types'; | ||
getPreferredMFA(user: any): Promise<string>; | ||
private _getMfaTypeFromUserData; | ||
private _getUserData; | ||
/** | ||
@@ -93,2 +95,3 @@ * set preferred MFA method | ||
* diable SMS | ||
* @deprecated | ||
* @param {CognitoUser} user - the current user | ||
@@ -100,2 +103,3 @@ * @return - A promise resolves is success | ||
* enable SMS | ||
* @deprecated | ||
* @param {CognitoUser} user - the current user | ||
@@ -102,0 +106,0 @@ * @return - A promise resolves is success |
251
lib/Auth.js
@@ -459,5 +459,7 @@ "use strict"; | ||
rej(err); | ||
return; | ||
} | ||
logger.debug('get MFA options success', mfaOptions); | ||
res(mfaOptions); | ||
return; | ||
}); | ||
@@ -471,2 +473,3 @@ }); | ||
AuthClass.prototype.getPreferredMFA = function (user) { | ||
var that = this; | ||
return new Promise(function (res, rej) { | ||
@@ -477,8 +480,64 @@ user.getUserData(function (err, data) { | ||
rej(err); | ||
return; | ||
} | ||
var preferredMFA = data.PreferredMfaSetting || 'NOMFA'; | ||
res(preferredMFA); | ||
var mfaType = that._getMfaTypeFromUserData(data); | ||
if (!mfaType) { | ||
rej('invalid MFA Type'); | ||
return; | ||
} | ||
else { | ||
res(mfaType); | ||
return; | ||
} | ||
}); | ||
}); | ||
}; | ||
AuthClass.prototype._getMfaTypeFromUserData = function (data) { | ||
var ret = null; | ||
var preferredMFA = data.PreferredMfaSetting; | ||
// if the user has used Auth.setPreferredMFA() to setup the mfa type | ||
// then the "PreferredMfaSetting" would exist in the response | ||
if (preferredMFA) { | ||
ret = preferredMFA; | ||
} | ||
else { | ||
// if mfaList exists but empty, then its noMFA | ||
var mfaList = data.UserMFASettingList; | ||
if (!mfaList) { | ||
// if SMS was enabled by using Auth.enableSMS(), | ||
// the response would contain MFAOptions | ||
// as for now Cognito only supports for SMS, so we will say it is 'SMS_MFA' | ||
// if it does not exist, then it should be NOMFA | ||
var MFAOptions = data.MFAOptions; | ||
if (MFAOptions) { | ||
ret = 'SMS_MFA'; | ||
} | ||
else { | ||
ret = 'NOMFA'; | ||
} | ||
} | ||
else if (mfaList.length === 0) { | ||
ret = 'NOMFA'; | ||
} | ||
else { | ||
logger.debug('invalid case for getPreferredMFA', data); | ||
} | ||
} | ||
return ret; | ||
}; | ||
AuthClass.prototype._getUserData = function (user) { | ||
return new Promise(function (res, rej) { | ||
user.getUserData(function (err, data) { | ||
if (err) { | ||
logger.debug('getting user data failed', err); | ||
rej(err); | ||
return; | ||
} | ||
else { | ||
res(data); | ||
return; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
@@ -492,72 +551,87 @@ * set preferred MFA method | ||
return __awaiter(this, void 0, void 0, function () { | ||
var smsMfaSettings, totpMfaSettings, that, TOTP_NOT_VERIFED, TOTP_NOT_SETUP; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getPreferredMFA(user)]; | ||
var userData, smsMfaSettings, totpMfaSettings, _a, mfaList, currentMFAType, that; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this._getUserData(user)]; | ||
case 1: | ||
smsMfaSettings = (_a.sent()) === 'SMS_MFA' ? | ||
{ PreferredMfa: false, Enabled: false } : null; | ||
userData = _b.sent(); | ||
smsMfaSettings = null; | ||
totpMfaSettings = null; | ||
_a = mfaMethod; | ||
switch (_a) { | ||
case 'TOTP' || 'SOFTWARE_TOKEN_MFA': return [3 /*break*/, 2]; | ||
case 'SMS' || 'SMS_MFA': return [3 /*break*/, 3]; | ||
case 'NOMFA': return [3 /*break*/, 4]; | ||
} | ||
return [3 /*break*/, 6]; | ||
case 2: | ||
totpMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
PreferredMfa: true, | ||
Enabled: true | ||
}; | ||
switch (mfaMethod) { | ||
case 'TOTP': | ||
totpMfaSettings = { | ||
PreferredMfa: true, | ||
Enabled: true | ||
}; | ||
break; | ||
case 'SMS': | ||
smsMfaSettings = { | ||
PreferredMfa: true, | ||
Enabled: true | ||
}; | ||
break; | ||
case 'NOMFA': | ||
break; | ||
default: | ||
logger.debug('no validmfa method provided'); | ||
return [2 /*return*/, Promise.reject('no validmfa method provided')]; | ||
return [3 /*break*/, 7]; | ||
case 3: | ||
smsMfaSettings = { | ||
PreferredMfa: true, | ||
Enabled: true | ||
}; | ||
return [3 /*break*/, 7]; | ||
case 4: | ||
mfaList = userData['UserMFASettingList']; | ||
return [4 /*yield*/, this._getMfaTypeFromUserData(userData)]; | ||
case 5: | ||
currentMFAType = _b.sent(); | ||
if (currentMFAType === 'NOMFA') { | ||
return [2 /*return*/, Promise.resolve('No change for mfa type')]; | ||
} | ||
else if (currentMFAType === 'SMS_MFA') { | ||
smsMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
}; | ||
} | ||
else if (currentMFAType === 'SOFTWARE_TOKEN_MFA') { | ||
totpMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
}; | ||
} | ||
else { | ||
return [2 /*return*/, Promise.reject('invalid MFA type')]; | ||
} | ||
// if there is a UserMFASettingList in the response | ||
// we need to disable every mfa type in that list | ||
if (mfaList && mfaList.length !== 0) { | ||
// to disable SMS or TOTP if exists in that list | ||
mfaList.forEach(function (mfaType) { | ||
if (mfaType === 'SMS_MFA') { | ||
smsMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
}; | ||
} | ||
else if (mfaType === 'SOFTWARE_TOKEN_MFA') { | ||
totpMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
}; | ||
} | ||
}); | ||
} | ||
return [3 /*break*/, 7]; | ||
case 6: | ||
logger.debug('no validmfa method provided'); | ||
return [2 /*return*/, Promise.reject('no validmfa method provided')]; | ||
case 7: | ||
that = this; | ||
TOTP_NOT_VERIFED = 'User has not verified software token mfa'; | ||
TOTP_NOT_SETUP = 'User has not set up software token mfa'; | ||
return [2 /*return*/, new Promise(function (res, rej) { | ||
user.setUserMfaPreference(smsMfaSettings, totpMfaSettings, function (err, result) { | ||
if (err) { | ||
// if totp not setup or verified and user want to set it, return error | ||
// otherwise igonre it | ||
if (err.message === TOTP_NOT_SETUP || err.message === TOTP_NOT_VERIFED) { | ||
if (mfaMethod === 'SMS') { | ||
that.enableSMS(user).then(function (data) { | ||
logger.debug('Set user mfa success', data); | ||
res(data); | ||
}).catch(function (err) { | ||
logger.debug('Set user mfa preference error', err); | ||
rej(err); | ||
}); | ||
} | ||
else if (mfaMethod === 'NOMFA') { | ||
// diable sms | ||
that.disableSMS(user).then(function (data) { | ||
logger.debug('Set user mfa success', data); | ||
res(data); | ||
}).catch(function (err) { | ||
logger.debug('Set user mfa preference error', err); | ||
rej(err); | ||
}); | ||
} | ||
else { | ||
logger.debug('Set user mfa preference error', err); | ||
rej(err); | ||
} | ||
} | ||
else { | ||
logger.debug('Set user mfa preference error', err); | ||
rej(err); | ||
} | ||
logger.debug('Set user mfa preference error', err); | ||
rej(err); | ||
return; | ||
} | ||
logger.debug('Set user mfa success', result); | ||
res(result); | ||
return; | ||
}); | ||
@@ -571,2 +645,3 @@ })]; | ||
* diable SMS | ||
* @deprecated | ||
* @param {CognitoUser} user - the current user | ||
@@ -581,5 +656,7 @@ * @return - A promise resolves is success | ||
rej(err); | ||
return; | ||
} | ||
logger.debug('disable mfa succeed', data); | ||
res(data); | ||
return; | ||
}); | ||
@@ -590,2 +667,3 @@ }); | ||
* enable SMS | ||
* @deprecated | ||
* @param {CognitoUser} user - the current user | ||
@@ -600,5 +678,7 @@ * @return - A promise resolves is success | ||
rej(err); | ||
return; | ||
} | ||
logger.debug('enable mfa succeed', data); | ||
res(data); | ||
return; | ||
}); | ||
@@ -618,2 +698,3 @@ }); | ||
rej(err); | ||
return; | ||
}, | ||
@@ -623,2 +704,3 @@ associateSecretCode: function (secretCode) { | ||
res(secretCode); | ||
return; | ||
} | ||
@@ -641,2 +723,3 @@ }); | ||
rej(err); | ||
return; | ||
}, | ||
@@ -646,2 +729,3 @@ onSuccess: function (data) { | ||
res(data); | ||
return; | ||
} | ||
@@ -801,5 +885,7 @@ }); | ||
reject(err); | ||
return; | ||
} | ||
else { | ||
resolve(result); | ||
return; | ||
} | ||
@@ -995,2 +1081,3 @@ }); | ||
reject(err); | ||
return; | ||
} | ||
@@ -1000,2 +1087,3 @@ else { | ||
resolve(session); | ||
return; | ||
} | ||
@@ -1048,4 +1136,10 @@ }); | ||
user.getAttributeVerificationCode(attr, { | ||
onSuccess: function (data) { resolve(data); }, | ||
onFailure: function (err) { reject(err); } | ||
onSuccess: function (data) { | ||
resolve(data); | ||
return; | ||
}, | ||
onFailure: function (err) { | ||
reject(err); | ||
return; | ||
} | ||
}); | ||
@@ -1067,4 +1161,10 @@ }); | ||
user.verifyAttribute(attr, code, { | ||
onSuccess: function (data) { resolve(data); }, | ||
onFailure: function (err) { reject(err); } | ||
onSuccess: function (data) { | ||
resolve(data); | ||
return; | ||
}, | ||
onFailure: function (err) { | ||
reject(err); | ||
return; | ||
} | ||
}); | ||
@@ -1181,5 +1281,7 @@ }); | ||
reject(err); | ||
return; | ||
} | ||
else { | ||
resolve(data); | ||
return; | ||
} | ||
@@ -1205,9 +1307,14 @@ }); | ||
user.forgotPassword({ | ||
onSuccess: function () { resolve(); }, | ||
onSuccess: function () { | ||
resolve(); | ||
return; | ||
}, | ||
onFailure: function (err) { | ||
logger.debug('forgot password failure', err); | ||
reject(err); | ||
return; | ||
}, | ||
inputVerificationCode: function (data) { | ||
resolve(data); | ||
return; | ||
} | ||
@@ -1240,4 +1347,10 @@ }); | ||
user.confirmPassword(code, password, { | ||
onSuccess: function () { resolve(); }, | ||
onFailure: function (err) { reject(err); } | ||
onSuccess: function () { | ||
resolve(); | ||
return; | ||
}, | ||
onFailure: function (err) { | ||
reject(err); | ||
return; | ||
} | ||
}); | ||
@@ -1322,4 +1435,6 @@ }); | ||
res(cred); | ||
return; | ||
}).catch(function (e) { | ||
rej(e); | ||
return; | ||
}); | ||
@@ -1326,0 +1441,0 @@ }); |
{ | ||
"name": "@aws-amplify/auth", | ||
"version": "1.0.5-unstable.4", | ||
"version": "1.0.5-unstable.5", | ||
"description": "Auth category of aws-amplify", | ||
@@ -56,3 +56,3 @@ "main": "./lib/index.js", | ||
"amazon-cognito-auth-js": "^1.1.9", | ||
"amazon-cognito-identity-js": "^2.0.20-unstable.4" | ||
"amazon-cognito-identity-js": "^2.0.20-unstable.5" | ||
}, | ||
@@ -59,0 +59,0 @@ "jest": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32820
5768640