Skip to content

Commit

Permalink
Export multi tenant service using injection token, fixes #173
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrerojosh committed Jan 11, 2024
1 parent 28a4e17 commit 595c086
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
KEYCLOAK_COOKIE_DEFAULT,
KEYCLOAK_INSTANCE,
KEYCLOAK_LOGGER,
KEYCLOAK_MULTITENANT_SERVICE,
TokenValidation,
} from '../constants';
import {
Expand All @@ -36,6 +37,7 @@ export class AuthGuard implements CanActivate {
private keycloakOpts: KeycloakConnectConfig,
@Inject(KEYCLOAK_LOGGER)
private logger: Logger,
@Inject(KEYCLOAK_MULTITENANT_SERVICE)
private multiTenant: KeycloakMultiTenantService,
private readonly reflector: Reflector,
) {}
Expand Down
2 changes: 2 additions & 0 deletions src/guards/resource.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
KEYCLOAK_CONNECT_OPTIONS,
KEYCLOAK_INSTANCE,
KEYCLOAK_LOGGER,
KEYCLOAK_MULTITENANT_SERVICE,
PolicyEnforcementMode,
} from '../constants';
import { META_ENFORCER_OPTIONS } from '../decorators/enforcer-options.decorator';
Expand All @@ -35,6 +36,7 @@ export class ResourceGuard implements CanActivate {
private keycloakOpts: KeycloakConnectConfig,
@Inject(KEYCLOAK_LOGGER)
private logger: Logger,
@Inject(KEYCLOAK_MULTITENANT_SERVICE)
private multiTenant: KeycloakMultiTenantService,
private readonly reflector: Reflector,
) {}
Expand Down
2 changes: 2 additions & 0 deletions src/guards/role.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
KEYCLOAK_CONNECT_OPTIONS,
KEYCLOAK_INSTANCE,
KEYCLOAK_LOGGER,
KEYCLOAK_MULTITENANT_SERVICE,
RoleMatchingMode,
RoleMerge,
} from '../constants';
Expand All @@ -33,6 +34,7 @@ export class RoleGuard implements CanActivate {
private keycloakOpts: KeycloakConnectConfig,
@Inject(KEYCLOAK_LOGGER)
private logger: Logger,
@Inject(KEYCLOAK_MULTITENANT_SERVICE)
private multiTenant: KeycloakMultiTenantService,
private readonly reflector: Reflector,
) {}
Expand Down
10 changes: 9 additions & 1 deletion src/keycloak-connect.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DynamicModule, Logger, Module, Provider } from '@nestjs/common';
import { KEYCLOAK_CONNECT_OPTIONS } from './constants';
import { KEYCLOAK_CONNECT_OPTIONS, KEYCLOAK_MULTITENANT_SERVICE } from './constants';

Check failure on line 2 in src/keycloak-connect.module.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·KEYCLOAK_CONNECT_OPTIONS,·KEYCLOAK_MULTITENANT_SERVICE·` with `␍⏎··KEYCLOAK_CONNECT_OPTIONS,␍⏎··KEYCLOAK_MULTITENANT_SERVICE,␍⏎`
import { KeycloakConnectModuleAsyncOptions } from './interface/keycloak-connect-module-async-options.interface';
import { KeycloakConnectOptionsFactory } from './interface/keycloak-connect-options-factory.interface';
import {
Expand Down Expand Up @@ -48,6 +48,10 @@ export class KeycloakConnectModule {
loggerProvider,
keycloakProvider,
KeycloakMultiTenantService,
{
provide: KEYCLOAK_MULTITENANT_SERVICE,
useClass: KeycloakMultiTenantService

Check failure on line 53 in src/keycloak-connect.module.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
}

Check failure on line 54 in src/keycloak-connect.module.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
];
return {
module: KeycloakConnectModule,
Expand Down Expand Up @@ -77,6 +81,10 @@ export class KeycloakConnectModule {
loggerProvider,
keycloakProvider,
KeycloakMultiTenantService,
{
provide: KEYCLOAK_MULTITENANT_SERVICE,
useClass: KeycloakMultiTenantService

Check failure on line 86 in src/keycloak-connect.module.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
}

Check failure on line 87 in src/keycloak-connect.module.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
];

if (options.useExisting || options.useFactory) {
Expand Down

0 comments on commit 595c086

Please sign in to comment.