@dlukt/vue-oidc-context

OpenID Connect (OIDC) & OAuth 2.0 authentication for Vue 3 — a lightweight, fully typed wrapper around oidc-client-ts, ported from react-oidc-context
511
Install
npm install @dlukt/vue-oidc-context
Latest Version:0.1.2
Vue:3
License:MIT
Last Updated:Oct 21, 2026
Links: GitHub  ·  npm
Maintainer: dalu

vue-oidc-context

CI npm license

OpenID Connect (OIDC) & OAuth 2.0 authentication for Vue 3 — a lightweight, fully typed wrapper around oidc-client-ts, ported from react-oidc-context. Same option names, same lifecycle, same callbacks — exposed as a Vue plugin, composables, components, and a vue-router guard.

Documentation: https://dlukt.github.io/vue-oidc-context/ · API contract: docs/SPEC.md · Roadmap: docs/PLAN.md

Published as @dlukt/vue-oidc-context — the unscoped npm name vue-oidc-context belongs to an unrelated package.

Install

pnpm add @dlukt/vue-oidc-context oidc-client-ts

Peers: vue ≥ 3.5, oidc-client-ts ≥ 3.3, and optionally vue-router 4.2+/5 for the guard.

Quickstart

1. Create the plugin

// main.ts
import { createApp } from "vue";
import { createOidcAuth } from "@dlukt/vue-oidc-context";
import App from "./App.vue";

const auth = createOidcAuth({
  authority: "https://demo.duendesoftware.com",
  client_id: "interactive.public",
  redirect_uri: `${window.location.origin}/`,
  post_logout_redirect_uri: `${window.location.origin}/`,
  onSigninCallback: () => {
    // strip ?code=...&state=... from the URL after the redirect completes
    window.history.replaceState({}, document.title, window.location.pathname);
  },
});

createApp(App).use(auth).mount("#app");

The options object is flat UserManagerSettings + callbacks — a react-oidc-context config works unchanged.

2. Use the auth state

<script setup lang="ts">
import { useAuth } from "@dlukt/vue-oidc-context";

const {
  user,
  isAuthenticated,
  isLoading,
  error,
  signinRedirect,
  signoutRedirect,
} = useAuth();
</script>

<template>
  <div v-if="isLoading">Signing you in/out…</div>
  <div v-else-if="error">Oops… {{ error.message }} ({{ error.source }})</div>
  <template v-else-if="isAuthenticated">
    Hello {{ user?.profile.name }}
    <button @click="signoutRedirect()">Log out</button>
  </template>
  <button v-else @click="signinRedirect()">Log in</button>
</template>

The fields are refs — destructure them (they auto-unwrap in templates). The context also exposes the full UserManager method surface (signinPopup, signinSilent, removeUser, querySessionStatus, …), settings, and the raw events bus.

3. Protect routes (vue-router)

import { createRouter, createWebHistory } from "vue-router";
import { createAuthGuard } from "@dlukt/vue-oidc-context/router";

const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: "/", component: Home },
    { path: "/admin", component: Admin, meta: { requiresAuth: true } },
  ],
});

router.beforeEach(createAuthGuard(auth));

Unauthenticated visits to protected routes redirect to the IdP with state.returnTo set to the target path; restore it in onSigninCallback with void router.replace(returnTo). See Protecting routes for the full recipe (and the pitfalls).

More

License

MIT

Related Packages

oidc-js-vue

Simple OIDC authentication for Vue. Plugin, composables, and navigation guards w...

1,013 3
keycloak-vue

Keycloak plugin for Vue 3.5+ in Composition API

1,043 5
@proteles/vue

Vue 3 composables and components for Proteles authentication, plus Nuxt/h3 serve...

465 0
vue-oidc-context

OpenID Connect & OAuth2 authentication using vue context api as state management

2,871 2
vuethenticate

A Vue 3 authentication state management library using oidc-client-ts

4,051 1

Version History

Version Released Vue License
0.1.2 ^3.5.0 MIT
0.1.1 ^3.5.0 MIT
0.1.0 ^3.5.0 MIT
0.0.0 ^3.5.0 MIT