oidcPlugin
oidcPlugin initializes the OIDC client and provides reactive authentication state to all components via Vue’s dependency injection. Install it with app.use() during app setup.
Installation
Section titled “Installation”npm install oidc-js-vueimport { createApp } from "vue";import { oidcPlugin } from "oidc-js-vue";import App from "./App.vue";
const app = createApp(App);
app.use(oidcPlugin, { config: { issuer: "https://auth.example.com", clientId: "my-app", redirectUri: "http://localhost:5173/callback", scopes: ["openid", "profile", "email", "offline_access"], postLogoutRedirectUri: "http://localhost:5173", },});
app.mount("#app");Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
config | OidcConfig | required | OIDC configuration (issuer, clientId, redirectUri, etc.) |
fetchProfile | boolean | true | Whether to fetch the UserInfo endpoint after login |
onLogin | (returnTo: string) => void | - | Called after successful login with the URL to restore |
onError | (error: Error) => void | - | Called when an error occurs during initialization |
onLogin callback
Section titled “onLogin callback”By default, the plugin restores the pre-login URL using window.history.replaceState. If you use Vue Router, handle navigation yourself:
import { createApp } from "vue";import { oidcPlugin } from "oidc-js-vue";import router from "./router";
const app = createApp(App);app.use(router);
app.use(oidcPlugin, { config: { /* ... */ }, onLogin: (returnTo) => router.replace(returnTo),});
app.mount("#app");Lifecycle
Section titled “Lifecycle”- On install, the plugin creates an
OidcClientand callsclient.init() init()fetches the OIDC discovery document- If the URL contains a
codeandstateparameter (callback from IdP), it exchanges the code for tokens - If the URL contains an
errorparameter, it callsonError - On app unmount, it unsubscribes and destroys the client