@dsb-norge/vue-keycloak-js
Advanced tools
Comparing version 2.2.0 to 2.3.0
/*! | ||
* vue-keycloak-js v2.2.0 | ||
* vue-keycloak-js v2.3.0 | ||
* @license ISC | ||
@@ -152,2 +152,3 @@ */ | ||
const keycloak = Keycloak__default["default"](config); | ||
const { updateInterval } = options; | ||
keycloak.onReady = function (authenticated) { | ||
@@ -163,3 +164,3 @@ updateWatchVariables(authenticated); | ||
keycloak.clearToken(); | ||
}), 10000); | ||
}), updateInterval !== null && updateInterval !== void 0 ? updateInterval : 10000); | ||
watch.logoutFn = () => { | ||
@@ -180,2 +181,7 @@ clearInterval(updateTokenInterval); | ||
}; | ||
keycloak.onAuthLogout = function () { | ||
updateWatchVariables(false); | ||
typeof options.onAuthLogout === 'function' && | ||
options.onAuthLogout(keycloak); | ||
}; | ||
keycloak | ||
@@ -228,3 +234,3 @@ .init(options.init) | ||
function assertOptions(options) { | ||
const { config, init, onReady, onInitError, onAuthRefreshError } = options; | ||
const { config, init, onReady, onInitError, onAuthRefreshError, onAuthLogout } = options; | ||
if (typeof config !== 'string' && !_isObject(config)) { | ||
@@ -260,2 +266,8 @@ return { | ||
} | ||
if (onAuthLogout && typeof onAuthLogout !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onAuthLogout' option must be a function. Found: '${onAuthLogout}'`, | ||
}; | ||
} | ||
return { | ||
@@ -262,0 +274,0 @@ hasError: false, |
/*! | ||
* vue-keycloak-js v2.2.0 | ||
* vue-keycloak-js v2.3.0 | ||
* @license ISC | ||
@@ -127,2 +127,3 @@ */ | ||
const keycloak = Keycloak(config); | ||
const { updateInterval } = options; | ||
keycloak.onReady = function (authenticated) { | ||
@@ -138,3 +139,3 @@ updateWatchVariables(authenticated); | ||
keycloak.clearToken(); | ||
}), 10000); | ||
}), updateInterval !== null && updateInterval !== void 0 ? updateInterval : 10000); | ||
watch.logoutFn = () => { | ||
@@ -155,2 +156,7 @@ clearInterval(updateTokenInterval); | ||
}; | ||
keycloak.onAuthLogout = function () { | ||
updateWatchVariables(false); | ||
typeof options.onAuthLogout === 'function' && | ||
options.onAuthLogout(keycloak); | ||
}; | ||
keycloak | ||
@@ -203,3 +209,3 @@ .init(options.init) | ||
function assertOptions(options) { | ||
const { config, init, onReady, onInitError, onAuthRefreshError } = options; | ||
const { config, init, onReady, onInitError, onAuthRefreshError, onAuthLogout } = options; | ||
if (typeof config !== 'string' && !_isObject(config)) { | ||
@@ -235,2 +241,8 @@ return { | ||
} | ||
if (onAuthLogout && typeof onAuthLogout !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onAuthLogout' option must be a function. Found: '${onAuthLogout}'`, | ||
}; | ||
} | ||
return { | ||
@@ -237,0 +249,0 @@ hasError: false, |
/*! | ||
* vue-keycloak-js v2.2.0 | ||
* vue-keycloak-js v2.3.0 | ||
* @license ISC | ||
@@ -153,2 +153,3 @@ */ | ||
const keycloak = Keycloak__default["default"](config); | ||
const { updateInterval } = options; | ||
keycloak.onReady = function (authenticated) { | ||
@@ -164,3 +165,3 @@ updateWatchVariables(authenticated); | ||
keycloak.clearToken(); | ||
}), 10000); | ||
}), updateInterval !== null && updateInterval !== void 0 ? updateInterval : 10000); | ||
watch.logoutFn = () => { | ||
@@ -181,2 +182,7 @@ clearInterval(updateTokenInterval); | ||
}; | ||
keycloak.onAuthLogout = function () { | ||
updateWatchVariables(false); | ||
typeof options.onAuthLogout === 'function' && | ||
options.onAuthLogout(keycloak); | ||
}; | ||
keycloak | ||
@@ -229,3 +235,3 @@ .init(options.init) | ||
function assertOptions(options) { | ||
const { config, init, onReady, onInitError, onAuthRefreshError } = options; | ||
const { config, init, onReady, onInitError, onAuthRefreshError, onAuthLogout } = options; | ||
if (typeof config !== 'string' && !_isObject(config)) { | ||
@@ -261,2 +267,8 @@ return { | ||
} | ||
if (onAuthLogout && typeof onAuthLogout !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onAuthLogout' option must be a function. Found: '${onAuthLogout}'`, | ||
}; | ||
} | ||
return { | ||
@@ -263,0 +275,0 @@ hasError: false, |
@@ -15,7 +15,9 @@ import type { KeycloakConfig, KeycloakError, KeycloakInitOptions, KeycloakLoginOptions, KeycloakProfile, KeycloakPromise, KeycloakResourceAccess, KeycloakRoles, KeycloakTokenParsed } from 'keycloak-js'; | ||
logout?: any; | ||
updateInterval?: number; | ||
onReady?: (keycloak: Keycloak, VueKeycloak?: VueKeycloakInstance) => void; | ||
onInitError?: (error: Error, err: KeycloakError) => void; | ||
onAuthLogout?: (keycloak: Keycloak) => void; | ||
onAuthRefreshError?: (keycloak: Keycloak) => void; | ||
onAuthRefreshSuccess?: (keycloak: Keycloak) => void; | ||
onInitSuccess?(authenticated: boolean, keycloak?: Keycloak, VueKeycloak?: VueKeycloakInstance): void; | ||
onInitSuccess?(authenticated: boolean): void; | ||
} | ||
@@ -22,0 +24,0 @@ export interface VueKeycloakTokenParsed extends KeycloakTokenParsed { |
{ | ||
"name": "@dsb-norge/vue-keycloak-js", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "Nils Lien", | ||
@@ -27,16 +27,16 @@ "description": "A Keycloak plugin for Vue >= 2.x", | ||
"devDependencies": { | ||
"@babel/eslint-parser": "7.19.1", | ||
"@babel/core": "7.20.12", | ||
"@babel/preset-env": "7.20.2", | ||
"@babel/eslint-parser": "7.21.8", | ||
"@babel/core": "7.22.1", | ||
"@babel/preset-env": "7.22.4", | ||
"@rollup/plugin-babel": "5.3.1", | ||
"@rollup/plugin-commonjs": "22.0.2", | ||
"@rollup/plugin-node-resolve": "13.3.0", | ||
"@typescript-eslint/eslint-plugin": "5.49.0", | ||
"@typescript-eslint/parser": "5.49.0", | ||
"eslint": "8.32.0", | ||
"@typescript-eslint/eslint-plugin": "5.59.8", | ||
"@typescript-eslint/parser": "5.59.8", | ||
"eslint": "8.41.0", | ||
"rollup": "2.79.1", | ||
"rollup-plugin-terser": "7.0.2", | ||
"rollup-plugin-typescript2": "0.34.1", | ||
"typescript": "4.9.4", | ||
"vue": "3.2.45" | ||
"typescript": "4.9.5", | ||
"vue": "3.2.47" | ||
}, | ||
@@ -49,4 +49,2 @@ "peerDependencies": { | ||
"dev": "rollup -c -w", | ||
"version": "npm run build && git add -A", | ||
"postversion": "git push -u --follow-tags origin main && npm publish", | ||
"lint": "eslint --ext .ts src", | ||
@@ -53,0 +51,0 @@ "lint:fix": "eslint --ext .ts src --fix" |
@@ -150,9 +150,13 @@ vue-keycloak plugin | ||
| Key | Type | Default | | ||
|---------------|----------------------|----------------------------------| | ||
| `config` | String | Object | `window.__BASEURL__ + '/config'` | | ||
| `init` | Object | `{onLoad: 'login-required'}` | | ||
| `logout` | Object | | | ||
| `onReady` | Function(keycloak) | | | ||
| `onInitError` | Function(error) | | | ||
| Key | Type | Default | | ||
| ---------------------- | ------------------------------ | -------------------------------- | | ||
| `config` | String | Object | `window.__BASEURL__ + '/config'` | | ||
| `init` | Object | `{onLoad: 'login-required'}` | | ||
| `logout` | Object | | | ||
| `onReady` | Function(keycloak) | | | ||
| `onInitError` | Function(error, keycloakError) | | | ||
| `onInitSuccess` | Function(authenticated) | | | ||
| `onAuthLogout` | Function(keycloak) | | | ||
| `onAuthRefreshError` | Function(keycloak) | | | ||
| `onAuthRefreshSuccess` | Function(keycloak) | | | ||
@@ -266,2 +270,29 @@ ### config | ||
### onInitSuccess | ||
This option is a callback function that is executed if Keycloak initialisation has succeeded. | ||
The callback function has one parameter, which is the `authenticated` value returned by Keycloak's `init` method. | ||
### onAuthLogout | ||
This option is a callback function that is executed if the user is logged out (will only be called if the session status iframe is enabled, or in Cordova mode). | ||
The callback function has one parameter, which is the keycloak object returned from the Keycloak adapter on | ||
instantiation. | ||
### onAuthRefreshError | ||
This option is a callback function that is executed if there was an error while trying to refresh the token. | ||
The callback function has one parameter, which is the keycloak object returned from the Keycloak adapter on | ||
instantiation. | ||
### onAuthRefreshSuccess | ||
This option is a callback function that is executed when the token is refreshed. | ||
The callback function has one parameter, which is the keycloak object returned from the Keycloak adapter on | ||
instantiation. | ||
## Examples | ||
@@ -366,12 +397,13 @@ | ||
## Develop and deploy | ||
## How to release | ||
```bash | ||
$ git clone https://github.com/dsb-norge/vue-keycloak-js.git | ||
# Do some work, add and/or commit to git. | ||
$ npm version patch | ||
$ git checkout main | ||
$ npm version [major | minor | patch ] | ||
$ git push | ||
$ git push --tags | ||
``` | ||
The command `npm version patch` will automatically run the build, push the branch upstream and publish the package to | ||
the NPM registry. | ||
Go to GitHub and create a new release based on the latest tag. | ||
GitHub Actions will then build and publish the release to npmjs.com. | ||
@@ -378,0 +410,0 @@ ## Frequently asked questions |
54939
912
422