vue3-oidc
📦 Install
pnpm i vue3-oidc
Running the Server Sample
$ cd example/server
$ npm install
$ npm run build
Running the Client Sample
$ cd example/client
$ npm install
$ npm run dev

Getting Started
Configure the library by wrapping your application in createOidc and your initialization application when run createOidc:
//main.ts
import { createApp } from "vue";
import App from "./App.vue";
import "./oidc";
import router from "./router";
const app = createApp(App);
app.use(router);
app.mount("#app");
//oidc.ts
import type { VueOidcSettings } from "vue3-oidc";
import { createOidc, useOidcStore, useAuth } from "vue3-oidc";
import { unref } from "vue";
const { state } = useOidcStore();
const { setRedirectUri } = useAuth();
const oidcSettings: VueOidcSettings = {
authority: "http://localhost:4000",
scope: "openid",
client_id: "your client id",
client_secret: "your client secret",
redirect_uri: origin + "/oidc-callback",
response_type: "code",
loadUserInfo: true,
onSigninRedirectCallback(user) {
console.log(user);
location.href = unref(state).redirect_uri || "/";
},
onBeforeSigninRedirectCallback() {
setRedirectUri(location.pathname + location.search);
},
};
createOidc({
oidcSettings: oidcSettings, //your oidc settings
auth: true, //if auth is true,will auto authenticate
events: {}, //your oidc customization callback events
refreshToken: {
enable: true,
time: 30000,
},
//your key customization of oidc redirect callback
redirectUriKey: "CUSTOM_REDIRECT_URI",
});
API
- useOidcStore
//type
import type { UserProfile } from "oidc-client-ts";
function useOidcStore<T>(): {
state: ComputedRef<OidcState<T>>;
actions: ComputedRef<OidcActions>;
};
interface OidcState<T = UserProfile> {
oidcSettings: MaybeNull<VueOidcSettings>;
userManager: MaybeNull<UserManager>;
refreshUserManager: MaybeNull<UserManager>;
user: MaybeNull<OidcUser<T>>;
token: ComputedRef<string | null>;
hasExpiresAt: ComputedRef<boolean>;
redirect_uri: string;
}
interface OidcActions {
setUser(user: User): void;
removeUser(): void;
}
type OidcUser<T = UserProfile> = User & {
profile: UseUserProfile<T>;
};
type UseUserProfile<T = UserProfile> = T;
- useAuth
//type
function useAuth(): {
autoAuthenticate: typeof autoAuthenticate;
signinRedirect: typeof signinRedirect;
signoutRedirect: typeof signoutRedirect;
refreshToken: typeof refreshToken;
setRedirectUri: typeof setRedirectUri;
};
//autoAuthenticate - will try to authenticate the user silently
function autoAuthenticate(): Promise<void>;
//signin callback
function signinRedirect(arg?: SigninRedirectArgs): void;
//signout callback
function signoutRedirect(arg?: SignoutRedirectArgs): void;
//refresh token
function refreshToken(
arg?: SigninSilentArgs,
success?: (user: User | null) => void | Promise<void>,
fail?: (err: any) => void | Promise<void>
): void;
//setRedirectUri
function setRedirectUri(uri: string): void;
Related Packages
vue-oidc-client
Wrapper around oidc-client-js to to better work in a Vue application with Vue Ro...
96,754
105
vue-oidc-client-deep-linking
Wrapper around oidc-client-js to better work in a Vue application with Vue Route...
2,792
105
jl-vue-oidc-client
Wrapper around oidc-client-js to to better work in a Vue application with Vue Ro...
2,699
Version History
| Version | Released | License |
|---|---|---|
| 1.0.2 | ISC | |
| 1.0.1 | ISC | |
| 1.0.0 | ISC | |
| 0.1.17 | ISC | |
| 0.1.16 | ISC | |
| 0.1.15 | ISC | |
| 0.1.14 | ISC | |
| 0.1.13 | ISC | |
| 0.1.12 | ISC | |
| 0.1.11 | ISC | |
| 0.1.10 | ISC | |
| 0.1.9 | ISC | |
| 0.1.8 | ISC | |
| 0.1.7 | ISC | |
| 0.1.5 | ISC | |
| 0.1.4 | ISC | |
| 0.1.3 | ISC | |
| 0.1.2 | ISC | |
| 0.1.1 | ISC | |
| 0.1.0 | ISC | |
| 0.0.12 | ISC | |
| 0.0.11 | ISC | |
| 0.0.10 | ISC | |
| 0.0.9 | ISC | |
| 0.0.8 | ISC | |
| 0.0.7 | ISC | |
| 0.0.6 | ISC | |
| 0.0.5 | ISC | |
| 0.0.4 | ISC | |
| 0.0.3 | ISC |
Showing the latest 30 of 32. See every release on npm