-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tenant-management): integrate auth0 idp provider
integrate auth0 idp provider GH-47
- Loading branch information
1 parent
a895365
commit 4ae038f
Showing
22 changed files
with
708 additions
and
269 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 55 additions & 56 deletions
111
services/tenant-management-service/src/controllers/idp.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
import { extensions, Getter, 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, IWebhookHandler } from '../types'; | ||
import { KeycloakIdpProvider } from '../providers/idp/idp-keycloak.provider'; | ||
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.