@point3/logto-module
Version:
포인트3 내부 logto Authentication 모듈입니다
171 lines • 8.45 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogtoModule = exports.LOGTO_MODULE_OPTIONS = void 0;
const config_1 = require("@nestjs/config");
const client_1 = require("./client");
const token_1 = require("./token");
const stateless_1 = require("./stateless");
exports.LOGTO_MODULE_OPTIONS = Symbol('LOGTO_MODULE_OPTIONS');
class LogtoModule {
static forRoot(options) {
const { global = false, enableClient = false, logger } = options;
const baseProviders = [
{
provide: client_1.LogtoLoggerServiceToken,
useExisting: logger.token,
},
{
provide: token_1.LogtoTokenVerifierToken,
useFactory: (configService) => {
return new token_1.LogtoTokenVerifier({
jwksUri: configService.getOrThrow('LOGTO_JWKS_URI'),
issuer: configService.getOrThrow('LOGTO_AUTH_ISSUER'),
});
},
inject: [config_1.ConfigService],
},
{
provide: stateless_1.LogtoTokenGuardToken,
useClass: stateless_1.LogtoTokenGuard,
},
];
const clientProviders = enableClient
? [
{
provide: client_1.OAuthClientToken,
useFactory: (configService, loggerService) => {
return new client_1.OAuthClient({
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
clientId: configService.getOrThrow('LOGTO_CLIENT_ID'),
clientSecret: configService.getOrThrow('LOGTO_CLIENT_SECRET'),
resources: [configService.getOrThrow('LOGTO_RESOURCES')],
scopes: configService.getOrThrow('LOGTO_SCOPES').split(','),
prompt: configService.getOrThrow('LOGTO_PROMPT'),
redirectUri: configService.getOrThrow('LOGTO_REDIRECT_URI'),
signInUri: configService.getOrThrow('LOGTO_SIGN_IN_URI'),
dashboardSignInUri: configService.getOrThrow('LOGTO_DASHBOARD_SIGN_IN_URI'),
}, loggerService);
},
inject: [config_1.ConfigService, client_1.LogtoLoggerServiceToken],
},
{
provide: client_1.LogtoLoginSessionToken,
useFactory: (configService, loggerService, oauthClient) => {
return new client_1.LogtoLoginSession(configService.getOrThrow('LOGTO_M2M_API_URL'), loggerService, oauthClient);
},
inject: [config_1.ConfigService, client_1.LogtoLoggerServiceToken, client_1.OAuthClientToken],
},
{
provide: client_1.LogtoM2MClientToken,
useFactory: (configService, tokenVerifier, loggerService) => {
return new client_1.LogtoM2MClient({
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
clientId: configService.getOrThrow('LOGTO_M2M_CLIENT_ID'),
clientSecret: configService.getOrThrow('LOGTO_M2M_CLIENT_SECRET'),
resource: configService.getOrThrow('LOGTO_M2M_RESOURCE'),
apiUrl: configService.getOrThrow('LOGTO_M2M_API_URL'),
scopes: ['all'],
}, tokenVerifier, loggerService);
},
inject: [config_1.ConfigService, token_1.LogtoTokenVerifierToken, client_1.LogtoLoggerServiceToken],
},
]
: [];
const providers = [...baseProviders, ...clientProviders];
return {
module: LogtoModule,
global,
imports: [logger.module],
providers,
exports: providers,
};
}
static forRootAsync(options) {
const { global = false, imports = [], loggerToken, useFactory, inject = [] } = options;
const asyncOptionsProvider = {
provide: exports.LOGTO_MODULE_OPTIONS,
useFactory,
inject,
};
const baseProviders = [
asyncOptionsProvider,
{
provide: client_1.LogtoLoggerServiceToken,
useExisting: loggerToken,
},
{
provide: token_1.LogtoTokenVerifierToken,
useFactory: (configService) => {
return new token_1.LogtoTokenVerifier({
jwksUri: configService.getOrThrow('LOGTO_JWKS_URI'),
issuer: configService.getOrThrow('LOGTO_AUTH_ISSUER'),
});
},
inject: [config_1.ConfigService],
},
{
provide: stateless_1.LogtoTokenGuardToken,
useClass: stateless_1.LogtoTokenGuard,
},
];
const clientProviders = [
{
provide: client_1.OAuthClientToken,
useFactory: (opts, configService, loggerService) => {
if (opts.enableClient) {
return new client_1.OAuthClient({
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
clientId: configService.getOrThrow('LOGTO_CLIENT_ID'),
clientSecret: configService.getOrThrow('LOGTO_CLIENT_SECRET'),
resources: [configService.getOrThrow('LOGTO_RESOURCES')],
scopes: configService.getOrThrow('LOGTO_SCOPES').split(','),
prompt: configService.getOrThrow('LOGTO_PROMPT'),
redirectUri: configService.getOrThrow('LOGTO_REDIRECT_URI'),
signInUri: configService.getOrThrow('LOGTO_SIGN_IN_URI'),
dashboardSignInUri: configService.getOrThrow('LOGTO_DASHBOARD_SIGN_IN_URI'),
}, loggerService);
}
return null;
},
inject: [exports.LOGTO_MODULE_OPTIONS, config_1.ConfigService, client_1.LogtoLoggerServiceToken],
},
{
provide: client_1.LogtoLoginSessionToken,
useFactory: (opts, configService, loggerService, oauthClient) => {
if (opts.enableClient) {
return new client_1.LogtoLoginSession(configService.getOrThrow('LOGTO_M2M_API_URL'), loggerService, oauthClient);
}
return null;
},
inject: [exports.LOGTO_MODULE_OPTIONS, config_1.ConfigService, client_1.LogtoLoggerServiceToken, client_1.OAuthClientToken],
},
{
provide: client_1.LogtoM2MClientToken,
useFactory: (opts, configService, tokenVerifier, loggerService) => {
if (opts.enableClient) {
return new client_1.LogtoM2MClient({
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
clientId: configService.getOrThrow('LOGTO_M2M_CLIENT_ID'),
clientSecret: configService.getOrThrow('LOGTO_M2M_CLIENT_SECRET'),
resource: configService.getOrThrow('LOGTO_M2M_RESOURCE'),
apiUrl: configService.getOrThrow('LOGTO_M2M_API_URL'),
scopes: ['all'],
}, tokenVerifier, loggerService);
}
return null;
},
inject: [exports.LOGTO_MODULE_OPTIONS, config_1.ConfigService, token_1.LogtoTokenVerifierToken, client_1.LogtoLoggerServiceToken],
},
];
const providers = [...baseProviders, ...clientProviders];
return {
module: LogtoModule,
global,
imports: [...imports],
providers,
exports: providers,
};
}
}
exports.LogtoModule = LogtoModule;
//# sourceMappingURL=module.js.map