2025-01-25 02:23:43 +01:00
|
|
|
import { createApp } from 'vue'
|
|
|
|
import Keycloak from "keycloak-js"
|
2025-01-30 20:34:22 +01:00
|
|
|
import VueKeycloakJs from '@dsb-norge/vue-keycloak-js'
|
2025-01-25 02:23:43 +01:00
|
|
|
import axios from 'axios'
|
|
|
|
import App from './App.vue'
|
2025-01-30 20:34:22 +01:00
|
|
|
import { settings } from "../settings"
|
2025-01-25 02:23:43 +01:00
|
|
|
|
2025-01-30 20:34:22 +01:00
|
|
|
export const authServer = axios.create({
|
2025-01-25 02:23:43 +01:00
|
|
|
baseURL: '/',
|
2025-01-28 19:50:17 +01:00
|
|
|
timeout: 10000
|
2025-01-25 02:23:43 +01:00
|
|
|
})
|
|
|
|
|
2025-01-30 20:34:22 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
return axiosSettings
|
|
|
|
}, error => {
|
|
|
|
return Promise.reject(error)
|
|
|
|
})
|
|
|
|
resourceServer.interceptors.request.use(axiosSettings => {
|
2025-01-25 02:23:43 +01:00
|
|
|
if (keycloak.authenticated) {
|
2025-01-30 20:34:22 +01:00
|
|
|
axiosSettings.headers.Authorization = `Bearer ${keycloak.token}`
|
|
|
|
axiosSettings.headers.auth_provider = settings.auth_provider
|
2025-01-25 02:23:43 +01:00
|
|
|
}
|
2025-01-30 20:34:22 +01:00
|
|
|
return axiosSettings
|
2025-01-25 02:23:43 +01:00
|
|
|
}, error => {
|
|
|
|
return Promise.reject(error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-01-30 20:34:22 +01:00
|
|
|
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)
|
|
|
|
},
|
|
|
|
})
|