Skip to content

Commit

Permalink
integrate auth0
Browse files Browse the repository at this point in the history
  • Loading branch information
Surbhi-sharma1 committed Sep 27, 2024
1 parent 830c939 commit 087a642
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 32 deletions.
18 changes: 1 addition & 17 deletions services/tenant-management-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import {
LEAD_TOKEN_VERIFIER,
SYSTEM_USER,
TenantManagementServiceBindings,
WEBHOOK_CONFIG,
WEBHOOK_VERIFIER,
} from './keys';
import {ITenantManagementServiceConfig} from './types';
import {InvoiceController} from './controllers/invoice.controller';
Expand Down Expand Up @@ -88,14 +86,6 @@ import {
ProvisioningService,
} from './services';
import {IdpController} from './controllers/idp.controller';
import {Auth0IdpProvider, KeycloakIdpProvider} from './providers/idp';
import {WebhookVerifierProvider} from './interceptors';
import {
DEFAULT_SIGNATURE_HEADER,
DEFAULT_TIMESTAMP_HEADER,
DEFAULT_TIMESTAMP_TOLERANCE,
} from './utils';
import {ProvisioningWebhookHandler} from './services/webhook';

export class TenantManagementServiceComponent implements Component {
constructor(
Expand Down Expand Up @@ -172,19 +162,13 @@ export class TenantManagementServiceComponent implements Component {
this.bindings = [
Binding.bind(LEAD_TOKEN_VERIFIER).toProvider(LeadTokenVerifierProvider),
Binding.bind(SYSTEM_USER).toProvider(SystemUserProvider),
Binding.bind(TenantManagementServiceBindings.IDP_KEYCLOAK).toProvider(
KeycloakIdpProvider,
),
Binding.bind(TenantManagementServiceBindings.IDP_AUTH0).toProvider(
Auth0IdpProvider,
),

createServiceBinding(ProvisioningService),
createServiceBinding(OnboardingService),
createServiceBinding(LeadAuthenticator),
createServiceBinding(CryptoHelperService),
Binding.bind('services.NotificationService').toClass(NotificationService),
createServiceBinding(InvoicePDFGenerator),

];

this.addClassBindingIfNotPresent(EventConnectorBinding.key, EventConnector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ export class Auth0IdpProvider
await this.management.organizations.getByName({name: tenant.name});

if (organizationResponse.status === 200) {
//NOSONAR
organizationId = organizationResponse.data.id;
}
} catch (error) {
if (error.statusCode === 404) {
//NOSONAR
const organization = await this.createOrganization(organizationData);
organizationId = organization.data.id;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
const adminUsername = `${tenant.key}-admin`; // Customize this as needed
const adminPassword = 'your-secure-password'; // This can be dynamic or set in the environment
await this.createUser(tenant.key, adminUsername, adminPassword, token);

console.log(
`Successfully configured Keycloak for tenant: ${tenant.name}`,
);
} catch (error) {
console.error(
`Error configuring Keycloak for tenant: ${tenant.name}`,
Expand Down Expand Up @@ -75,7 +71,7 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
async createRealm(realmName: string, token: string): Promise<void> {
// const token = await this.authenticateAdmin();

const response = await axios.post(
await axios.post(
`${process.env.KEYCLOAK_HOST}/admin/realms`,
{
realm: realmName,
Expand All @@ -87,8 +83,6 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
},
},
);

console.log('Realm created:', response.data);
}

async createClient(
Expand All @@ -98,7 +92,7 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
): Promise<void> {
// const token = await this.authenticateAdmin();

const response = await axios.post(
await axios.post(
`${process.env.KEYCLOAK_HOST}/admin/realms/${realmName}/clients`,
{
clientId: clientId,
Expand All @@ -113,8 +107,6 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
},
},
);

console.log('Client created:', response.data);
}

async createUser(
Expand All @@ -125,7 +117,7 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
): Promise<void> {
// const token = await this.authenticateAdmin();

const response = await axios.post(
await axios.post(
`${process.env.KEYCLOAK_HOST}/admin/realms/${realmName}/users`,
{
username: username,
Expand All @@ -144,7 +136,5 @@ export class KeycloakIdpProvider implements Provider<ConfigureIdpFunc<void>> {
},
},
);

console.log('User created:', response.data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface UserData {
// eslint-disable-next-line
phone_number?: string;
// eslint-disable-next-line
user_metadata?: {[key: string]: any};
user_metadata?: {[key: string]: any}; //NOSONAR
blocked?: boolean;
// eslint-disable-next-line
email_verified?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import {
import {ProvisioningWebhookHandler} from './services/webhook';
import {KeycloakIdpProvider} from './providers/idp/idp-keycloak.provider';
import {IdpController} from './controllers/idp.controller';
import { Auth0IdpProvider } from './providers/idp';
import {Auth0IdpProvider} from './providers/idp';

export class WebhookTenantManagementServiceComponent implements Component {
constructor(
Expand Down

0 comments on commit 087a642

Please sign in to comment.