From d8034578131d43ec911f4dfc7db605317bf4fb58 Mon Sep 17 00:00:00 2001 From: Samarpan Date: Thu, 8 Oct 2020 10:12:11 +0530 Subject: [PATCH] feat(core): add security spec for open api spec generation SFO-0 --- packages/core/src/index.ts | 1 + packages/core/src/security-specs.ts | 12 +++++++++++ .../authentication-service/src/component.ts | 17 ++++++++++++++-- services/in-mail-service/src/component.ts | 15 ++++++++++++++ .../notification-service/src/component.ts | 14 +++++++++++++ services/scheduler-service/src/component.ts | 14 +++++++++++++ .../src/component.ts | 20 ++++++++++++++++--- 7 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 packages/core/src/security-specs.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index d14cd0a9e5..f97342b8f5 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -11,3 +11,4 @@ export * from './secure-sequence'; export * from './service-sequence'; export * from './utils'; export * from './types'; +export * from './security-specs'; diff --git a/packages/core/src/security-specs.ts b/packages/core/src/security-specs.ts new file mode 100644 index 0000000000..12a1362508 --- /dev/null +++ b/packages/core/src/security-specs.ts @@ -0,0 +1,12 @@ +import {ReferenceObject, SecuritySchemeObject} from '@loopback/openapi-v3'; +export const OPERATION_SECURITY_SPEC = [{HTTPBearer: []}]; +export type SecuritySchemeObjects = { + [securityScheme: string]: SecuritySchemeObject | ReferenceObject; +}; +export const SECURITY_SCHEME_SPEC: SecuritySchemeObjects = { + HTTPBearer: { + type: 'http', + scheme: 'bearer', + bearerFormat: 'JWT', + }, +}; diff --git a/services/authentication-service/src/component.ts b/services/authentication-service/src/component.ts index 70c5937165..e2514a04c0 100644 --- a/services/authentication-service/src/component.ts +++ b/services/authentication-service/src/component.ts @@ -8,7 +8,7 @@ import { } from '@loopback/core'; import {Class, Model, Repository} from '@loopback/repository'; import {RestApplication} from '@loopback/rest'; -import {CoreComponent} from '@sourceloop/core'; +import {CoreComponent, SECURITY_SCHEME_SPEC} from '@sourceloop/core'; import {AuthenticationComponent, Strategies} from 'loopback4-authentication'; import { AuthorizationBindings, @@ -40,7 +40,7 @@ export class AuthenticationServiceComponent implements Component { @inject(CoreBindings.APPLICATION_INSTANCE) private readonly application: RestApplication, @inject(AuthServiceBindings.Config, {optional: true}) - private readonly notifConfig?: IAuthServiceConfig, + private readonly authConfig?: IAuthServiceConfig, ) { this.bindings = []; this.providers = {}; @@ -54,6 +54,19 @@ export class AuthenticationServiceComponent implements Component { // Mount authorization component this.setupAuthorizationComponent(); + this.application.api({ + openapi: '3.0.0', + info: { + title: 'Authentication Service', + version: '1.0.0', + }, + paths: {}, + components: { + securitySchemes: SECURITY_SCHEME_SPEC, + }, + servers: [{url: '/'}], + }); + // Mount Helmet component this.application.component(Loopback4HelmetComponent); this.bindings.push( diff --git a/services/in-mail-service/src/component.ts b/services/in-mail-service/src/component.ts index 61a541ad67..0a91919fca 100644 --- a/services/in-mail-service/src/component.ts +++ b/services/in-mail-service/src/component.ts @@ -13,6 +13,7 @@ import { BearerVerifierConfig, BearerVerifierType, CoreComponent, + SECURITY_SCHEME_SPEC, ServiceSequence, } from '@sourceloop/core'; import {AuthenticationComponent} from 'loopback4-authentication'; @@ -20,6 +21,7 @@ import { AuthorizationBindings, AuthorizationComponent, } from 'loopback4-authorization'; + import { CollectorController, OriginatorController, @@ -78,5 +80,18 @@ export class InMailServiceComponent implements Component { allowAlwaysPaths: ['/explorer'], }); this.application.component(AuthorizationComponent); + + this.application.api({ + openapi: '3.0.0', + info: { + title: 'In-mail Service', + version: '1.0.0', + }, + paths: {}, + components: { + securitySchemes: SECURITY_SCHEME_SPEC, + }, + servers: [{url: '/'}], + }); } } diff --git a/services/notification-service/src/component.ts b/services/notification-service/src/component.ts index 77487d8505..b46d277f98 100644 --- a/services/notification-service/src/component.ts +++ b/services/notification-service/src/component.ts @@ -14,6 +14,7 @@ import { BearerVerifierConfig, BearerVerifierType, CoreComponent, + SECURITY_SCHEME_SPEC, ServiceSequence, } from '@sourceloop/core'; import {AuthenticationComponent} from 'loopback4-authentication'; @@ -57,6 +58,19 @@ export class NotificationServiceComponent implements Component { // Mount core component this.application.component(CoreComponent); + this.application.api({ + openapi: '3.0.0', + info: { + title: 'Notification Service', + version: '1.0.0', + }, + paths: {}, + components: { + securitySchemes: SECURITY_SCHEME_SPEC, + }, + servers: [{url: '/'}], + }); + // Mount notifications component this.application.component(NotificationsComponent); if (!(this.notifConfig && this.notifConfig.useCustomEmailProvider)) { diff --git a/services/scheduler-service/src/component.ts b/services/scheduler-service/src/component.ts index 8cbc59a22d..b96002ac13 100644 --- a/services/scheduler-service/src/component.ts +++ b/services/scheduler-service/src/component.ts @@ -16,6 +16,7 @@ import { BearerVerifierType, CoreComponent, IServiceConfig, + SECURITY_SCHEME_SPEC, ServiceSequence, } from '@sourceloop/core'; import {AuthenticationComponent} from 'loopback4-authentication'; @@ -82,6 +83,19 @@ export class SchedulerServiceComponent implements Component { // Mount core component this.application.component(CoreComponent); + this.application.api({ + openapi: '3.0.0', + info: { + title: 'Scheduler Service', + version: '1.0.0', + }, + paths: {}, + components: { + securitySchemes: SECURITY_SCHEME_SPEC, + }, + servers: [{url: '/'}], + }); + if (!(this.schedulerConfig && this.schedulerConfig.useCustomSequence)) { // Mount default sequence if needed this.setupSequence(this.bindings); diff --git a/services/video-conferencing-service/src/component.ts b/services/video-conferencing-service/src/component.ts index 723df3a349..491e4f9e36 100644 --- a/services/video-conferencing-service/src/component.ts +++ b/services/video-conferencing-service/src/component.ts @@ -14,8 +14,9 @@ import { BearerVerifierConfig, BearerVerifierType, CoreComponent, - ServiceSequence, IServiceConfig, + SECURITY_SCHEME_SPEC, + ServiceSequence, } from '@sourceloop/core'; import {AuthenticationComponent} from 'loopback4-authentication'; import { @@ -29,10 +30,10 @@ import {VideoChatBindings} from './keys'; import {AuditLogs} from './models/audit-logs.model'; import {VideoChatSession} from './models/video-chat-session.model'; import {VonageProvider} from './providers/vonage/vonage.provider'; -import {AuditLogsRepository} from './repositories/audit-logs.repository'; -import {VideoChatSessionRepository} from './repositories/video-chat-session.repository'; import {VonageService} from './providers/vonage/vonage.service'; import {SessionAttendeesRepository} from './repositories'; +import {AuditLogsRepository} from './repositories/audit-logs.repository'; +import {VideoChatSessionRepository} from './repositories/video-chat-session.repository'; export class VideoConfServiceComponent implements Component { constructor( @@ -47,6 +48,19 @@ export class VideoConfServiceComponent implements Component { // Mount core component this.application.component(CoreComponent); + this.application.api({ + openapi: '3.0.0', + info: { + title: 'Video Conferencing Service', + version: '1.0.0', + }, + paths: {}, + components: { + securitySchemes: SECURITY_SCHEME_SPEC, + }, + servers: [{url: '/'}], + }); + this.bindings.push( Binding.bind(VideoChatBindings.VideoChatProvider).toProvider( VonageProvider,