Comparing version 1.4.0 to 1.4.1
@@ -0,1 +1,2 @@ | ||
import AWS = require('aws-sdk'); | ||
/** | ||
@@ -63,2 +64,31 @@ * A wrapper for AWS Cognito. | ||
deleteUser(email: string, cognitoUserPoolId: string): Promise<void>; | ||
/** | ||
* Sign in a user of a specific pool through username and password. | ||
* @param {string} email the email used as login | ||
* @param {string} password the password to authenticate the user | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @param {string} cognitoUserPoolClientId the client id to access the user pool | ||
* (`ADMIN_NO_SRP_AUTH` must be enabled) | ||
* @return {Promise<AWS.CognitoIdentityServiceProvider.AuthenticationResultType>} | ||
*/ | ||
signIn(email: string, password: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<AWS.CognitoIdentityServiceProvider.AuthenticationResultType>; | ||
/** | ||
* Change the email address (== username) associated to a user. | ||
* @param {string} email the email currently used to login | ||
* @param {string} newEmail the new email to set | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @return {Promise<void>} | ||
*/ | ||
updateEmail(email: string, newEmail: string, cognitoUserPoolId: string): Promise<void>; | ||
/** | ||
* Change the password to sign in for a user. | ||
* @param {string} email the email currently used to login | ||
* @param {string} oldPassword the password to authenticate the user | ||
* @param {string} newPassword the new password to set | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @param {string} cognitoUserPoolClientId the client id to access the user pool | ||
* (`ADMIN_NO_SRP_AUTH` must be enabled) | ||
* @return {Promise<void>} | ||
*/ | ||
updatePassword(email: string, oldPassword: string, newPassword: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<void>; | ||
} |
@@ -178,3 +178,91 @@ "use strict"; | ||
} | ||
/** | ||
* Sign in a user of a specific pool through username and password. | ||
* @param {string} email the email used as login | ||
* @param {string} password the password to authenticate the user | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @param {string} cognitoUserPoolClientId the client id to access the user pool | ||
* (`ADMIN_NO_SRP_AUTH` must be enabled) | ||
* @return {Promise<AWS.CognitoIdentityServiceProvider.AuthenticationResultType>} | ||
*/ | ||
signIn(email, password, cognitoUserPoolId, cognitoUserPoolClientId) { | ||
return new Promise((resolve, reject) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminInitiateAuth({ | ||
UserPoolId: cognitoUserPoolId, | ||
ClientId: cognitoUserPoolClientId, | ||
AuthFlow: 'ADMIN_NO_SRP_AUTH', | ||
AuthParameters: { 'USERNAME': email, 'PASSWORD': password } | ||
}, (err, data) => { | ||
IdeaX.logger('COGNITO SIGN IN', err, data ? JSON.stringify(data.toString) : null); | ||
if (err || !data.AuthenticationResult) | ||
reject(err); | ||
else | ||
resolve(data.AuthenticationResult); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Change the email address (== username) associated to a user. | ||
* @param {string} email the email currently used to login | ||
* @param {string} newEmail the new email to set | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @return {Promise<void>} | ||
*/ | ||
updateEmail(email, newEmail, cognitoUserPoolId) { | ||
return new Promise((resolve, reject) => { | ||
if (IdeaX.isEmpty(newEmail, 'email')) | ||
return reject(new Error('E.COGNITO.INVALID_NEW_EMAIL')); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminUpdateUserAttributes({ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: [ | ||
{ Name: 'email', Value: newEmail }, | ||
{ Name: 'email_verified', Value: 'true' } | ||
] | ||
}, (err, _) => { | ||
IdeaX.logger('COGNITO UPDATE EMAIL', err, newEmail); | ||
if (err) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Change the password to sign in for a user. | ||
* @param {string} email the email currently used to login | ||
* @param {string} oldPassword the password to authenticate the user | ||
* @param {string} newPassword the new password to set | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @param {string} cognitoUserPoolClientId the client id to access the user pool | ||
* (`ADMIN_NO_SRP_AUTH` must be enabled) | ||
* @return {Promise<void>} | ||
*/ | ||
updatePassword(email, oldPassword, newPassword, cognitoUserPoolId, cognitoUserPoolClientId) { | ||
return new Promise((resolve, reject) => { | ||
if (newPassword.length < 8) | ||
return reject(new Error('E.COGNITO.INVALID_NEW_PASSWORD')); | ||
// get a token to run the password change | ||
this.signIn(email, oldPassword, cognitoUserPoolId, cognitoUserPoolClientId) | ||
.then((data) => { | ||
// request the password change | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.changePassword({ | ||
AccessToken: data.AccessToken, | ||
PreviousPassword: oldPassword, | ||
ProposedPassword: newPassword | ||
}, (err, _) => { | ||
IdeaX.logger('COGNITO UPDATE PASSWORD', err, '*******'); | ||
if (err) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
}) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
} | ||
exports.Cognito = Cognito; |
var typedoc = typedoc || {}; | ||
typedoc.search = typedoc.search || {}; | ||
typedoc.search.data = {"kinds":{"128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","262144":"Accessor"},"rows":[{"id":0,"kind":128,"name":"Cognito","url":"classes/cognito.html","classes":"tsd-kind-class"},{"id":1,"kind":512,"name":"constructor","url":"classes/cognito.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"Cognito"},{"id":2,"kind":2048,"name":"getUserByClaims","url":"classes/cognito.html#getuserbyclaims","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":3,"kind":2048,"name":"getUserByEmail","url":"classes/cognito.html#getuserbyemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":4,"kind":2048,"name":"getUserBySub","url":"classes/cognito.html#getuserbysub","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":5,"kind":2048,"name":"createUser","url":"classes/cognito.html#createuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":6,"kind":2048,"name":"resendPassword","url":"classes/cognito.html#resendpassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":7,"kind":2048,"name":"deleteUser","url":"classes/cognito.html#deleteuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":8,"kind":128,"name":"DynamoDB","url":"classes/dynamodb.html","classes":"tsd-kind-class"},{"id":9,"kind":512,"name":"constructor","url":"classes/dynamodb.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"DynamoDB"},{"id":10,"kind":2048,"name":"IUID","url":"classes/dynamodb.html#iuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":11,"kind":2048,"name":"getAtomicCounterByKey","url":"classes/dynamodb.html#getatomiccounterbykey","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":12,"kind":2048,"name":"get","url":"classes/dynamodb.html#get","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":13,"kind":2048,"name":"put","url":"classes/dynamodb.html#put","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":14,"kind":2048,"name":"update","url":"classes/dynamodb.html#update","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":15,"kind":2048,"name":"delete","url":"classes/dynamodb.html#delete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":16,"kind":2048,"name":"batchGet","url":"classes/dynamodb.html#batchget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":17,"kind":2048,"name":"batchPut","url":"classes/dynamodb.html#batchput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":18,"kind":2048,"name":"batchDelete","url":"classes/dynamodb.html#batchdelete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":19,"kind":2048,"name":"query","url":"classes/dynamodb.html#query","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":20,"kind":2048,"name":"scan","url":"classes/dynamodb.html#scan","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":21,"kind":256,"name":"RequestLog","url":"interfaces/requestlog.html","classes":"tsd-kind-interface"},{"id":22,"kind":1024,"name":"key","url":"interfaces/requestlog.html#key","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":23,"kind":1024,"name":"at","url":"interfaces/requestlog.html#at","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":24,"kind":1024,"name":"expiresAt","url":"interfaces/requestlog.html#expiresat","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":25,"kind":1024,"name":"userId","url":"interfaces/requestlog.html#userid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":26,"kind":1024,"name":"resource","url":"interfaces/requestlog.html#resource","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":27,"kind":1024,"name":"resourceId","url":"interfaces/requestlog.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":28,"kind":1024,"name":"method","url":"interfaces/requestlog.html#method","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":29,"kind":1024,"name":"action","url":"interfaces/requestlog.html#action","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":30,"kind":1024,"name":"requestSucceeded","url":"interfaces/requestlog.html#requestsucceeded","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":31,"kind":1024,"name":"description","url":"interfaces/requestlog.html#description","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":32,"kind":128,"name":"S3","url":"classes/s3.html","classes":"tsd-kind-class"},{"id":33,"kind":512,"name":"constructor","url":"classes/s3.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"S3"},{"id":34,"kind":2048,"name":"createDownloadURLFromData","url":"classes/s3.html#createdownloadurlfromdata","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":35,"kind":2048,"name":"signedURLPut","url":"classes/s3.html#signedurlput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":36,"kind":2048,"name":"signedURLGet","url":"classes/s3.html#signedurlget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":37,"kind":256,"name":"SignedURL","url":"interfaces/signedurl.html","classes":"tsd-kind-interface"},{"id":38,"kind":1024,"name":"url","url":"interfaces/signedurl.html#url","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"SignedURL"},{"id":39,"kind":128,"name":"SES","url":"classes/ses.html","classes":"tsd-kind-class"},{"id":40,"kind":512,"name":"constructor","url":"classes/ses.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SES"},{"id":41,"kind":2048,"name":"sendEmail","url":"classes/ses.html#sendemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SES"},{"id":42,"kind":128,"name":"SNS","url":"classes/sns.html","classes":"tsd-kind-class"},{"id":43,"kind":512,"name":"constructor","url":"classes/sns.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SNS"},{"id":44,"kind":2048,"name":"createPushPlatormEndpoint","url":"classes/sns.html#createpushplatormendpoint","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":45,"kind":2048,"name":"publishSNSPush","url":"classes/sns.html#publishsnspush","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":46,"kind":128,"name":"ResourceController","url":"classes/resourcecontroller.html","classes":"tsd-kind-class"},{"id":47,"kind":512,"name":"constructor","url":"classes/resourcecontroller.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"ResourceController"},{"id":48,"kind":2048,"name":"handleRequest","url":"classes/resourcecontroller.html#handlerequest","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ResourceController"},{"id":49,"kind":262144,"name":"dynamoDB","url":"classes/resourcecontroller.html#dynamodb","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":50,"kind":262144,"name":"cognito","url":"classes/resourcecontroller.html#cognito","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":51,"kind":262144,"name":"s3","url":"classes/resourcecontroller.html#s3","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":52,"kind":262144,"name":"ses","url":"classes/resourcecontroller.html#ses","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":53,"kind":262144,"name":"sns","url":"classes/resourcecontroller.html#sns","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":54,"kind":256,"name":"ResourceControllerOptions","url":"interfaces/resourcecontrolleroptions.html","classes":"tsd-kind-interface"},{"id":55,"kind":1024,"name":"tables","url":"interfaces/resourcecontrolleroptions.html#tables","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":56,"kind":1024,"name":"resourceId","url":"interfaces/resourcecontrolleroptions.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":57,"kind":1024,"name":"logsKeys","url":"interfaces/resourcecontrolleroptions.html#logskeys","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"}]}; | ||
typedoc.search.data = {"kinds":{"128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","262144":"Accessor"},"rows":[{"id":0,"kind":128,"name":"Cognito","url":"classes/cognito.html","classes":"tsd-kind-class"},{"id":1,"kind":512,"name":"constructor","url":"classes/cognito.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"Cognito"},{"id":2,"kind":2048,"name":"getUserByClaims","url":"classes/cognito.html#getuserbyclaims","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":3,"kind":2048,"name":"getUserByEmail","url":"classes/cognito.html#getuserbyemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":4,"kind":2048,"name":"getUserBySub","url":"classes/cognito.html#getuserbysub","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":5,"kind":2048,"name":"createUser","url":"classes/cognito.html#createuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":6,"kind":2048,"name":"resendPassword","url":"classes/cognito.html#resendpassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":7,"kind":2048,"name":"deleteUser","url":"classes/cognito.html#deleteuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":8,"kind":2048,"name":"signIn","url":"classes/cognito.html#signin","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":9,"kind":2048,"name":"updateEmail","url":"classes/cognito.html#updateemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":10,"kind":2048,"name":"updatePassword","url":"classes/cognito.html#updatepassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":11,"kind":128,"name":"DynamoDB","url":"classes/dynamodb.html","classes":"tsd-kind-class"},{"id":12,"kind":512,"name":"constructor","url":"classes/dynamodb.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"DynamoDB"},{"id":13,"kind":2048,"name":"IUID","url":"classes/dynamodb.html#iuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":14,"kind":2048,"name":"getAtomicCounterByKey","url":"classes/dynamodb.html#getatomiccounterbykey","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":15,"kind":2048,"name":"get","url":"classes/dynamodb.html#get","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":16,"kind":2048,"name":"put","url":"classes/dynamodb.html#put","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":17,"kind":2048,"name":"update","url":"classes/dynamodb.html#update","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":18,"kind":2048,"name":"delete","url":"classes/dynamodb.html#delete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":19,"kind":2048,"name":"batchGet","url":"classes/dynamodb.html#batchget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":20,"kind":2048,"name":"batchPut","url":"classes/dynamodb.html#batchput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":21,"kind":2048,"name":"batchDelete","url":"classes/dynamodb.html#batchdelete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":22,"kind":2048,"name":"query","url":"classes/dynamodb.html#query","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":23,"kind":2048,"name":"scan","url":"classes/dynamodb.html#scan","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":24,"kind":256,"name":"RequestLog","url":"interfaces/requestlog.html","classes":"tsd-kind-interface"},{"id":25,"kind":1024,"name":"key","url":"interfaces/requestlog.html#key","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":26,"kind":1024,"name":"at","url":"interfaces/requestlog.html#at","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":27,"kind":1024,"name":"expiresAt","url":"interfaces/requestlog.html#expiresat","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":28,"kind":1024,"name":"userId","url":"interfaces/requestlog.html#userid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":29,"kind":1024,"name":"resource","url":"interfaces/requestlog.html#resource","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":30,"kind":1024,"name":"resourceId","url":"interfaces/requestlog.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":31,"kind":1024,"name":"method","url":"interfaces/requestlog.html#method","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":32,"kind":1024,"name":"action","url":"interfaces/requestlog.html#action","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":33,"kind":1024,"name":"requestSucceeded","url":"interfaces/requestlog.html#requestsucceeded","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":34,"kind":1024,"name":"description","url":"interfaces/requestlog.html#description","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":35,"kind":128,"name":"S3","url":"classes/s3.html","classes":"tsd-kind-class"},{"id":36,"kind":512,"name":"constructor","url":"classes/s3.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"S3"},{"id":37,"kind":2048,"name":"createDownloadURLFromData","url":"classes/s3.html#createdownloadurlfromdata","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":38,"kind":2048,"name":"signedURLPut","url":"classes/s3.html#signedurlput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":39,"kind":2048,"name":"signedURLGet","url":"classes/s3.html#signedurlget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":40,"kind":256,"name":"SignedURL","url":"interfaces/signedurl.html","classes":"tsd-kind-interface"},{"id":41,"kind":1024,"name":"url","url":"interfaces/signedurl.html#url","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"SignedURL"},{"id":42,"kind":128,"name":"SES","url":"classes/ses.html","classes":"tsd-kind-class"},{"id":43,"kind":512,"name":"constructor","url":"classes/ses.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SES"},{"id":44,"kind":2048,"name":"sendEmail","url":"classes/ses.html#sendemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SES"},{"id":45,"kind":128,"name":"SNS","url":"classes/sns.html","classes":"tsd-kind-class"},{"id":46,"kind":512,"name":"constructor","url":"classes/sns.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SNS"},{"id":47,"kind":2048,"name":"createPushPlatormEndpoint","url":"classes/sns.html#createpushplatormendpoint","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":48,"kind":2048,"name":"publishSNSPush","url":"classes/sns.html#publishsnspush","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":49,"kind":128,"name":"ResourceController","url":"classes/resourcecontroller.html","classes":"tsd-kind-class"},{"id":50,"kind":512,"name":"constructor","url":"classes/resourcecontroller.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"ResourceController"},{"id":51,"kind":2048,"name":"handleRequest","url":"classes/resourcecontroller.html#handlerequest","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ResourceController"},{"id":52,"kind":262144,"name":"dynamoDB","url":"classes/resourcecontroller.html#dynamodb","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":53,"kind":262144,"name":"cognito","url":"classes/resourcecontroller.html#cognito","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":54,"kind":262144,"name":"s3","url":"classes/resourcecontroller.html#s3","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":55,"kind":262144,"name":"ses","url":"classes/resourcecontroller.html#ses","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":56,"kind":262144,"name":"sns","url":"classes/resourcecontroller.html#sns","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":57,"kind":256,"name":"ResourceControllerOptions","url":"interfaces/resourcecontrolleroptions.html","classes":"tsd-kind-interface"},{"id":58,"kind":1024,"name":"tables","url":"interfaces/resourcecontrolleroptions.html#tables","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":59,"kind":1024,"name":"resourceId","url":"interfaces/resourcecontrolleroptions.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":60,"kind":1024,"name":"logsKeys","url":"interfaces/resourcecontrolleroptions.html#logskeys","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"}]}; |
{ | ||
"name": "idea-aws", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "AWS wrappers to use in IDEA's back-ends", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -157,3 +157,3 @@ import AWS = require('aws-sdk'); | ||
*/ | ||
public deleteUser(email: string, cognitoUserPoolId: string,): Promise<void> { | ||
public deleteUser(email: string, cognitoUserPoolId: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
@@ -169,2 +169,90 @@ if(IdeaX.isEmpty(email, 'email')) return reject(new Error(`E.COGNITO.INVALID_EMAIL`)); | ||
} | ||
/** | ||
* Sign in a user of a specific pool through username and password. | ||
* @param {string} email the email used as login | ||
* @param {string} password the password to authenticate the user | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @param {string} cognitoUserPoolClientId the client id to access the user pool | ||
* (`ADMIN_NO_SRP_AUTH` must be enabled) | ||
* @return {Promise<AWS.CognitoIdentityServiceProvider.AuthenticationResultType>} | ||
*/ | ||
public signIn( | ||
email: string, password: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string | ||
): Promise<AWS.CognitoIdentityServiceProvider.AuthenticationResultType> { | ||
return new Promise((resolve, reject) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminInitiateAuth({ | ||
UserPoolId: cognitoUserPoolId, | ||
ClientId: cognitoUserPoolClientId, | ||
AuthFlow: 'ADMIN_NO_SRP_AUTH', | ||
AuthParameters: { 'USERNAME': email, 'PASSWORD': password } | ||
}, (err: Error, data: AWS.CognitoIdentityServiceProvider.AdminInitiateAuthResponse) => { | ||
IdeaX.logger('COGNITO SIGN IN', err, data ? JSON.stringify(data.toString) : null); | ||
if(err || !data.AuthenticationResult) reject(err); | ||
else resolve(data.AuthenticationResult); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Change the email address (== username) associated to a user. | ||
* @param {string} email the email currently used to login | ||
* @param {string} newEmail the new email to set | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @return {Promise<void>} | ||
*/ | ||
public updateEmail(email: string, newEmail: string, cognitoUserPoolId: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
if(IdeaX.isEmpty(newEmail, 'email')) return reject(new Error('E.COGNITO.INVALID_NEW_EMAIL')); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminUpdateUserAttributes({ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: [ | ||
{ Name: 'email', Value: newEmail }, | ||
{ Name: 'email_verified', Value: 'true' } | ||
] | ||
}, (err: Error, _: any) => { | ||
IdeaX.logger('COGNITO UPDATE EMAIL', err, newEmail); | ||
if(err) reject(err); | ||
else resolve(); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Change the password to sign in for a user. | ||
* @param {string} email the email currently used to login | ||
* @param {string} oldPassword the password to authenticate the user | ||
* @param {string} newPassword the new password to set | ||
* @param {string} cognitoUserPoolId the pool in which the user is stored | ||
* @param {string} cognitoUserPoolClientId the client id to access the user pool | ||
* (`ADMIN_NO_SRP_AUTH` must be enabled) | ||
* @return {Promise<void>} | ||
*/ | ||
public updatePassword( | ||
email: string, oldPassword: string, newPassword: string, | ||
cognitoUserPoolId: string, cognitoUserPoolClientId: string | ||
): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
if(newPassword.length < 8) return reject(new Error('E.COGNITO.INVALID_NEW_PASSWORD')); | ||
// get a token to run the password change | ||
this.signIn(email, oldPassword, cognitoUserPoolId, cognitoUserPoolClientId) | ||
.then((data: AWS.CognitoIdentityServiceProvider.AuthenticationResultType) => { | ||
// request the password change | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.changePassword({ | ||
AccessToken: data.AccessToken, | ||
PreviousPassword: oldPassword, | ||
ProposedPassword: newPassword | ||
}, (err: Error, _: any) => { | ||
IdeaX.logger('COGNITO UPDATE PASSWORD', err, '*******'); | ||
if(err) reject(err); | ||
else resolve(); | ||
}); | ||
}) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
} |
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
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
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
3583960
3975