A comprehensive Vue 3.5+ wrapper for keycloak-js using the Composition API. This library provides a seamless integration of Keycloak authentication into your Vue applications with full TypeScript support.
For complete documentation, examples, and API reference, visit:
- β¨ Features
- π Quick Start
- π¦ Installation
- π§ Basic Usage
- π Documentation
- π Links
- π€ Contributing
- π License
- β¨ Vue 3.5+ Composition API - Built for modern Vue applications
- π Type-Safe - Full TypeScript definitions for all Keycloak types, props, and constants
- π― Reactive State - Reactive authentication state using Vue's reactivity system
- π Plugin System - Easy integration with Vue's plugin system
- π‘οΈ Vue Router Integration - Built-in support for route guards and authentication flows
- π IIFE Compatible - Supports older browsers without top-level await
- π¨ Flexible - Use as a plugin or composable
- π¦ Tree-Shakeable - Import only what you need
- π SSO Ready - Full support for Single Sign-On features
- π Token Management - Automatic token refresh capabilities
Get started in just 2 steps:
npm install keycloak-vue keycloak-js// main.ts
import { createApp } from "vue";
import { createKeycloakPlugin } from "keycloak-vue";
import App from "./App.vue";
const app = createApp(App);
app.use(
createKeycloakPlugin({
config: {
url: "https://your-keycloak-server",
realm: "your-realm",
clientId: "your-client-id",
},
initOptions: {
onLoad: "login-required",
},
})
);
app.mount("#app");<script setup lang="ts">
import { useKeycloak } from "keycloak-vue";
const { isAuthenticated, username, login, logout } = useKeycloak();
</script>
<template>
<div v-if="isAuthenticated">
<p>Welcome, {{ username }}!</p>
<button @click="logout()">Logout</button>
</div>
<div v-else>
<button @click="login()">Login</button>
</div>
</template>That's it! π
npm install keycloak-vue keycloak-jsor
yarn add keycloak-vue keycloak-jsor
pnpm add keycloak-vue keycloak-js// main.ts
import { createApp } from "vue";
import { createKeycloakPlugin } from "keycloak-vue";
import App from "./App.vue";
const app = createApp(App);
app.use(
createKeycloakPlugin({
config: {
url: "https://your-keycloak-server",
realm: "your-realm",
clientId: "your-client-id",
},
initOptions: {
onLoad: "login-required",
checkLoginIframe: false,
},
})
);
app.mount("#app");<script setup lang="ts">
import { useKeycloak } from "keycloak-vue";
const {
isAuthenticated,
isReady,
username,
token,
login,
logout,
hasRealmRole,
} = useKeycloak();
</script>
<template>
<div v-if="isReady">
<div v-if="isAuthenticated">
<p>Welcome, {{ username }}!</p>
<button @click="logout()">Logout</button>
<div v-if="hasRealmRole('admin')">
<p>Admin content</p>
</div>
</div>
<div v-else>
<button @click="login()">Login</button>
</div>
</div>
<div v-else>Loading...</div>
</template>Our documentation includes:
- π Getting Started Guide - Step-by-step setup
- βοΈ Configuration - All configuration options
- π― API Reference - Complete API documentation
- π‘ Examples - Real-world use cases
- π§ Advanced Usage - Manual initialization and more
| Topic | Description | Link |
|---|---|---|
| π Installation | How to install and setup | Guide |
| π Plugin Setup | Vue plugin configuration | Guide |
| π― Composable | Using useKeycloak() |
API |
| π Token Refresh | Automatic token refresh | Example |
| π‘οΈ Protected APIs | Making authenticated requests | Example |
| π₯ Role-Based Access | User roles and permissions | Example |
| π£οΈ Router Integration | Vue Router guards | Guide |
- π Documentation - Complete documentation
- π¦ NPM Package - Package on NPM
- π GitHub Repository - Source code
- π Keycloak - Official Keycloak website
- π Keycloak JS Adapter - Official JS adapter docs
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Released under the MIT License.