-
Notifications
You must be signed in to change notification settings - Fork 70
/
component.ts
91 lines (87 loc) · 2.43 KB
/
component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {
Binding,
Component,
ControllerClass,
CoreBindings,
inject,
ProviderMap,
} from '@loopback/core';
import {Class, Model, Repository} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
CoreComponent,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {
AuthClientRepository,
UserCredentialsRepository,
UserRepository,
} from './repositories';
import {OidcController} from './controllers';
import {OidcProviderProvider, FindAccountProvider} from './providers';
import {OidcInitializerService} from './services';
import {OIDCServiceBindings} from './keys';
import path from 'path';
import {AuthClient, User} from './models';
export class OidcServiceComponent implements Component {
repositories?: Class<Repository<Model>>[];
/**
* An optional list of Model classes to bind for dependency injection
* via `app.model()` API.
*/
models?: Class<Model>[];
providers: ProviderMap = {
[OIDCServiceBindings.OIDC_PROVIDER.key]: OidcProviderProvider,
[OIDCServiceBindings.FIND_ACCOUNT_PROVIDER.key]: FindAccountProvider,
};
services = [OidcInitializerService];
/**
* An array of controller classes
*/
controllers?: ControllerClass[];
bindings?: Binding[];
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE)
private readonly application: RestApplication,
) {
this.application.component(CoreComponent);
this.models = [User, AuthClient];
this.controllers = [OidcController];
this.repositories = [
AuthClientRepository,
UserRepository,
UserCredentialsRepository,
];
this.bindings = [
new Binding(OIDCServiceBindings.LoginTemplate).to(
path.join(__dirname, '../public/views/login.ejs'),
),
new Binding(OIDCServiceBindings.InteractionTemplate).to(
path.join(__dirname, '../public/views/interaction.ejs'),
),
];
this.application.api({
openapi: '3.0.0',
info: {
title: 'Oidc Service',
version: '1.0.0',
},
paths: {},
components: {
securitySchemes: SECURITY_SCHEME_SPEC,
},
servers: [{url: '/'}],
});
}
/**
* Setup ServiceSequence by default if no other sequnce provided
*/
setupSequence() {
this.application.sequence(ServiceSequence);
}
}