diff --git a/services/tenant-management-service/src/providers/idp/idp-auth0.provider.ts b/services/tenant-management-service/src/providers/idp/idp-auth0.provider.ts index 9596dfb..0448111 100644 --- a/services/tenant-management-service/src/providers/idp/idp-auth0.provider.ts +++ b/services/tenant-management-service/src/providers/idp/idp-auth0.provider.ts @@ -2,9 +2,8 @@ import {Provider} from '@loopback/context'; import {ConfigureIdpFunc, IdpDetails, IdPKey, IdpResp} from '../../types'; import {ManagementClient, PostOrganizationsRequest, UserCreate} from 'auth0'; -import {randomBytes} from 'crypto'; import {repository} from '@loopback/repository'; - +import {randomBytes} from 'crypto'; import {HttpErrors} from '@loopback/rest'; import {TenantMgmtConfigRepository} from '../../repositories'; @@ -57,17 +56,19 @@ export class Auth0IdpProvider implements Provider> { enabled_connections: configValue.enabled_connections, }; function generateStrongPassword(length: number): string { - const charset = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+~`|}{[]:;?><,./-='; + const regex = /[A-Za-z0-9!@#$%^&*()_+~`|}{[\]:;?><,./-=]/; + const validChars: string[] = []; - // Generate random bytes + for (let i = 33; i <= 126; i++) { + const char = String.fromCharCode(i); + if (regex.test(char)) { + validChars.push(char); + } + } const randomBytesArray = randomBytes(length); - - // Map each byte to a character in the charset const password = Array.from(randomBytesArray) - .map(byte => charset[byte % charset.length]) + .map(byte => validChars[byte % validChars.length]) .join(''); - return password; }