Skip to content

Commit e137f9b

Browse files
author
Dennis Labordus
authored
Merge pull request #36 from com-pas/keycloak_integration
Keycloak integration
2 parents 17649ad + 81fec91 commit e137f9b

File tree

11 files changed

+143
-5
lines changed

11 files changed

+143
-5
lines changed

__snapshots__/compas-settings.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
value="http://localhost:9091/compas-cim-mapping"
2020
>
2121
</mwc-textfield>
22+
<mwc-textfield
23+
dialoginitialfocus=""
24+
id="keycloakAuthUrl"
25+
label="[compas.settings.keycloakAuthUrl]"
26+
required=""
27+
value="http://localhost:8089/auth/"
28+
>
29+
</mwc-textfield>
2230
<mwc-button style="--mdc-theme-primary: var(--mdc-theme-error)">
2331
[reset]
2432
</mwc-button>

__snapshots__/open-scd.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,26 @@
2323
aria-disabled="false"
2424
class="top"
2525
graphic="icon"
26-
iconid="folder_open"
26+
iconid="login"
2727
mwc-list-item=""
2828
tabindex="0"
29+
>
30+
<mwc-icon slot="graphic">
31+
login
32+
</mwc-icon>
33+
<span>
34+
Login
35+
</span>
36+
<mwc-linear-progress indeterminate="">
37+
</mwc-linear-progress>
38+
</mwc-list-item>
39+
<mwc-list-item
40+
aria-disabled="false"
41+
class="top"
42+
graphic="icon"
43+
iconid="folder_open"
44+
mwc-list-item=""
45+
tabindex="-1"
2946
>
3047
<mwc-icon slot="graphic">
3148
folder_open
@@ -402,6 +419,14 @@
402419
</mwc-top-app-bar-fixed>
403420
</mwc-drawer>
404421
<div class="landing">
422+
<mwc-icon-button
423+
class="landing_icon"
424+
icon="login"
425+
>
426+
<div class="landing_label">
427+
Login
428+
</div>
429+
</mwc-icon-button>
405430
<mwc-icon-button
406431
class="landing_icon"
407432
icon="folder_open"
@@ -661,6 +686,22 @@
661686
role="separator"
662687
>
663688
</li>
689+
<mwc-check-list-item
690+
aria-disabled="false"
691+
class="official"
692+
graphic="control"
693+
hasmeta=""
694+
left=""
695+
mwc-list-item=""
696+
selected=""
697+
tabindex="-1"
698+
value="/src/menu/Login.js"
699+
>
700+
<mwc-icon slot="meta">
701+
login
702+
</mwc-icon>
703+
Login
704+
</mwc-check-list-item>
664705
<mwc-check-list-item
665706
aria-disabled="false"
666707
class="official"

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@material/mwc-top-app-bar-fixed": "^0.21.0",
3838
"ace-custom-element": "^1.6.5",
3939
"carehtml": "^0.1.3",
40+
"keycloak-js": "^15.0.0",
4041
"lit-element": "2.4.0",
4142
"lit-html": "1.3.0",
4243
"lit-translate": "^1.2.1",

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ export const officialPlugins = [
2828
default: true,
2929
kind: 'editor',
3030
},
31+
{
32+
name: 'Login',
33+
src: '/src/menu/Login.js',
34+
icon: 'login',
35+
default: true,
36+
kind: 'menu',
37+
requireDoc: false,
38+
position: 'top'
39+
},
3140
{
3241
name: 'Open project',
3342
src: '/src/menu/OpenProject.js',

src/compas/CompasSettingsElement.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {TextFieldBase} from "@material/mwc-textfield/mwc-textfield-base";
88
export type CompasSettingsRecord = {
99
sclDataServiceUrl: string;
1010
cimMappingServiceUrl: string;
11+
keycloakAuthUrl: string;
1112
};
1213
export const defaults: CompasSettingsRecord = {
1314
sclDataServiceUrl: 'http://localhost:9090/compas-scl-data-service',
14-
cimMappingServiceUrl: 'http://localhost:9091/compas-cim-mapping'
15+
cimMappingServiceUrl: 'http://localhost:9091/compas-cim-mapping',
16+
keycloakAuthUrl: 'http://localhost:8089/auth/'
1517
};
1618

1719
export function CompasSettings() {
@@ -21,6 +23,7 @@ export function CompasSettings() {
2123
return {
2224
sclDataServiceUrl: this.getCompasSetting('sclDataServiceUrl'),
2325
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
26+
keycloakAuthUrl: this.getCompasSetting('keycloakAuthUrl')
2427
};
2528
},
2629

@@ -52,9 +55,14 @@ export class CompasSettingsElement extends LitElement {
5255
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="cimMappingServiceUrl"]');
5356
}
5457

58+
getKeycloakAuthUrlField(): TextFieldBase {
59+
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="keycloakAuthUrl"]');
60+
}
61+
5562
valid(): boolean {
5663
return this.getSclDataServiceUrlField().checkValidity()
57-
&& this.getCimMappingServiceUrlField().checkValidity();
64+
&& this.getCimMappingServiceUrlField().checkValidity()
65+
&& this.getKeycloakAuthUrlField().checkValidity();
5866
}
5967

6068
save(): boolean {
@@ -65,6 +73,7 @@ export class CompasSettingsElement extends LitElement {
6573
// Update settings from TextField.
6674
CompasSettings().setCompasSetting('sclDataServiceUrl', this.getSclDataServiceUrlField().value);
6775
CompasSettings().setCompasSetting('cimMappingServiceUrl', this.getCimMappingServiceUrlField().value);
76+
CompasSettings().setCompasSetting('keycloakAuthUrl', this.getKeycloakAuthUrlField().value);
6877
return true;
6978
}
7079

@@ -91,6 +100,10 @@ export class CompasSettingsElement extends LitElement {
91100
label="${translate('compas.settings.cimMappingServiceUrl')}"
92101
value="${this.compasSettings.cimMappingServiceUrl}" required>
93102
</mwc-textfield>
103+
<mwc-textfield dialogInitialFocus id="keycloakAuthUrl"
104+
label="${translate('compas.settings.keycloakAuthUrl')}"
105+
value="${this.compasSettings.keycloakAuthUrl}" required>
106+
</mwc-textfield>
94107
95108
<mwc-button style="--mdc-theme-primary: var(--mdc-theme-error)"
96109
@click=${() => {

src/menu/Login.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { LitElement} from 'lit-element';
2+
import { login } from '../state/auth/KeycloakManager';
3+
4+
export default class LoginPlugin extends LitElement {
5+
async run(): Promise<void> {
6+
return login();
7+
}
8+
}

src/state/auth/KeycloakManager.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Keycloak from 'keycloak-js';
2+
import { CompasSettings } from '../../compas/CompasSettingsElement';
3+
4+
const keycloakInstance = Keycloak({
5+
url: CompasSettings().compasSettings.keycloakAuthUrl,
6+
realm: 'compas',
7+
clientId: 'openscd'
8+
});
9+
10+
export function login() {
11+
keycloakInstance.init({onLoad: 'login-required'}).then(() => {
12+
console.log("Logged in as '" + keycloakInstance.subject + "'");
13+
});
14+
}
15+
16+
export function getJwtToken() {
17+
return keycloakInstance.token;
18+
}

src/translations/de.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ export const de: Translations = {
410410
name: "CoMPAS Einstellungen",
411411
sclDataServiceUrl: "CoMPAS SCL Data Service URL",
412412
cimMappingServiceUrl: "CoMPAS CIM Mapping Service URL",
413+
keycloakAuthUrl: "Keycloak Auth URL",
413414
}
414-
},
415+
}
415416
};

src/translations/en.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ export const en = {
407407
name: "CoMPAS Settings",
408408
sclDataServiceUrl: "CoMPAS SCL Data Service URL",
409409
cimMappingServiceUrl: "CoMPAS CIM Mapping Service URL",
410+
keycloakAuthUrl: "Keycloak Auth URL",
410411
}
411-
},
412+
}
412413
};

0 commit comments

Comments
 (0)