From 3fd024f4f7ff5d49d067f7aa395d2e744e5c5de9 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Sun, 20 Oct 2024 10:53:44 +0200 Subject: [PATCH] GUI improvements Signed-off-by: Stephan Richter --- .../de/srsoftware/oidc/api/Constants.java | 128 +++++++++--------- de.srsoftware.oidc.app/build.gradle | 2 +- .../de/srsoftware/oidc/app/Application.java | 20 +-- .../src/main/resources/de/edit_client.html | 22 +++ .../src/main/resources/de/new_client.html | 22 +++ .../src/main/resources/en/edit_client.html | 22 +++ .../src/main/resources/en/new_client.html | 22 +++ .../main/resources/en/scripts/edit_client.js | 21 ++- .../main/resources/en/scripts/new_client.js | 21 ++- .../src/main/resources/en/style.css | 9 +- 10 files changed, 208 insertions(+), 81 deletions(-) diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java index fd13ee2..dbfd69f 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java @@ -3,69 +3,69 @@ package de.srsoftware.oidc.api; public class Constants { - public static final String ACCESS_TOKEN = "access_token"; - public static final String APP_NAME = "LightOIDC"; - public static final String AT_HASH = "at_hash"; - public static final String ATTEMPTS = "attempts"; - public static final String AUTH_CODE = "authorization_code"; - public static final String AUTHORZED = "authorized"; - public static final String BEARER = "Bearer"; - public static final String CAUSE = "cause"; - public static final String CLIENT_ID = "client_id"; - public static final String CLIENT_SECRET = "client_secret"; - public static final String CODE = "code"; - public static final String EMAIL = "email"; - public static final String ERROR = "error"; - public static final String CONFIG_PATH = "LIGHTOIDC_CONFIG_PATH"; - public static final String CONFIRMED = "confirmed"; - public static final String DAYS = "days"; - public static final String ENCRYPTION_KEY = "encryption_key"; - public static final String ERROR_DESCRIPTION = "error_description"; - public static final String ERROR_INVALID_REDIRECT = "error_invalid_redirect"; - public static final String ERROR_LOCKED = "error_locked"; - public static final String ERROR_LOGIN_FAILED = "error_login_failed"; - public static final String ERROR_MISSING_PARAMETER = "error_missing_parameter"; + public static final String ACCESS_TOKEN = "access_token"; + public static final String APP_NAME = "LightOIDC"; + public static final String AT_HASH = "at_hash"; + public static final String ATTEMPTS = "attempts"; + public static final String AUTH_CODE = "authorization_code"; + public static final String AUTHORZED = "authorized"; + public static final String BEARER = "Bearer"; + public static final String CAUSE = "cause"; + public static final String CLIENT_ID = "client_id"; + public static final String CLIENT_SECRET = "client_secret"; + public static final String CODE = "code"; + public static final String EMAIL = "email"; + public static final String ERROR = "error"; + public static final String CONFIG_PATH = "LIGHTOIDC_CONFIG_PATH"; + public static final String CONFIRMED = "confirmed"; + public static final String DAYS = "days"; + public static final String ENCRYPTION_KEY = "encryption_key"; + public static final String ERROR_DESCRIPTION = "error_description"; + public static final String ERROR_INVALID_REDIRECT = "error_invalid_redirect"; + public static final String ERROR_LOCKED = "error_locked"; + public static final String ERROR_LOGIN_FAILED = "error_login_failed"; + public static final String ERROR_MISSING_PARAMETER = "error_missing_parameter"; public static final String ERROR_MISSONG_CODE_RESPONSE_TYPE = "error_missing_code"; - public static final String ERROR_NO_USERNAME = "error_no_username"; - public static final String ERROR_UNKNOWN_CLIENT = "error_unknown_client"; - public static final String ERROR_UNSUPPORTED_RESPONSE_TYPE = "error_unsupported_response_type"; - public static final String EXPIRATION = "expiration"; - public static final String EXPIRES_IN = "expires_in"; - public static final String GRANT_TYPE = "grant_type"; - public static final String ID_TOKEN = "id_token"; - public static final String INVALID_CLIENT = "invalid_client"; - public static final String INVALID_GRANT = "invalid_grant"; - public static final String INVALID_REDIRECT_URI = "invalid_request_uri"; - public static final String INVALID_REQUEST = "invalid_request"; - public static final String INVALID_REQUEST_OBJECT = "invalid_request_object"; - public static final String INVALID_SCOPE = "invalid_scope"; - public static final String LANDING_PAGE = "landing_page"; - public static final String MAILCONFIG = "mail_config"; - public static final String NAME = "name"; - public static final String NONCE = "nonce"; - public static final String PARAM = "parameter"; - public static final String PERMISSION = "permission"; - public static final String OPENID = "openid"; - public static final String REDIRECT_URI = "redirect_uri"; - public static final String REDIRECT_URIS = "redirect_uris"; - public static final String RELEASE = "release"; - public static final String REQUEST_NOT_SUPPORTED = "request_not_supported"; - public static final String RESPONSE_TYPE = "response_type"; - public static final String SALT = "salt"; - public static final String SCOPE = "scope"; - public static final String SECRET = "secret"; - public static final String SESSION_DURATION = "session_duration"; - public static final String SMTP_USER = "smtp_user"; - public static final String SMTP_PASSWORD = "smtp_pass"; - public static final String SMTP_AUTH = "smtp_auth"; - public static final String SMTP_HOST = "smtp_host"; - public static final String SMTP_PORT = "smtp_port"; - public static final String STATE = "state"; - public static final String START_TLS = "start_tls"; - public static final String TOKEN = "token"; - public static final String TOKEN_TYPE = "token_type"; - public static final String TRUST = "trust"; - public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; - public static final String USER = "user"; - public static final String USER_ID = "user_id"; + public static final String ERROR_NO_USERNAME = "error_no_username"; + public static final String ERROR_UNKNOWN_CLIENT = "error_unknown_client"; + public static final String ERROR_UNSUPPORTED_RESPONSE_TYPE = "error_unsupported_response_type"; + public static final String EXPIRATION = "expiration"; + public static final String EXPIRES_IN = "expires_in"; + public static final String GRANT_TYPE = "grant_type"; + public static final String ID_TOKEN = "id_token"; + public static final String INVALID_CLIENT = "invalid_client"; + public static final String INVALID_GRANT = "invalid_grant"; + public static final String INVALID_REDIRECT_URI = "invalid_request_uri"; + public static final String INVALID_REQUEST = "invalid_request"; + public static final String INVALID_REQUEST_OBJECT = "invalid_request_object"; + public static final String INVALID_SCOPE = "invalid_scope"; + public static final String LANDING_PAGE = "landing_page"; + public static final String MAILCONFIG = "mail_config"; + public static final String NAME = "name"; + public static final String NONCE = "nonce"; + public static final String PARAM = "parameter"; + public static final String PERMISSION = "permission"; + public static final String OPENID = "openid"; + public static final String REDIRECT_URI = "redirect_uri"; + public static final String REDIRECT_URIS = "redirect_uris"; + public static final String RELEASE = "release"; + public static final String REQUEST_NOT_SUPPORTED = "request_not_supported"; + public static final String RESPONSE_TYPE = "response_type"; + public static final String SALT = "salt"; + public static final String SCOPE = "scope"; + public static final String SECRET = "secret"; + public static final String SESSION_DURATION = "session_duration"; + public static final String SMTP_USER = "smtp_user"; + public static final String SMTP_PASSWORD = "smtp_pass"; + public static final String SMTP_AUTH = "smtp_auth"; + public static final String SMTP_HOST = "smtp_host"; + public static final String SMTP_PORT = "smtp_port"; + public static final String STATE = "state"; + public static final String START_TLS = "start_tls"; + public static final String TOKEN = "token"; + public static final String TOKEN_TYPE = "token_type"; + public static final String TRUST = "trust"; + public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; + public static final String USER = "user"; + public static final String USER_ID = "user_id"; } diff --git a/de.srsoftware.oidc.app/build.gradle b/de.srsoftware.oidc.app/build.gradle index 54cb89b..cebaba4 100644 --- a/de.srsoftware.oidc.app/build.gradle +++ b/de.srsoftware.oidc.app/build.gradle @@ -44,4 +44,4 @@ jar { from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } -} \ No newline at end of file +} diff --git a/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java b/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java index 231a2f3..0342348 100644 --- a/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java +++ b/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java @@ -53,16 +53,16 @@ public class Application { private static System.Logger LOG = new ColorLogger("Application").setLogLevel(DEBUG); public static void main(String[] args) throws Exception { - var argMap = map(args); - Optional basePath = argMap.get(BASE_PATH) instanceof Path p ? Optional.of(p) : empty(); - var configDir = configDir(APP_NAME); - var defaultFile = configDir.resolve("data.json"); - var configFile = (argMap.get(CONFIG_PATH) instanceof Path p ? p : configDir.resolve("config.json")).toFile(); - var config = new Configuration(configFile); - var encryptionKey = nullable(System.getenv(ENCRYPTION_KEY)).or(() -> config.get(ENCRYPTION_KEY)); - var passHasher = new UuidHasher(); - var firstHash = passHasher.hash(FIRST_USER_PASS, FIRST_UUID); - var firstUser = new User(FIRST_USER, firstHash, FIRST_USER, "%s@internal".formatted(FIRST_USER), FIRST_UUID).add(MANAGE_CLIENTS, MANAGE_PERMISSIONS, MANAGE_SMTP, MANAGE_USERS); + var argMap = map(args); + Optional basePath = argMap.get(BASE_PATH) instanceof Path p ? Optional.of(p) : empty(); + var configDir = configDir(APP_NAME); + var defaultFile = configDir.resolve("data.json"); + var configFile = (argMap.get(CONFIG_PATH) instanceof Path p ? p : configDir.resolve("config.json")).toFile(); + var config = new Configuration(configFile); + var encryptionKey = nullable(System.getenv(ENCRYPTION_KEY)).or(() -> config.get(ENCRYPTION_KEY)); + var passHasher = new UuidHasher(); + var firstHash = passHasher.hash(FIRST_USER_PASS, FIRST_UUID); + var firstUser = new User(FIRST_USER, firstHash, FIRST_USER, "%s@internal".formatted(FIRST_USER), FIRST_UUID).add(MANAGE_CLIENTS, MANAGE_PERMISSIONS, MANAGE_SMTP, MANAGE_USERS); FileStoreProvider fileStoreProvider = new FileStoreProvider(passHasher); diff --git a/de.srsoftware.oidc.web/src/main/resources/de/edit_client.html b/de.srsoftware.oidc.web/src/main/resources/de/edit_client.html index 60e7245..eb3eff3 100644 --- a/de.srsoftware.oidc.web/src/main/resources/de/edit_client.html +++ b/de.srsoftware.oidc.web/src/main/resources/de/edit_client.html @@ -43,6 +43,28 @@ +
+ Client-Konfiguration +

Nutzen Sie die folgenden Daten, um ihren Client einzurichten:

+ + + + + + + + + + + + + + + + + +
Autodiscovery-URL:
Autorization-Endpunkt:
Token-Endpunkt:
Userinfo-Endpunkt:
+
\ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/de/new_client.html b/de.srsoftware.oidc.web/src/main/resources/de/new_client.html index f401625..411df15 100644 --- a/de.srsoftware.oidc.web/src/main/resources/de/new_client.html +++ b/de.srsoftware.oidc.web/src/main/resources/de/new_client.html @@ -42,6 +42,28 @@ +
+ Client-Konfiguration +

Nutzen Sie die folgenden Daten, um ihren Client einzurichten:

+ + + + + + + + + + + + + + + + + +
Autodiscovery-URL:
Autorization-Endpunkt:
Token-Endpunkt:
Userinfo-Endpunkt:
+
diff --git a/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html b/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html index 58e90d0..07675b5 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html +++ b/de.srsoftware.oidc.web/src/main/resources/en/edit_client.html @@ -43,6 +43,28 @@ +
+ Client configuration +

User the following data to set up your client:

+ + + + + + + + + + + + + + + + + +
Autodiscovery URL:
Autorization endpoint:
Token endpoint:
Userinfo endpoint:
+
\ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/new_client.html b/de.srsoftware.oidc.web/src/main/resources/en/new_client.html index abe0305..bedca3d 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/new_client.html +++ b/de.srsoftware.oidc.web/src/main/resources/en/new_client.html @@ -42,6 +42,28 @@ +
+ Client configuration +

User the following data to set up your client:

+ + + + + + + + + + + + + + + + + +
Autodiscovery URL:
Autorization endpoint:
Token endpoint:
Userinfo endpoint:
+
\ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/scripts/edit_client.js b/de.srsoftware.oidc.web/src/main/resources/en/scripts/edit_client.js index 8d1bc49..c8e04ff 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/scripts/edit_client.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/scripts/edit_client.js @@ -1,7 +1,16 @@ var params = new URLSearchParams(window.location.search); var id = params.get('id'); - +function handleAutoDiscover(response){ + if (response.ok){ + response.json().then(json => { + console.log(json); + setText('authorization',json.authorization_endpoint); + setText('token',json.token_endpoint); + setText('userinfo',json.userinfo_endpoint); + }); + } +} function handleLoadResponse(response){ if (response.ok){ response.json().then(json => { @@ -48,11 +57,17 @@ function updateClient(){ setTimeout(resetButton,4000); } -fetch(api+'/client', - { +document.addEventListener("DOMContentLoaded", function(event) { // wait until page loaded + fetch(api+'/client', { method: 'POST', body: JSON.stringify({ client_id : id }), credentials:'include' }).then(handleLoadResponse); + var autodiscover = window.location.origin+'/.well-known/openid-configuration'; + setText('autodiscover',autodiscover); + fetch(autodiscover).then(handleAutoDiscover); +}); + + diff --git a/de.srsoftware.oidc.web/src/main/resources/en/scripts/new_client.js b/de.srsoftware.oidc.web/src/main/resources/en/scripts/new_client.js index 3cbb4d1..464112d 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/scripts/new_client.js +++ b/de.srsoftware.oidc.web/src/main/resources/en/scripts/new_client.js @@ -14,7 +14,7 @@ function addClient(){ }, body : JSON.stringify(newData), credentials:'include' - }).then(handleClientdResponse); + }).then(handleClientResponse); setText('button','sent…'); setTimeout(function(){ @@ -23,7 +23,18 @@ function addClient(){ },10000); } -function handleClientdResponse(response){ +function handleAutoDiscover(response){ + if (response.ok){ + response.json().then(json => { + console.log(json); + setText('authorization',json.authorization_endpoint); + setText('token',json.token_endpoint); + setText('userinfo',json.userinfo_endpoint); + }); + } +} + +function handleClientResponse(response){ if (response.ok){ redirect("clients.html"); } else { @@ -36,4 +47,10 @@ function checkPermissions(){ if (user && !user.permissions.includes('MANAGE_CLIENTS')) redirect("index.html"); } + +document.addEventListener("DOMContentLoaded", function(event) { // wait until page loaded setTimeout(checkPermissions,100); + var autodiscover = window.location.origin+'/.well-known/openid-configuration'; + setText('autodiscover',autodiscover); + fetch(autodiscover).then(handleAutoDiscover); +}); \ No newline at end of file diff --git a/de.srsoftware.oidc.web/src/main/resources/en/style.css b/de.srsoftware.oidc.web/src/main/resources/en/style.css index 492fd01..77640ec 100644 --- a/de.srsoftware.oidc.web/src/main/resources/en/style.css +++ b/de.srsoftware.oidc.web/src/main/resources/en/style.css @@ -67,11 +67,18 @@ body fieldset { display: inline-block; } +code { + font-weight: bold; + color: orange; +} + .wide input, textarea{ width: 600px; } - +th { + padding: 10px; +} input:-webkit-autofill{ filter: none; box-shadow: 0 0 0 100px rgb(38, 103, 152) inset;