Skip to content

Commit

Permalink
feat(core): add security spec for open api spec generation
Browse files Browse the repository at this point in the history
SFO-0
  • Loading branch information
samarpan-b committed Oct 8, 2020
1 parent 47fad0c commit d803457
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './secure-sequence';
export * from './service-sequence';
export * from './utils';
export * from './types';
export * from './security-specs';
12 changes: 12 additions & 0 deletions packages/core/src/security-specs.ts
Original file line number Diff line number Diff line change
@@ -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',
},
};
17 changes: 15 additions & 2 deletions services/authentication-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions services/in-mail-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import {
BearerVerifierConfig,
BearerVerifierType,
CoreComponent,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';

import {
CollectorController,
OriginatorController,
Expand Down Expand Up @@ -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: '/'}],
});
}
}
14 changes: 14 additions & 0 deletions services/notification-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
BearerVerifierConfig,
BearerVerifierType,
CoreComponent,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {AuthenticationComponent} from 'loopback4-authentication';
Expand Down Expand Up @@ -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)) {
Expand Down
14 changes: 14 additions & 0 deletions services/scheduler-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
BearerVerifierType,
CoreComponent,
IServiceConfig,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {AuthenticationComponent} from 'loopback4-authentication';
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 17 additions & 3 deletions services/video-conferencing-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
BearerVerifierConfig,
BearerVerifierType,
CoreComponent,
ServiceSequence,
IServiceConfig,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
Expand All @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit d803457

Please sign in to comment.