Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keycloak authentication #240

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ WBO supports authentication with a JWT. This should be passed in as a query with

The `AUTH_SECRET_KEY` variable in [`configuration.js`](./server/configuration.js) should be filled with the secret key for the JWT.

WBO supports authentication with OIDC based on [`keycloak`](https://github.com/keycloak)
Some important environment variables are :
- `KEYCLOAK_ENABLE` is used for enable OIDC authentication
- `KEYCLOAK_URL` is the URL of Keycloak, eg, `https://keycloak-server/auth`
- `KEYCLOAK_REALM` is the Realm name, eg, **myrealm**
- `KEYCLOAK_CLIENTID` is the Public Client Id, eg, **myapp**
- `KEYCLOAK_USERINFO_ATTRIBUTE` is the attribute name for authorization, and it is not mandatory
Comment on lines +90 to +94
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have to take more than an optional oidc discovery url

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is necessary, everything is conditioned on the KEYCLOAK_ENABLE variable


For any further information you can see [`here`](https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter)

## Configuration

When you start a WBO server, it loads its configuration from several environment variables.
Expand Down
2 changes: 2 additions & 0 deletions client-data/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<link rel="alternate" hreflang="{{.}}" href="{{../boardUriComponent}}?lang={{.}}" />
{{/languages}}
<script src="../polyfill.min.js"></script>
<script src="../js/keycloak.js"></script>
</head>

<body>
Expand Down Expand Up @@ -90,6 +91,7 @@
<script src="../js/minitpl.js"></script>
<script src="../js/intersect.js"></script>
<script src="../js/board.js"></script>
<script src="../tools/keycloak/keycloak.js"></script>
<script src="../tools/pencil/wbo_pencil_point.js"></script>
<script src="../tools/pencil/pencil.js"></script>
<script src="../tools/cursor/cursor.js"></script>
Expand Down
2,387 changes: 2,387 additions & 0 deletions client-data/js/keycloak.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions client-data/tools/keycloak/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client-data/tools/keycloak/keycloak.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

65 changes: 65 additions & 0 deletions client-data/tools/keycloak/keycloak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* WHITEBOPHIR
*********************************************************
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
*
* Copyright (C) 2013 Ophir LOJKINE
*
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend
*/

(function () { //Code isolation
if (Tools.server_config.KEYCLOAK_ENABLE) {
var keycloak = Keycloak({
url: Tools.server_config.KEYCLOAK_URL,
realm: Tools.server_config.KEYCLOAK_REALM,
clientId: Tools.server_config.KEYCLOAK_CLIENTID
});

keycloak.init({
onLoad: 'login-required'
}).catch(function(e) {
console.log(e);
});

function onStart() {
keycloak.logout({
redirectUri: window.location.href.split("/boards/")[0]
});
}

keycloak.onAuthSuccess = function() {
keycloak.loadUserInfo().then(function(userInfo) {
if (Tools.server_config.KEYCLOAK_USERINFO_ATTRIBUTE) {
if (!userInfo[Tools.server_config.KEYCLOAK_USERINFO_ATTRIBUTE]) {
alert(Tools.i18n.t("access_denied" || "") + userInfo.preferred_username);
keycloak.logout();
}
}
Tools.add({ //The new tool
"name": Tools.i18n.t("logout" || "") + userInfo.given_name + " " + userInfo.family_name,
"shortcut": "L",
"onstart": onStart,
"stylesheet": "tools/keycloak/keycloak.css",
"icon": "tools/keycloak/icon.svg"
});
});
}
}
})(); //End of code isolation
54 changes: 53 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"async-mutex": "^0.3.1",
"handlebars": "^4.7.7",
"jsonwebtoken": "^8.5.1",
"keycloak-js": "^17.0.1",
"polyfill-library": "^3.107.1",
"serve-static": "^1.14.1",
"socket.io": "^4",
Expand Down
6 changes: 6 additions & 0 deletions server/client_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ module.exports = {
BLOCKED_TOOLS: config.BLOCKED_TOOLS,
BLOCKED_SELECTION_BUTTONS: config.BLOCKED_SELECTION_BUTTONS,
AUTO_FINGER_WHITEOUT: config.AUTO_FINGER_WHITEOUT,
KEYCLOAK_ENABLE: config.KEYCLOAK_ENABLE,
KEYCLOAK_URL: config.KEYCLOAK_URL,
KEYCLOAK_REALM: config.KEYCLOAK_REALM,
KEYCLOAK_CLIENTID: config.KEYCLOAK_CLIENTID,
KEYCLOAK_USERINFO_ATTRIBUTE: config.KEYCLOAK_USERINFO_ATTRIBUTE

};
11 changes: 11 additions & 0 deletions server/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ module.exports = {

/** Secret key for jwt */
AUTH_SECRET_KEY: (process.env["AUTH_SECRET_KEY"] || ""),

KEYCLOAK_ENABLE: (process.env["KEYCLOAK_ENABLE"] || false),

KEYCLOAK_URL: process.env["KEYCLOAK_URL"],

KEYCLOAK_REALM: process.env["KEYCLOAK_REALM"],

KEYCLOAK_CLIENTID: process.env["KEYCLOAK_CLIENTID"],

KEYCLOAK_USERINFO_ATTRIBUTE: process.env["KEYCLOAK_USERINFO_ATTRIBUTE"],

};
20 changes: 15 additions & 5 deletions server/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"tools": "Werkzeuge",
"view_source": "Quellcode auf GitHub",
"white-out": "Korrekturflüssigkeit",
"zoom": "Zoom"
"zoom": "Zoom",
"access_denied": "System nicht verfügbar für ",
"logout": "Logout "
},
"en": {
"White-out": "White-out",
Expand Down Expand Up @@ -77,7 +79,9 @@
"text": "Text",
"tools": "Tools",
"view_source": "Source code on GitHub",
"zoom": "Zoom"
"zoom": "Zoom",
"access_denied": "System not available for ",
"logout": "Logout "
},
"es": {
"board_name_placeholder": "Nombre de la pizarra …",
Expand Down Expand Up @@ -116,7 +120,9 @@
"tools": "Herramientas",
"view_source": "Código fuente en GitHub",
"white-out": "Blanqueado",
"zoom": "Zoom"
"zoom": "Zoom",
"access_denied": "Sistema no disponible para ",
"logout": "Logout "
},
"fr": {
"board_name_placeholder": "Nom du tableau…",
Expand Down Expand Up @@ -154,7 +160,9 @@
"text": "Texte",
"tools": "Outils",
"view_source": "Code source sur GitHub",
"white-out": "Blanco"
"white-out": "Blanco",
"access_denied": "Système non disponible pour ",
"logout": "Logout "
},
"hu": {
"White-out": "Lefedő",
Expand Down Expand Up @@ -232,7 +240,9 @@
"tools": "Strumenti",
"view_source": "Codice sorgente su GitHub",
"white-out": "Bianchetto",
"zoom": "Zoom"
"zoom": "Zoom",
"access_denied": "Sistema non disponibile per ",
"logout": "Logout "
},
"ja": {
"board_name_placeholder": "ボードの名前",
Expand Down