-
Notifications
You must be signed in to change notification settings - Fork 2
/
keycloak.js
50 lines (45 loc) · 1.24 KB
/
keycloak.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { boot } from 'quasar/wrappers'
import Keycloak from 'keycloak-js'
export default boot(({ app /* , store } */ }) => {
async function createRefreshTokenTimer(keycloak) {
setInterval(() => {
keycloak.updateToken(60).then((refreshed) => {
if (refreshed) {
console.log("Token refreshed" + refreshed)
} else {
// Do Something
}
}).catch(() => {
console.log("Failed to refresh token")
})
}, 6000)
}
return new Promise(resolve => {
const keycloak = Keycloak({
url: "http://localhost:8080/auth/",
realm: "myrealm",
clientId: "myclient"
})
keycloak
.init({
onLoad: "login-required",
checkLoginIframe: false,
enableLogging: true
})
.then(async (authenticated) => {
if (authenticated) {
console.log("Authenticated")
await createRefreshTokenTimer(keycloak);
resolve()
} else {
console.log("Not authenticated")
// window.location.reload()
}
}).catch((error) => {
console.log("Authentication failure", error)
// window.location.reload()
})
app.config.globalProperties.$keycloak = keycloak
app.use(keycloak)
})
})