Skip to content

Commit

Permalink
feat(tenant-management): generate temporary password
Browse files Browse the repository at this point in the history
generate temporary password

GH-47
  • Loading branch information
Surbhi-sharma1 committed Oct 11, 2024
1 parent ff7705e commit c68c044
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion services/tenant-management-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
import {
ContactController,
HomePageController,
IdpController,
LeadController,
LeadTenantController,
PingController,
Expand Down
1 change: 0 additions & 1 deletion services/tenant-management-service/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from '@loopback/core';
import {BINDING_PREFIX} from '@sourceloop/core';
import {IEventConnector} from './types/i-event-connector.interface';
import {Auth0Response} from './providers/idp';

export namespace TenantManagementServiceBindings {
export const Config =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {getJsonSchema} from '@loopback/openapi-v3';
import {AnyObject, Model, model, property} from '@loopback/repository';
import {IdpDetails, IdPKey} from '../../types';
import {TenantDto} from './tenant-dto.model';

@model({
description: 'model describing payload for IDP controller',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {Provider} from '@loopback/context';

import {ConfigureIdpFunc, IdpDetails, IdPKey, IdpResp} from '../../types';
import {ManagementClient, PostOrganizationsRequest, UserCreate} from 'auth0';

import {Auth0Response} from './types';

import { randomBytes } from 'crypto';
import {repository} from '@loopback/repository';

import {HttpErrors} from '@loopback/rest';
Expand Down Expand Up @@ -58,7 +56,22 @@ export class Auth0IdpProvider implements Provider<ConfigureIdpFunc<IdpResp>> {
// eslint-disable-next-line
enabled_connections: configValue.enabled_connections,
};

function generateStrongPassword(length: number): string {
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=';

// Generate random bytes
const randomBytesArray = randomBytes(length);

// Map each byte to a character in the charset
const password = Array.from(randomBytesArray)
.map(byte => charset[byte % charset.length])
.join('');

return password;
}

const passwordLength = 16;
const password = generateStrongPassword(passwordLength);
const userData: UserCreate = {
email: tenant.contacts[0].email,

Expand All @@ -68,7 +81,7 @@ export class Auth0IdpProvider implements Provider<ConfigureIdpFunc<IdpResp>> {
** the user will be forced to change it on first login
** need to check actions in auth0 to see how we can achieve this
**/
password: 'test123!@#',
password: password,
// eslint-disable-next-line
verify_email: configValue.verify_email,
// eslint-disable-next-line
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {AnyObject} from '@loopback/repository';
import {Tenant} from '../models';

export enum IdPKey {
AUTH0 = 'auth0',
Expand Down

0 comments on commit c68c044

Please sign in to comment.