From 553e85a5d562c1cc70888669b7ab405f3d7f8093 Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 7 Feb 2025 13:20:30 +0100 Subject: [PATCH 01/14] Fix network error message for resource server --- src/App.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 3122449..2a4f53e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,7 +40,11 @@ async function get_resource(id: string) { ).catch( err => { resource.value = [] - msg.value = `${err.message} (${err.response.statusText}): ${err.response.data["detail"]}` + if (err.response) { + msg.value = `${err.message} (${err.response.statusText}): ${err.response.data["detail"]}` + } else { + msg.value = `${err.message} (cannot reach the resource server)` + } } ) } From 88423b26ddc52b83e84a424eb59ee4570120bf01 Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 7 Feb 2025 16:45:27 +0100 Subject: [PATCH 02/14] Follow changes of oidc-test: move all resources to json; use buttons --- public/styles.css | 9 ++---- src/App.vue | 74 +++++++++++++++++++++++++---------------------- src/main.ts | 4 ++- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/public/styles.css b/public/styles.css index 3f9679d..cc7abeb 100644 --- a/public/styles.css +++ b/public/styles.css @@ -170,11 +170,12 @@ hr { gap: 0.5em; flex-flow: wrap; } -.content .links-to-check a { +.content .links-to-check button { color: black; padding: 5px 10px; text-decoration: none; border-radius: 8px; + border: none; } .token { @@ -182,12 +183,6 @@ hr { font-family: monospace; } -.actions { - display: flex; - justify-content: center; - gap: 0.5em; -} - .resource { padding: 0.5em; display: flex; diff --git a/src/App.vue b/src/App.vue index 2a4f53e..7fd21b1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,5 @@ + + diff --git a/src/main.ts b/src/main.ts index f4bc87d..b9bfc24 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { createApp } from 'vue' +import { createApp, ref } from 'vue' import Keycloak from "keycloak-js" import VueKeycloakJs from '@dsb-norge/vue-keycloak-js' import axios, { type AxiosInstance } from 'axios' @@ -15,6 +15,14 @@ interface Settings { tokenSandbox: boolean } +export interface Resource { + name: string +} + +export interface Resources { + [name: string]: Resource +} + export let settings: Settings export let authServer: AxiosInstance export let resourceServer: AxiosInstance @@ -72,8 +80,8 @@ function initializeTokenInterceptor(keycloak: Keycloak) { }) } -async function checkHref(elem: HTMLLinkElement) { - const url = elem.getAttribute("resource-id") +export async function checkResource(elem: HTMLLinkElement) { + const url = elem.getAttribute("resource-name") if (!url) return await resourceServer.get(url).then( resp => { @@ -88,11 +96,11 @@ async function checkHref(elem: HTMLLinkElement) { } function checkPerms(className: string) { + // Scan elements with className and check the respose var rootElems = document.getElementsByClassName(className) Array.from(rootElems).forEach(elem => - Array.from(elem.children).forEach(elem => checkHref(elem)) + Array.from(elem.children).forEach(elem => checkResource(elem)) ) } - const app = createApp(App) From d44bb6218765d6ed5cd10f8534cf8568a8cdc3f2 Mon Sep 17 00:00:00 2001 From: phil Date: Thu, 13 Feb 2025 15:12:17 +0100 Subject: [PATCH 05/14] Fix some typings --- src/App.vue | 41 +++++++++++++++++++++++++---------------- src/ResourceButton.vue | 10 +++++----- src/main.ts | 10 +--------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/App.vue b/src/App.vue index 08c0ee9..2b4aba5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,11 +1,20 @@ + + diff --git a/src/TokenView.vue b/src/TokenView.vue new file mode 100644 index 0000000..91b34eb --- /dev/null +++ b/src/TokenView.vue @@ -0,0 +1,30 @@ + + + diff --git a/src/UserInfo.vue b/src/UserInfo.vue new file mode 100644 index 0000000..cfc1c31 --- /dev/null +++ b/src/UserInfo.vue @@ -0,0 +1,45 @@ + + + diff --git a/src/main.ts b/src/main.ts index b9bfc24..e2ab97d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ -import { createApp, ref } from 'vue' +import { createApp } from 'vue' import Keycloak from "keycloak-js" import VueKeycloakJs from '@dsb-norge/vue-keycloak-js' import axios, { type AxiosInstance } from 'axios' -import App from './App.vue' +import App from '@/App.vue' interface Settings { keycloakUri: string @@ -17,6 +17,9 @@ interface Settings { export interface Resource { name: string + default_resource_id: string + role_required: string + scope_required: string } export interface Resources { @@ -51,14 +54,12 @@ axios.get("settings.json").then().then( }, onReady(keycloak: Keycloak) { initializeTokenInterceptor(keycloak) - checkPerms('links-to-check') + app.mount("#app") }, }) - app.mount("#app") } ) - function initializeTokenInterceptor(keycloak: Keycloak) { authServer.interceptors.request.use(axiosSettings => { if (keycloak.authenticated) { @@ -80,27 +81,4 @@ function initializeTokenInterceptor(keycloak: Keycloak) { }) } -export async function checkResource(elem: HTMLLinkElement) { - const url = elem.getAttribute("resource-name") - if (!url) return - await resourceServer.get(url).then( - resp => { - elem.classList.add("hasResponseStatus") - elem.classList.add("status-" + resp.status) - elem.title = "Response code: " + resp.status + " - " + resp.statusText - }).catch(err => { - elem.classList.add("hasResponseStatus") - elem.classList.add("status-" + err.response.status) - elem.title = "Response code: " + err.response.status + " - " + err.response.statusText - }) -} - -function checkPerms(className: string) { - // Scan elements with className and check the respose - var rootElems = document.getElementsByClassName(className) - Array.from(rootElems).forEach(elem => - Array.from(elem.children).forEach(elem => checkResource(elem)) - ) -} - const app = createApp(App) From 7a379934399d53797d83cb361aff6ab40d497c2a Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 21 Feb 2025 01:20:35 +0100 Subject: [PATCH 07/14] Fix typo --- src/TokenView.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TokenView.vue b/src/TokenView.vue index 91b34eb..b8287bf 100644 --- a/src/TokenView.vue +++ b/src/TokenView.vue @@ -9,21 +9,21 @@ const keycloak = useKeycloak()

id token

-
+

access token

-
+

refresh token

-
+
From d2dcfb6e2e52eef3b90ab75407aaf540ae86a39e Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 21 Feb 2025 13:45:18 +0100 Subject: [PATCH 08/14] Support third party resource providers --- public/styles.css | 3 +++ src/App.vue | 27 +++++++++++++++---- src/ResourceButton.vue | 10 ++++--- src/main.ts | 60 +++++++++++++++++++++++++++++++++--------- 4 files changed, 80 insertions(+), 20 deletions(-) diff --git a/public/styles.css b/public/styles.css index 36de6da..8d4804f 100644 --- a/public/styles.css +++ b/public/styles.css @@ -178,6 +178,9 @@ hr { border: none; cursor: pointer; } +.content .links-to-check span { + margin: auto; +} .token { overflow-wrap: anywhere; diff --git a/src/App.vue b/src/App.vue index c120088..006f88b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,9 @@