@aws-amplify/auth
Advanced tools
Comparing version 1.0.3 to 1.0.4-unstable.0
141
CHANGELOG.md
@@ -6,4 +6,4 @@ # Change Log | ||
<a name="1.0.3"></a> | ||
## [1.0.3](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.2...@aws-amplify/auth@1.0.3) (2018-07-27) | ||
<a name="1.0.4-unstable.0"></a> | ||
## [1.0.4-unstable.0](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.14...@aws-amplify/auth@1.0.4-unstable.0) (2018-07-27) | ||
@@ -15,2 +15,139 @@ | ||
<a name="1.0.3-unstable.15"></a> | ||
## [1.0.3-unstable.15](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.14...@aws-amplify/auth@1.0.3-unstable.15) (2018-07-27) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.14"></a> | ||
## [1.0.3-unstable.14](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.13...@aws-amplify/auth@1.0.3-unstable.14) (2018-07-27) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.13"></a> | ||
## [1.0.3-unstable.13](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.12...@aws-amplify/auth@1.0.3-unstable.13) (2018-07-26) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.12"></a> | ||
## [1.0.3-unstable.12](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.11...@aws-amplify/auth@1.0.3-unstable.12) (2018-07-26) | ||
### Bug Fixes | ||
* **@aws-amplify/auth:** currentAuthenticatedUser throws error when the user is disabled/deleted ([1b09e2f](https://github.com/aws/aws-amplify/commit/1b09e2f)) | ||
<a name="1.0.3-unstable.11"></a> | ||
## [1.0.3-unstable.11](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.10...@aws-amplify/auth@1.0.3-unstable.11) (2018-07-26) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.10"></a> | ||
## [1.0.3-unstable.10](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.9...@aws-amplify/auth@1.0.3-unstable.10) (2018-07-26) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.9"></a> | ||
## [1.0.3-unstable.9](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.8...@aws-amplify/auth@1.0.3-unstable.9) (2018-07-25) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.8"></a> | ||
## [1.0.3-unstable.8](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.7...@aws-amplify/auth@1.0.3-unstable.8) (2018-07-25) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.7"></a> | ||
## [1.0.3-unstable.7](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.6...@aws-amplify/auth@1.0.3-unstable.7) (2018-07-25) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.6"></a> | ||
## [1.0.3-unstable.6](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.5...@aws-amplify/auth@1.0.3-unstable.6) (2018-07-24) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.5"></a> | ||
## [1.0.3-unstable.5](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.4...@aws-amplify/auth@1.0.3-unstable.5) (2018-07-23) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.4"></a> | ||
## [1.0.3-unstable.4](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.3...@aws-amplify/auth@1.0.3-unstable.4) (2018-07-23) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.3"></a> | ||
## [1.0.3-unstable.3](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.2...@aws-amplify/auth@1.0.3-unstable.3) (2018-07-23) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.2"></a> | ||
## [1.0.3-unstable.2](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.1...@aws-amplify/auth@1.0.3-unstable.2) (2018-07-20) | ||
### Bug Fixes | ||
* **@aws-amplify/auth:** give the option to set Federated Identity Pool region ([f370b33](https://github.com/aws/aws-amplify/commit/f370b33)) | ||
<a name="1.0.3-unstable.1"></a> | ||
## [1.0.3-unstable.1](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.3-unstable.0...@aws-amplify/auth@1.0.3-unstable.1) (2018-07-20) | ||
**Note:** Version bump only for package @aws-amplify/auth | ||
<a name="1.0.3-unstable.0"></a> | ||
## [1.0.3-unstable.0](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.2...@aws-amplify/auth@1.0.3-unstable.0) (2018-07-20) | ||
### Bug Fixes | ||
* **@aws-amplify/auth:** fix issue [#1165](https://github.com/aws/aws-amplify/issues/1165) and adds an api to get current preferred mfa type ([6f8a100](https://github.com/aws/aws-amplify/commit/6f8a100)) | ||
<a name="1.0.2"></a> | ||
@@ -17,0 +154,0 @@ ## [1.0.2](https://github.com/aws/aws-amplify/compare/@aws-amplify/auth@1.0.2-unstable.1...@aws-amplify/auth@1.0.2) (2018-07-19) |
@@ -72,2 +72,4 @@ import { AuthOptions, FederatedResponse, ConfirmSignUpOptions } from './types'; | ||
* get user current preferred mfa option | ||
* this method doesn't work with totp, we need to deprecate it. | ||
* @deprecated | ||
* @param {CognitoUser} user - the current user | ||
@@ -78,2 +80,7 @@ * @return - A promise resolves the current preferred mfa option if success | ||
/** | ||
* get preferred mfa method | ||
* @param {CognitoUser} user - the current cognito user | ||
*/ | ||
getPreferredMFA(user: any): Promise<string>; | ||
/** | ||
* set preferred MFA method | ||
@@ -80,0 +87,0 @@ * @param {CognitoUser} user - the current Cognito user |
231
lib/Auth.js
@@ -89,3 +89,3 @@ "use strict"; | ||
this._config = conf; | ||
var _a = this._config, userPoolId = _a.userPoolId, userPoolWebClientId = _a.userPoolWebClientId, cookieStorage = _a.cookieStorage, oauth = _a.oauth, region = _a.region, identityPoolId = _a.identityPoolId, mandatorySignIn = _a.mandatorySignIn, refreshHandlers = _a.refreshHandlers, storage = _a.storage; | ||
var _a = this._config, userPoolId = _a.userPoolId, userPoolWebClientId = _a.userPoolWebClientId, cookieStorage = _a.cookieStorage, oauth = _a.oauth, region = _a.region, identityPoolId = _a.identityPoolId, mandatorySignIn = _a.mandatorySignIn, refreshHandlers = _a.refreshHandlers, storage = _a.storage, identityPoolRegion = _a.identityPoolRegion; | ||
if (!this._config.storage) { | ||
@@ -116,3 +116,3 @@ // backward compatbility | ||
mandatorySignIn: mandatorySignIn, | ||
region: region, | ||
region: identityPoolRegion || region, | ||
userPoolId: userPoolId, | ||
@@ -450,2 +450,4 @@ identityPoolId: identityPoolId, | ||
* get user current preferred mfa option | ||
* this method doesn't work with totp, we need to deprecate it. | ||
* @deprecated | ||
* @param {CognitoUser} user - the current user | ||
@@ -467,2 +469,18 @@ * @return - A promise resolves the current preferred mfa option if success | ||
/** | ||
* get preferred mfa method | ||
* @param {CognitoUser} user - the current cognito user | ||
*/ | ||
AuthClass.prototype.getPreferredMFA = function (user) { | ||
return new Promise(function (res, rej) { | ||
user.getUserData(function (err, data) { | ||
if (err) { | ||
logger.debug('getting preferred mfa failed', err); | ||
rej('getting preferred mfa failed: ' + err); | ||
} | ||
var preferredMFA = data.PreferredMfaSetting || 'NOMFA'; | ||
res(preferredMFA); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* set preferred MFA method | ||
@@ -474,66 +492,76 @@ * @param {CognitoUser} user - the current Cognito user | ||
AuthClass.prototype.setPreferredMFA = function (user, mfaMethod) { | ||
var smsMfaSettings = null; | ||
var totpMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
}; | ||
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 Promise.reject('no validmfa method provided'); | ||
} | ||
var that = this; | ||
var TOTP_NOT_VERIFED = 'User has not verified software token mfa'; | ||
var TOTP_NOT_SETUP = 'User has not set up software token mfa'; | ||
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); | ||
}); | ||
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)]; | ||
case 1: | ||
smsMfaSettings = (_a.sent()) === 'SMS_MFA' ? | ||
{ PreferredMfa: false, Enabled: false } : null; | ||
totpMfaSettings = { | ||
PreferredMfa: false, | ||
Enabled: false | ||
}; | ||
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')]; | ||
} | ||
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); | ||
} | ||
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 success', result); | ||
res(result); | ||
}); | ||
})]; | ||
} | ||
logger.debug('Set user mfa success', result); | ||
res(result); | ||
}); | ||
@@ -841,9 +869,30 @@ }); | ||
} | ||
// refresh the session if the session expired. | ||
user.getSession(function (err, session) { | ||
if (err) { | ||
logger.debug('Failed to get the user session', err); | ||
rej(err); | ||
return; | ||
} | ||
else { | ||
res(user); | ||
}); | ||
// get user data from Cognito, also to make sure the user is still valid | ||
user.getUserData(function (err, data) { | ||
if (err) { | ||
logger.debug('getting user data failed', err); | ||
rej(err); | ||
return; | ||
} | ||
var preferredMFA = data.PreferredMfaSetting || 'NOMFA'; | ||
var attributeList = []; | ||
for (var i = 0; i < data.UserAttributes.length; i++) { | ||
var attribute = { | ||
Name: data.UserAttributes[i].Name, | ||
Value: data.UserAttributes[i].Value, | ||
}; | ||
var userAttribute = new amazon_cognito_identity_js_1.CognitoUserAttribute(attribute); | ||
attributeList.push(userAttribute); | ||
} | ||
var attributes = _this.attributesToObject(attributeList); | ||
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA }); | ||
res(user); | ||
}); | ||
@@ -859,5 +908,5 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var federatedUser, user, e_5, attributes, _a, e_6; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
var federatedUser, user, e_5; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
@@ -879,30 +928,16 @@ logger.debug('getting current authenticted user'); | ||
user = null; | ||
_b.label = 2; | ||
_a.label = 2; | ||
case 2: | ||
_b.trys.push([2, 4, , 5]); | ||
_a.trys.push([2, 4, , 5]); | ||
return [4 /*yield*/, this.currentUserPoolUser()]; | ||
case 3: | ||
user = _b.sent(); | ||
user = _a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
e_5 = _b.sent(); | ||
throw 'not authenticated'; | ||
e_5 = _a.sent(); | ||
logger.debug('The user is not authenticated by the error', e_5); | ||
throw e_5; | ||
case 5: | ||
attributes = {}; | ||
_b.label = 6; | ||
case 6: | ||
_b.trys.push([6, 8, 9, 10]); | ||
_a = this.attributesToObject; | ||
return [4 /*yield*/, this.userAttributes(user)]; | ||
case 7: | ||
attributes = _a.apply(this, [_b.sent()]); | ||
return [3 /*break*/, 10]; | ||
case 8: | ||
e_6 = _b.sent(); | ||
logger.debug('cannot get user attributes'); | ||
return [3 /*break*/, 10]; | ||
case 9: | ||
this.user = Object.assign(user, { attributes: attributes }); | ||
this.user = user; | ||
return [2 /*return*/, this.user]; | ||
case 10: return [2 /*return*/]; | ||
} | ||
@@ -1051,3 +1086,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_7, user, that; | ||
var e_6, user, that; | ||
var _this = this; | ||
@@ -1063,3 +1098,3 @@ return __generator(this, function (_a) { | ||
case 2: | ||
e_7 = _a.sent(); | ||
e_6 = _a.sent(); | ||
logger.debug('failed to clear cached items'); | ||
@@ -1083,3 +1118,3 @@ return [3 /*break*/, 3]; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var e_8; | ||
var e_7; | ||
return __generator(this, function (_a) { | ||
@@ -1094,4 +1129,4 @@ switch (_a.label) { | ||
case 2: | ||
e_8 = _a.sent(); | ||
logger.debug('cannot load guest credentials for unauthenticated user', e_8); | ||
e_7 = _a.sent(); | ||
logger.debug('cannot load guest credentials for unauthenticated user', e_7); | ||
return [3 /*break*/, 4]; | ||
@@ -1210,3 +1245,3 @@ case 3: | ||
return __awaiter(this, void 0, void 0, function () { | ||
var source, user, attributes, userAttrs, credentials, e_9, info, err_1, user; | ||
var source, user, attributes, userAttrs, credentials, e_8, info, err_1, user; | ||
return __generator(this, function (_a) { | ||
@@ -1240,4 +1275,4 @@ switch (_a.label) { | ||
case 6: | ||
e_9 = _a.sent(); | ||
logger.debug('Failed to retrieve credentials while getting current user info', e_9); | ||
e_8 = _a.sent(); | ||
logger.debug('Failed to retrieve credentials while getting current user info', e_8); | ||
return [3 /*break*/, 7]; | ||
@@ -1244,0 +1279,0 @@ case 7: |
@@ -29,6 +29,7 @@ import { ICookieStorageData, ICognitoStorage } from "amazon-cognito-identity-js"; | ||
authenticationFlowType?: string; | ||
identityPoolRegion?: string; | ||
} | ||
/** | ||
* Details for multi-factor authentication | ||
*/ | ||
* Details for multi-factor authentication | ||
*/ | ||
export interface MfaRequiredDetails { | ||
@@ -35,0 +36,0 @@ challengeName: any; |
{ | ||
"name": "@aws-amplify/auth", | ||
"version": "1.0.3", | ||
"version": "1.0.4-unstable.0", | ||
"description": "Auth category of aws-amplify", | ||
@@ -53,6 +53,6 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@aws-amplify/cache": "^1.0.2", | ||
"@aws-amplify/core": "^1.0.2", | ||
"@aws-amplify/cache": "^1.0.3-unstable.0", | ||
"@aws-amplify/core": "^1.0.3-unstable.0", | ||
"amazon-cognito-auth-js": "^1.1.9", | ||
"amazon-cognito-identity-js": "^2.0.17" | ||
"amazon-cognito-identity-js": "^2.0.18-unstable.0" | ||
}, | ||
@@ -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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
5806152
32688
1