@dsb-norge/vue-keycloak-js
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "@dsb-norge/vue-keycloak-js", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"author": "Nils Lien <nils.lien@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "A Keycloak plugin for Vue >= 2.x", |
126
README.md
@@ -60,18 +60,39 @@ vue-keycloak plugin | ||
The plugin adds a `$keycloak` property to the global Vue instance. | ||
This is actually a new Vue instance and can be used as such. It holds this data: | ||
This is actually a new Vue instance and can be used as such. | ||
It shadows most of the keycloak instance's properties and functions, | ||
with the exception of the callback events, which the plugin needs to control itself. | ||
These properties/functions are exposed: | ||
``` | ||
{ | ||
ready: Boolean, // Flag indicating whether Keycloak has initialised and is ready | ||
ready: Boolean, // Flag indicating whether Keycloak has initialised and is ready | ||
authenticated: Boolean, | ||
userName: String, // Username from Keycloak. Collected from tokenParsed['preferred_username'] | ||
fullName: String, // Full name from Keycloak. Collected from tokenParsed['name'] | ||
logoutFn: Function, // App+Keycloak logout function | ||
loginFn: Function, // App+Keycloak login function | ||
createLoginUrl: Function, // Keycloak createLoginUrl function | ||
createLogoutUrl: Function, // Keycloak createLogoutUrl function | ||
hasRealmRole: Function, // Keycloak hasRealmRole function | ||
hasResourceRole: Function, // Keycloak hasResourceRole function | ||
token: String, // The base64 encoded token that can be sent in the Authorization header in requests to services | ||
tokenParsed: String // The parsed token as a JavaScript object | ||
userName: String, // Username from Keycloak. Collected from tokenParsed['preferred_username'] | ||
fullName: String, // Full name from Keycloak. Collected from tokenParsed['name'] | ||
login: Function, // [Keycloak] login function | ||
loginFn: Function, // Alias for login | ||
logoutFn: Function, // Keycloak logout function | ||
createLoginUrl: Function, // Keycloak createLoginUrl function | ||
createLogoutUrl: Function, // Keycloak createLogoutUrl function | ||
createRegisterUrl: Function, // Keycloak createRegisterUrl function | ||
register: Function, // Keycloak register function | ||
accountManagement: Function, // Keycloak accountManagement function | ||
createAccountUrl: Function, // Keycloak createAccountUrl function | ||
loadUserProfile: Function, // Keycloak loadUserProfile function | ||
loadUserInfo: Function, // Keycloak loadUserInfo function | ||
subject: String, // The user id | ||
idToken: String, // The base64 encoded ID token. | ||
idTokenParsed: Object, // The parsed id token as a JavaScript object. | ||
realmAccess: Object, // The realm roles associated with the token. | ||
resourceAccess: Object, // The resource roles associated with the token. | ||
refreshToken: String, // The base64 encoded refresh token that can be used to retrieve a new token. | ||
refreshTokenParsed: Object, // The parsed refresh token as a JavaScript object. | ||
timeSkew: Number, // The estimated time difference between the browser time and the Keycloak server in seconds. This value is just an estimation, but is accurate enough when determining if a token is expired or not. | ||
responseMode: String, // Response mode passed in init (default value is fragment). | ||
responseType: String, // Response type sent to Keycloak with login requests. This is determined based on the flow value used during initialization, but can be overridden by setting this value. | ||
hasRealmRole: Function, // Keycloak hasRealmRole function | ||
hasResourceRole: Function, // Keycloak hasResourceRole function | ||
token: String, // The base64 encoded token that can be sent in the Authorization header in requests to services | ||
tokenParsed: String // The parsed token as a JavaScript object | ||
} | ||
@@ -160,5 +181,5 @@ ``` | ||
The callback function has one parameter, which is the keycloak object returned from the Keycloak adapter on | ||
instatiation. | ||
instantiation. | ||
One use case for this callback could be to instatiate and mount the Vue application. Then we are sure that the Keycloak | ||
One use case for this callback could be to instantiate and mount the Vue application. Then we are sure that the Keycloak | ||
authentication and the `$keycloak` property are properly finished and hydrated with data: | ||
@@ -181,3 +202,3 @@ | ||
In conjuction with the above, you might find it useful to intercept e.g. axios and set the token on each request: | ||
In conjunction with the above, you might find it useful to intercept e.g. axios and set the token on each request: | ||
@@ -208,2 +229,77 @@ ```javascript | ||
## Examples | ||
### Supply a configuration object for the Keycloak constructor | ||
```javascript | ||
Vue.use(VueKeyCloak, { | ||
config: { | ||
realm: 'MyRealm', | ||
url: 'https://my.keycloak.server/auth', | ||
clientId: 'MyClientId' | ||
}, | ||
onReady: kc => { | ||
new Vue({ | ||
render: h => h(App) | ||
}).$mount('#app') | ||
} | ||
}) | ||
``` | ||
### Supply init option (disable monitoring login state) | ||
```javascript | ||
Vue.use(VueKeyCloak, { | ||
init: { | ||
onLoad: 'login-required', | ||
checkLoginIframe: false | ||
}, | ||
onReady: kc => { | ||
new Vue({ | ||
render: h => h(App) | ||
}).$mount('#app') | ||
} | ||
}) | ||
``` | ||
### Supply init option (use `check-sso`) | ||
Remember; `login-required` is the default value for the onLoad property | ||
in the init object. So without passing an `init` object as argument, the default is | ||
`{ init: 'login-required' }` | ||
```javascript | ||
Vue.use(VueKeyCloak, { | ||
init: { | ||
onLoad: 'check-sso' | ||
}, | ||
onReady: kc => { | ||
new Vue({ | ||
render: h => h(App) | ||
}).$mount('#app') | ||
} | ||
}) | ||
``` | ||
### Specify a `redirectUri` | ||
```javascript | ||
Vue.use(VueKeyCloak, { | ||
logout: { | ||
redirectUri: 'https://mydomain.lives.here.com' | ||
}, | ||
onReady: kc => { | ||
new Vue({ | ||
render: h => h(App) | ||
}).$mount('#app') | ||
} | ||
}) | ||
``` | ||
### Example application | ||
View a complete example app, with router guards: | ||
[hello-keycloak](https://github.com/dsb-norge/vue-keycloak-js/tree/master/examples) | ||
## Develop and deploy | ||
@@ -210,0 +306,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
222066
4795
311