Skip to content

Commit

Permalink
adjust realm names: realm and client-id for admin renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
DPDS93CT committed Oct 16, 2023
1 parent 8dd1d9b commit cb5453c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions config/config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
},
"KEYCLOAK": {
"BASE_URL": "http://127.0.0.1:8080",
"REALM_NAME": "master",
"CLIENT_ID": "admin-cli",
"SCHULPORTAL_REALM_NAME": "schulportal",
"SCHULPORTAL_CLIENT_ID": "schulportal"
"ADMIN_REALM_NAME": "master",
"ADMIN_CLIENT_ID": "admin-cli",
"REALM_NAME": "schulportal",
"CLIENT_ID": "schulportal"
}
}
8 changes: 4 additions & 4 deletions config/config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
},
"KEYCLOAK": {
"BASE_URL": "http://127.0.0.1:8080",
"REALM_NAME": "master",
"CLIENT_ID": "admin-cli",
"SCHULPORTAL_REALM_NAME": "schulportal",
"SCHULPORTAL_CLIENT_ID": "schulportal"
"ADMIN_REALM_NAME": "master",
"ADMIN_CLIENT_ID": "admin-cli",
"REALM_NAME": "schulportal",
"CLIENT_ID": "schulportal"
}
}
6 changes: 3 additions & 3 deletions src/frontend/frontend.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import { mappingErrorHandler } from '../shared/error/mapping.error.js';

return {
authServerUrl: keycloakConfig.BASE_URL,
realm: keycloakConfig.REALM_NAME,
clientId: keycloakConfig.CLIENT_ID,
secret: keycloakConfig.SECRET,
realm: keycloakConfig.ADMIN_REALM_NAME,
clientId: keycloakConfig.ADMIN_CLIENT_ID,
secret: keycloakConfig.ADMIN_SECRET,
};
},
inject: [ConfigService],
Expand Down
10 changes: 5 additions & 5 deletions src/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ describe('HealthController', () => {
let entityManager: SqlEntityManager;
let httpHealthIndicator: DeepMocked<HttpHealthIndicator>;
const keycloakConfig: KeycloakConfig = {
CLIENT_ID: '',
SECRET: '',
REALM_NAME: '',
ADMIN_CLIENT_ID: '',
ADMIN_SECRET: '',
ADMIN_REALM_NAME: '',
BASE_URL: 'http://keycloak.test',
SCHULPORTAL_REALM_NAME: '',
SCHULPORTAL_CLIENT_ID: '',
REALM_NAME: '',
CLIENT_ID: '',
};
let configService: DeepMocked<ConfigService>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class KeycloakAdministrationService {

this.kcAdminClient.setConfig({
baseUrl: this.kcConfig.BASE_URL,
realmName: this.kcConfig.REALM_NAME,
realmName: this.kcConfig.ADMIN_REALM_NAME,
});
}

Expand All @@ -45,8 +45,8 @@ export class KeycloakAdministrationService {
try {
const credentials: Credentials = {
grantType: 'client_credentials',
clientId: this.kcConfig.CLIENT_ID,
clientSecret: this.kcConfig.SECRET,
clientId: this.kcConfig.ADMIN_CLIENT_ID,
clientSecret: this.kcConfig.ADMIN_SECRET,
};

await this.kcAdminClient.auth(credentials);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ui-backend/domain/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export class LoginService {
public async getTokenForUser(username: string, password: string): Promise<TokenSet> {
try {
const keycloakIssuer: Issuer = await Issuer.discover(
this.kcConfig.BASE_URL + '/realms/' + this.kcConfig.SCHULPORTAL_REALM_NAME,
this.kcConfig.BASE_URL + '/realms/' + this.kcConfig.REALM_NAME,
);
const client: Client = new keycloakIssuer.Client({
client_id: this.kcConfig.SCHULPORTAL_CLIENT_ID,
client_id: this.kcConfig.CLIENT_ID,
token_endpoint_auth_method: 'none',
});
return await client.grant({
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ui-backend/domain/new-login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export class NewLoginService {
this.kcConfig = this.config.getOrThrow<KeycloakConfig>('KEYCLOAK');
this.kcAdminClient.setConfig({
baseUrl: this.kcConfig.BASE_URL,
realmName: this.kcConfig.SCHULPORTAL_REALM_NAME,
realmName: this.kcConfig.REALM_NAME,
});
}

public async auth(username: string, password: string): Promise<Result<string, DomainError>> {
try {
const credentials: Credentials = {
grantType: 'password',
clientId: this.kcConfig.SCHULPORTAL_CLIENT_ID,
clientId: this.kcConfig.CLIENT_ID,
username: username,
password: password,
};
Expand Down
16 changes: 8 additions & 8 deletions src/shared/config/config.loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ describe('configloader', () => {
},
KEYCLOAK: {
BASE_URL: 'localhost:8080',
CLIENT_ID: 'admin-cli',
REALM_NAME: 'master',
SCHULPORTAL_REALM_NAME: 'schulportal',
SCHULPORTAL_CLIENT_ID: 'schulportal',
ADMIN_CLIENT_ID: 'admin-cli',
ADMIN_REALM_NAME: 'master',
REALM_NAME: 'schulportal',
CLIENT_ID: 'schulportal',
},
};

const secrets: DeepPartial<JsonConfig> = {
DB: { SECRET: 'SuperSecretSecret' },
KEYCLOAK: { SECRET: 'ClientSecret' },
KEYCLOAK: { ADMIN_SECRET: 'ClientSecret' },
};

beforeAll(() => {
Expand Down Expand Up @@ -82,10 +82,10 @@ describe('configloader', () => {
},
KEYCLOAK: {
BASE_URL: '',
CLIENT_ID: '',
ADMIN_CLIENT_ID: '',
ADMIN_REALM_NAME: '',
REALM_NAME: '',
SCHULPORTAL_REALM_NAME: '',
SCHULPORTAL_CLIENT_ID: '',
CLIENT_ID: '',
},
};

Expand Down
10 changes: 5 additions & 5 deletions src/shared/config/keycloak.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ export class KeycloakConfig {

@IsString()
@IsNotEmpty()
public readonly REALM_NAME!: string;
public readonly ADMIN_REALM_NAME!: string;

@IsString()
@IsNotEmpty()
public readonly CLIENT_ID!: string;
public readonly ADMIN_CLIENT_ID!: string;

@IsString()
@IsNotEmpty()
public readonly SECRET!: string;
public readonly ADMIN_SECRET!: string;

@IsString()
@IsNotEmpty()
public readonly SCHULPORTAL_REALM_NAME!: string;
public readonly REALM_NAME!: string;

@IsString()
@IsNotEmpty()
public readonly SCHULPORTAL_CLIENT_ID!: string;
public readonly CLIENT_ID!: string;
}

0 comments on commit cb5453c

Please sign in to comment.