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 0de1f89
Show file tree
Hide file tree
Showing 15 changed files with 443 additions and 158 deletions.
44 changes: 44 additions & 0 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
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;
}
}
}
7 changes: 7 additions & 0 deletions services/tenant-management-service/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { BINDING_PREFIX } from '@sourceloop/core';
import { IEventConnector } from './types/i-event-connector.interface';
import { ValueOrPromise } from '@loopback/context';
import { Auth0Response } from './providers/idp/types';

export namespace TenantManagementServiceBindings {
export const Config =
Expand All @@ -32,6 +33,12 @@ export namespace TenantManagementServiceBindings {
>('sf.user.idp.keycloak');
}

/**
* Binding key for the Idp Auth0 provider.
*/
export const IDP_AUTH0 =
BindingKey.create<ConfigureIdpFunc<Auth0Response>>('sf.user.idp.auth0');

/**
* Binding key for the lead token verifier.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getJsonSchema } from '@loopback/openapi-v3';
import { Model, model, property } from '@loopback/repository';
import { IdpDetails, IdPKey } from '../../types';
import { TenantDto } from './tenant-dto.model';
import {getJsonSchema} from '@loopback/openapi-v3';
import {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 All @@ -13,8 +13,8 @@ export class IdpDetailsDTO extends Model implements IdpDetails {
required: true,
default: IdPKey.AUTH0,
jsonSchema: {
enum: Object.values(IdPKey),
},
enum: Object.values(IdPKey),
},
})
identityProvider: IdPKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export class SubscriptionDTO implements ISubscription {
@property({type: 'string'})
planId: string;

@property({type: 'string'})
invoiceId: string;

// Assuming IPlan interface is defined, you can include it here
@property()
plan?: IPlan;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getJsonSchema } from '@loopback/openapi-v3';
import { model, property } from '@loopback/repository';
import { Address } from '../address.model';
import { Contact } from '../contact.model';
import { Tenant } from '../tenant.model';
import {getJsonSchema} from '@loopback/openapi-v3';
import {AnyObject, model, property} from '@loopback/repository';
import {Address} from '../address.model';

import {Tenant} from '../tenant.model';
import {Contact} from '../contact.model';

@model({
description: 'model describing payload used to create a lead',
Expand All @@ -25,6 +26,12 @@ export class TenantDto extends Tenant {
},
})
contacts: Contact[];
@property({
type: 'object',
description: 'plan details',
jsonSchema: getJsonSchema(Object),
})
plan: AnyObject;

constructor(data?: Partial<TenantDto>) {
super(data);
Expand Down
2 changes: 1 addition & 1 deletion services/tenant-management-service/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export * from './resource.model';
export * from './invoice.model';
export * from './address.model';
export * from './lead-token.model';
export * from './tenant-config.model';
export * from './tenant-config.model';
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { belongsTo, model, property } from '@loopback/repository';
import { UserModifiableEntity } from '@sourceloop/core';
import { Tenant } from './tenant.model';
import {model, property, belongsTo} from '@loopback/repository';
import {UserModifiableEntity} from '@sourceloop/core';
import {Tenant} from './tenant.model';
import {ConfigValue} from '../providers/idp';

@model({
name: 'tenant_configs',
description: 'tenant_configs to save any tenant specific data related to idP'
description: 'tenant_configs to save any tenant specific data related to idP',
})
export class TenantConfig extends UserModifiableEntity {
@property({
Expand All @@ -17,16 +18,16 @@ export class TenantConfig extends UserModifiableEntity {
@property({
type: 'string',
required: true,
name: 'config_key'
name: 'config_key',
})
configKey: string;

@property({
type: 'object',
required: true,
name: 'config_value'
name: 'config_value',
})
configValue: object;
configValue: ConfigValue;

@belongsTo(
() => Tenant,
Expand Down
Loading

0 comments on commit 0de1f89

Please sign in to comment.