Move settings as dynamic json file; nice token info display
This commit is contained in:
parent
14c9091e77
commit
d17ba9f735
5 changed files with 106 additions and 42 deletions
76
src/main.ts
76
src/main.ts
|
@ -1,25 +1,62 @@
|
|||
import { createApp } from 'vue'
|
||||
import Keycloak from "keycloak-js"
|
||||
import VueKeycloakJs from '@dsb-norge/vue-keycloak-js'
|
||||
import axios from 'axios'
|
||||
import axios, { type AxiosInstance } from 'axios'
|
||||
import App from './App.vue'
|
||||
import { settings } from "../settings"
|
||||
|
||||
export const authServer = axios.create({
|
||||
baseURL: '/',
|
||||
timeout: 10000
|
||||
})
|
||||
interface Settings {
|
||||
keycloakUri: string
|
||||
realm: string
|
||||
clientId: string
|
||||
sso: boolean
|
||||
resourceServerUrl: string
|
||||
resourceScopes: string[]
|
||||
authProvider: string
|
||||
sslCertFile: string
|
||||
sslKeyFile: string
|
||||
tokenSandbox: boolean
|
||||
}
|
||||
|
||||
|
||||
export let settings: Settings
|
||||
export let authServer: AxiosInstance
|
||||
export let resourceServer: AxiosInstance
|
||||
|
||||
axios.get("settings.json").then().then(
|
||||
resp => {
|
||||
settings = resp.data
|
||||
resourceServer = axios.create({
|
||||
baseURL: settings.resourceServerUrl,
|
||||
timeout: 10000
|
||||
})
|
||||
authServer = axios.create({
|
||||
baseURL: '/',
|
||||
timeout: 10000
|
||||
})
|
||||
app.use(VueKeycloakJs, {
|
||||
config: {
|
||||
url: settings.keycloakUri,
|
||||
realm: settings.realm,
|
||||
clientId: settings.clientId
|
||||
},
|
||||
init: {
|
||||
onLoad: settings.sso ? "check-sso" : "login-required",
|
||||
scope: "openid email profile " + settings.resourceScopes.join(" ")
|
||||
},
|
||||
onReady(keycloak: Keycloak) {
|
||||
initializeTokenInterceptor(keycloak)
|
||||
},
|
||||
})
|
||||
app.mount("#app")
|
||||
}
|
||||
)
|
||||
|
||||
export const resourceServer = axios.create({
|
||||
baseURL: settings.url,
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
function initializeTokenInterceptor(keycloak: Keycloak) {
|
||||
authServer.interceptors.request.use(axiosSettings => {
|
||||
if (keycloak.authenticated) {
|
||||
axiosSettings.headers.Authorization = `Bearer ${keycloak.token}`
|
||||
axiosSettings.headers.auth_provider = settings.auth_provider
|
||||
axiosSettings.headers.auth_provider = settings.authProvider
|
||||
}
|
||||
return axiosSettings
|
||||
}, error => {
|
||||
|
@ -28,7 +65,7 @@ function initializeTokenInterceptor(keycloak: Keycloak) {
|
|||
resourceServer.interceptors.request.use(axiosSettings => {
|
||||
if (keycloak.authenticated) {
|
||||
axiosSettings.headers.Authorization = `Bearer ${keycloak.token}`
|
||||
axiosSettings.headers.auth_provider = settings.auth_provider
|
||||
axiosSettings.headers.auth_provider = settings.authProvider
|
||||
}
|
||||
return axiosSettings
|
||||
}, error => {
|
||||
|
@ -37,18 +74,3 @@ function initializeTokenInterceptor(keycloak: Keycloak) {
|
|||
}
|
||||
|
||||
const app = createApp(App)
|
||||
app.mount('#app')
|
||||
app.use(VueKeycloakJs, {
|
||||
config: {
|
||||
url: 'https://philo.ydns.eu/auth/',
|
||||
realm: 'test',
|
||||
clientId: 'oidc-test-web',
|
||||
},
|
||||
init: {
|
||||
onLoad: settings.sso ? 'check-sso' : 'login-required',
|
||||
scope: "openid email profile get:time get:bs"
|
||||
},
|
||||
onReady(keycloak: Keycloak) {
|
||||
initializeTokenInterceptor(keycloak)
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue