aws-user-service
Advanced tools
Comparing version 1.0.11 to 1.0.12
45
index.js
@@ -11,6 +11,6 @@ const AWS = require('aws-sdk'); | ||
getUserIdFromRequest(request) { | ||
return request.apiGateway.event.requestContext.identity.cognitoAuthenticationProvider.split(':').pop(); | ||
return request.apiGateway.event.requestContext.identity.cognitoAuthenticationProvider.split(':').pop(); | ||
} | ||
async getUser(userId){ | ||
async getUser(userId) { | ||
const listUsersResponse = await this.cognitoidentityserviceprovider.listUsers({ | ||
@@ -23,3 +23,42 @@ UserPoolId: this.authIntegrationUserPoolId, | ||
} | ||
async getUsers(paginationToken, pageSize) { | ||
const request = { | ||
UserPoolId: this.authIntegrationUserPoolId, | ||
Limit: pageSize | ||
} | ||
if (paginationToken) { | ||
request.PaginationToken = paginationToken | ||
} | ||
const response = await this.cognitoidentityserviceprovider.listUsers(request).promise(); | ||
return { | ||
paginationToken: response.PaginationToken, | ||
users: response.Users | ||
} | ||
} | ||
async isAdmin(userId) { | ||
const groups = await this.cognitoidentityserviceprovider.adminListGroupsForUser({ | ||
UserPoolId: this.authIntegrationUserPoolId, | ||
Username: userId, | ||
Limit: 10 | ||
}).promise(); | ||
if (!groups) | ||
return false | ||
if (groups.err) { | ||
console.log(groups.err) | ||
return false | ||
} | ||
if (!groups.data) | ||
return false | ||
return groups.data.Groups.filter(x => x.GroupName === "SenterAdmin").length === 1 | ||
} | ||
updateUserAttributes = async (userId, attributeName, attributeValue) => { | ||
@@ -26,0 +65,0 @@ |
{ | ||
"name": "aws-user-service", | ||
"version": "1.0.11", | ||
"description": "Contain methods to work with asw user", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "npm test" | ||
}, | ||
"author": "DM", | ||
"license": "ISC", | ||
"dependencies": {} | ||
"name": "aws-user-service", | ||
"version": "1.0.12", | ||
"description": "Contain methods to work with asw user", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "npm test" | ||
}, | ||
"author": "Senter", | ||
"license": "ISC", | ||
"dependencies": {} | ||
} |
2653
61