Plugin-vuejs-keycloak
Vue.js with Keycloak authentication
This plugin integrates VueJS with Keycloak to perform authentication and configuration of the authorization to send requests to the backend.
Requirements
- Vue ^2.0.0
- Vuex ^2.0.0
- axios ^0.17.0
Installation
$ npm install --save plugin-vuejs-keycloak
Setup
Put the frontend settings in /src/static/keycloak.json
file that will be used to authenticate to Keycloak.
Put the plugin at VueJS startup
// The Vue build version to load with the `import` command// (runtime-only or standalone) has been set in webpack.base.conf with an alias. /* eslint-disable no-new */ el: '#app' router store template: '<App/>' components: App
Configure the vue-router
for to use plugin-vuejs-keycloak
on verification of the routes.
Vue { // '@' is aliased to src/components return import`@/.vue`} const routes = path: '/' component: meta: requiresAuth: true roles: 'user' children: path: '' name: 'home' component: meta: requiresAuth: true roles: 'user' path: '*' component: // Not found path: '/unauthorized' name: 'Unauthorized' component: // Unauthorized const router = /* * NOTE! VueRouter "history" mode DOESN'T works for Cordova builds, * it is only to be used only for websites. * * If you decide to go with "history" mode, please also open /config/index.js * and set "build.publicPath" to something other than an empty string. * Example: '/' instead of current '' * * If switching back to default "hash" mode, don't forget to set the * build publicPath back to '' so Cordova builds work again. */ mode: 'history' y: 0 routes router