@adastradev/user-management-sdk
Advanced tools
import { ICognitoUserPoolLocator } from './ICognitoUserPoolLocator'; | ||
import { CognitoUserSession } from 'amazon-cognito-identity-js'; | ||
import { CognitoIdentityCredentials } from 'aws-sdk/global'; | ||
import { ICognitoUserPoolLocatorByTenantId } from './ICognitoUserPoolLocatorByTenantId'; | ||
export declare class AuthManager { | ||
lastRefresh: number; | ||
private locator; | ||
private locatorByTenantId; | ||
private poolData; | ||
@@ -13,4 +15,4 @@ private readonly region; | ||
private authenticatorURI; | ||
constructor(locator: ICognitoUserPoolLocator, region: string); | ||
signIn(email: string, password: string, newPassword?: string): Promise<CognitoUserSession>; | ||
constructor(locator: ICognitoUserPoolLocator, locatorByTenantId: ICognitoUserPoolLocatorByTenantId, region: string); | ||
signIn(email: string, password: string, newPassword?: string, tenantId?: string): Promise<CognitoUserSession>; | ||
getAndSetEnvironmentCredentials(): Promise<any>; | ||
@@ -17,0 +19,0 @@ getCognitoCredentials(): Promise<any>; |
@@ -45,4 +45,5 @@ "use strict"; | ||
var AuthManager = /** @class */ (function () { | ||
function AuthManager(locator, region) { | ||
function AuthManager(locator, locatorByTenantId, region) { | ||
this.locator = locator; | ||
this.locatorByTenantId = locatorByTenantId; | ||
this.region = region; | ||
@@ -53,26 +54,37 @@ this.lastRefresh = 0; | ||
} | ||
AuthManager.prototype.signIn = function (email, password, newPassword) { | ||
AuthManager.prototype.signIn = function (email, password, newPassword, tenantId) { | ||
var _this = this; | ||
if (newPassword === void 0) { newPassword = ''; } | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, error_1, userPool, authenticationData, userData, authenticationDetails, that; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
var _a, _b, error_1, userPool, authenticationData, userData, authenticationDetails, that; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
// get the pool data from the response | ||
console.log("Signing into AWS Cognito"); | ||
_b.label = 1; | ||
_c.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
_c.trys.push([1, 6, , 7]); | ||
if (!tenantId) return [3 /*break*/, 3]; | ||
_a = this; | ||
return [4 /*yield*/, this.locator.getPoolForUsername(email)]; | ||
return [4 /*yield*/, this.locatorByTenantId.getPoolForTenantId(tenantId)]; | ||
case 2: | ||
_a.poolData = _b.sent(); | ||
_a.poolData = _c.sent(); | ||
console.log("test log pool data " + JSON.stringify(this.poolData)); | ||
this.authenticatorURI = "cognito-idp." + this.region + ".amazonaws.com/" + this.poolData.UserPoolId; | ||
return [3 /*break*/, 4]; | ||
return [3 /*break*/, 5]; | ||
case 3: | ||
error_1 = _b.sent(); | ||
_b = this; | ||
return [4 /*yield*/, this.locator.getPoolForUsername(email)]; | ||
case 4: | ||
_b.poolData = _c.sent(); | ||
console.log("test log pool via username data" + JSON.stringify(this.poolData)); | ||
this.authenticatorURI = "cognito-idp." + this.region + ".amazonaws.com/" + this.poolData.UserPoolId; | ||
_c.label = 5; | ||
case 5: return [3 /*break*/, 7]; | ||
case 6: | ||
error_1 = _c.sent(); | ||
console.log("error getting pool for user: " + error_1.message); | ||
return [2 /*return*/, reject(error_1)]; | ||
case 4: | ||
case 7: | ||
userPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.poolData); | ||
@@ -79,0 +91,0 @@ authenticationData = { |
export * from './AuthManager'; | ||
export * from './CognitoUserPoolLocatorStatic'; | ||
export * from './CognitoUserPoolLocatorByTenantIdStatic'; | ||
export * from './CognitoUserPoolLocatorUserManagement'; | ||
export * from './CognitoUserPoolLocatorUserManagementByTenantId'; | ||
export * from './ICognitoUserPoolApiModel'; | ||
export * from './ICognitoUserPoolLocator'; | ||
export * from './ICognitoUserPoolLocatorByTenantId'; | ||
export * from './UserManagementApi'; |
@@ -15,6 +15,9 @@ "use strict"; | ||
__exportStar(require("./CognitoUserPoolLocatorStatic"), exports); | ||
__exportStar(require("./CognitoUserPoolLocatorByTenantIdStatic"), exports); | ||
__exportStar(require("./CognitoUserPoolLocatorUserManagement"), exports); | ||
__exportStar(require("./CognitoUserPoolLocatorUserManagementByTenantId"), exports); | ||
__exportStar(require("./ICognitoUserPoolApiModel"), exports); | ||
__exportStar(require("./ICognitoUserPoolLocator"), exports); | ||
__exportStar(require("./ICognitoUserPoolLocatorByTenantId"), exports); | ||
__exportStar(require("./UserManagementApi"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,8 +0,12 @@ | ||
import { ApiCredentials } from '@adastradev/serverless-discovery-sdk'; | ||
import { ApiCredentials, IAMCredentials } from '@adastradev/serverless-discovery-sdk'; | ||
export interface IAMCredentialsWithSession extends IAMCredentials { | ||
sessionToken: string; | ||
} | ||
export declare class UserManagementApi { | ||
private apigClient; | ||
private additionalParams; | ||
constructor(serviceEndpointUri: string, region: string, credentials: ApiCredentials, apigClient?: any); | ||
constructor(serviceEndpointUri: string, region: string, credentials: ApiCredentials | IAMCredentialsWithSession, apigClient?: any); | ||
createUserPool(tenantId: string): any; | ||
deleteUserPool(id: string): any; | ||
getUserPool(tenantId: string): any; | ||
getUserPools(): any; | ||
@@ -9,0 +13,0 @@ createUser(tenantId: string, userName: string, password: string, firstName: string, lastName: string, suppressInviteEmail?: boolean, role?: string): any; |
@@ -7,8 +7,2 @@ "use strict"; | ||
var apigClientFactory = require('@adastradev/aws-api-gateway-client').default; // tslint:disable-line | ||
// interceptor logging for Authorization headers | ||
// axios.interceptors.request.use(function(config) { | ||
// var authorizationHeader = config.headers['Authorization']; | ||
// console.log('Authorization header: ' + authorizationHeader); | ||
// return config; | ||
// }); | ||
var UserManagementApi = /** @class */ (function () { | ||
@@ -81,2 +75,10 @@ function UserManagementApi(serviceEndpointUri, region, credentials, apigClient) { | ||
}; | ||
UserManagementApi.prototype.getUserPool = function (tenantId) { | ||
var params = {}; | ||
var pathTemplate = "/admin/userpool/" + tenantId; | ||
var method = 'GET'; | ||
var additionalParams = {}; | ||
var body = {}; | ||
return this.apigClient.invokeApi(params, pathTemplate, method, additionalParams, body); | ||
}; | ||
UserManagementApi.prototype.getUserPools = function () { | ||
@@ -83,0 +85,0 @@ var params = {}; |
{ | ||
"name": "@adastradev/user-management-sdk", | ||
"version": "4.0.0", | ||
"version": "4.1.0-beta.1677873419391", | ||
"description": "Astra user management SDK for JavaScript in the browser and Node.js", | ||
@@ -33,2 +33,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@adastradev/astra-logger": "^1.4.7", | ||
"@adastradev/aws-api-gateway-client": "^1.0.6", | ||
@@ -47,3 +48,3 @@ "@adastradev/serverless-discovery-sdk": "^2.2.6", | ||
"@types/sinon": "^7.5.2", | ||
"aws-sdk": "^2.896.0", | ||
"aws-sdk": "^2.1321.0", | ||
"chai": "^4.3.4", | ||
@@ -50,0 +51,0 @@ "chai-as-promised": "^7.1.1", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
62419
38.06%33
37.5%817
41.11%6
20%1
Infinity%5
25%