Skip to content

Commit

Permalink
feat(tenant-management): integraqte auth0
Browse files Browse the repository at this point in the history
integrate auth0

GH-47
  • Loading branch information
Surbhi-sharma1 committed Sep 27, 2024
1 parent f14113b commit 548db0d
Show file tree
Hide file tree
Showing 26 changed files with 633 additions and 292 deletions.
80 changes: 62 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions services/tenant-management-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@
"@loopback/build": "^11.0.2",
"@loopback/eslint-config": "^15.0.2",
"@loopback/testlab": "^7.0.2",
"@types/auth0": "^3.3.10",
"@types/jsonwebtoken": "^9.0.5",
"@types/moment": "^2.13.0",
"@types/node": "^18.11.9",
"@types/pdfkit": "^0.13.4",
"auth0": "^4.10.0",
"eslint": "^8.57.0",
"nodemon": "^2.0.21",
"nyc": "^15.1.0",
Expand Down
25 changes: 16 additions & 9 deletions services/tenant-management-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
ProviderMap,
ServiceOrProviderClass,
} from '@loopback/core';
import { Class, Model, Repository } from '@loopback/repository';
import { RestApplication } from '@loopback/rest';
import {Class, Model, Repository} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
BearerVerifierBindings,
BearerVerifierComponent,
Expand All @@ -25,20 +25,22 @@ import {
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import { AuthenticationComponent } from 'loopback4-authentication';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import {
ContactController,
HomePageController,
IdpController,
LeadController,
LeadTenantController,
PingController,
TenantConfigController,
TenantController,
} from './controllers';
import { InvoiceController } from './controllers/invoice.controller';
import {InvoiceController} from './controllers/invoice.controller';
import {
EventConnectorBinding,
LEAD_TOKEN_VERIFIER,
Expand All @@ -61,7 +63,7 @@ import {
WebhookDTO,
WebhookSecret,
} from './models';
import { LeadTokenVerifierProvider, SystemUserProvider } from './providers';
import {LeadTokenVerifierProvider, SystemUserProvider} from './providers';
import {
AddressRepository,
ContactRepository,
Expand All @@ -82,7 +84,9 @@ import {
OnboardingService,
ProvisioningService,
} from './services';
import { ITenantManagementServiceConfig } from './types';
import {ITenantManagementServiceConfig} from './types';
import {TenantConfigTenantController} from '@sourceloop/ctrl-plane-tenant-management-service/dist/controllers';

export class TenantManagementServiceComponent implements Component {
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE)
Expand Down Expand Up @@ -122,7 +126,7 @@ export class TenantManagementServiceComponent implements Component {
ResourceRepository,
TenantRepository,
WebhookSecretRepository,
TenantConfigRepository
TenantConfigRepository,
];

this.models = [
Expand All @@ -139,7 +143,7 @@ export class TenantManagementServiceComponent implements Component {
TenantOnboardDTO,
VerifyLeadResponseDTO,
WebhookDTO,
TenantConfig
TenantConfig,
];

this.controllers = [
Expand All @@ -149,7 +153,10 @@ export class TenantManagementServiceComponent implements Component {
LeadTenantController,
LeadController,
PingController,
TenantController
TenantController,
IdpController,
TenantConfigController,
TenantConfigTenantController,
];

this.bindings = [
Expand Down
110 changes: 55 additions & 55 deletions services/tenant-management-service/src/controllers/idp.controller.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
import { inject, intercept } from '@loopback/core';
import { getModelSchemaRef, post, requestBody } from '@loopback/rest';
import {inject, intercept} from '@loopback/core';
import {getModelSchemaRef, post, requestBody} from '@loopback/rest';
import {
CONTENT_TYPE,
OPERATION_SECURITY_SPEC,
rateLimitKeyGenPublic,
STATUS_CODE,
CONTENT_TYPE,
OPERATION_SECURITY_SPEC,
rateLimitKeyGenPublic,
STATUS_CODE,
} from '@sourceloop/core';
import { authorize } from 'loopback4-authorization';
import { ratelimit } from 'loopback4-ratelimiter';
import { TenantManagementServiceBindings, WEBHOOK_VERIFIER } from '../keys';
import { IdpDetailsDTO } from '../models/dtos/idp-details-dto.model';
import { ConfigureIdpFunc, IdPKey } from '../types';
import {authorize} from 'loopback4-authorization';
import {ratelimit} from 'loopback4-ratelimiter';
import {TenantManagementServiceBindings, WEBHOOK_VERIFIER} from '../keys';
import {IdpDetailsDTO} from '../models/dtos/idp-details-dto.model';
import {ConfigureIdpFunc, IdPKey} from '../types';

const basePath = '/manage/users';
export class IdpController {
constructor(
@inject(TenantManagementServiceBindings.IDP_KEYCLOAK)
private readonly idpKeycloakProvider:ConfigureIdpFunc<IdpDetailsDTO>
) { }
@intercept(WEBHOOK_VERIFIER)
@ratelimit(true, {
max: parseInt(process.env.WEBHOOK_API_MAX_ATTEMPTS ?? '10'),
keyGenerator: rateLimitKeyGenPublic,
})
@authorize({
permissions: ['*'],
})
@post(`${basePath}`, {
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.NO_CONTENT]: {
description: 'Webhook success',
},
constructor(
@inject(TenantManagementServiceBindings.IDP_KEYCLOAK)
private readonly idpKeycloakProvider: ConfigureIdpFunc<IdpDetailsDTO>,
@inject(TenantManagementServiceBindings.IDP_AUTH0)
private readonly idpAuth0Provider: ConfigureIdpFunc<IdpDetailsDTO>,
) {}
@intercept(WEBHOOK_VERIFIER)
@ratelimit(true, {
max: parseInt(process.env.WEBHOOK_API_MAX_ATTEMPTS ?? '10'),
keyGenerator: rateLimitKeyGenPublic,
})
@authorize({
permissions: ['*'],
})
@post(`${basePath}`, {
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.NO_CONTENT]: {
description: 'Webhook success',
},
},
})
async idpConfigure(
@requestBody({
content: {
[CONTENT_TYPE.JSON]: {
schema: getModelSchemaRef(IdpDetailsDTO, {
title: 'IdpDetailsDTO',
}),
},
},
})
async idpConfigure(
@requestBody({
content: {
[CONTENT_TYPE.JSON]: {
schema: getModelSchemaRef(IdpDetailsDTO, {
title: 'IdpDetailsDTO',
}),
},
},
})
payload: IdpDetailsDTO,
): Promise<void> {
switch (payload.identityProvider) {
case IdPKey.AUTH0:

break;
case IdPKey.COGNITO:

break;
case IdPKey.KEYCLOAK:
await this.idpKeycloakProvider(payload);
break;

default:
break;
}
payload: IdpDetailsDTO,
): Promise<void> {
switch (payload.identityProvider) {
case IdPKey.AUTH0:
await this.idpAuth0Provider(payload);
break;
case IdPKey.COGNITO:
break;
case IdPKey.KEYCLOAK:
await this.idpKeycloakProvider(payload);
break;

default:
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from './webhook.controller';
export * from './invoice.controller';
export * from './tenant-config.controller';
export * from './tenant-config-tenant.controller';
export * from './idp.controller';
export * from './idp.controller';
Loading

0 comments on commit 548db0d

Please sign in to comment.