Overview
The WSO2 Identity Server Vue SDK (@asgardeo/vue) adds authentication to Vue 3 single-page applications. It gives you a Vue plugin, a root provider component, ready-made components for sign-in, sign-out, user profiles and organizations, and composables that expose the authentication state and methods to your own components.
The SDK is built on the WSO2 Identity Server Browser SDK. It uses the OpenID Connect authorization code flow with PKCE and keeps the session in the browser.
Installation¶
Use one of the following options to install the WSO2 Identity Server Vue SDK.
Getting started¶
Try out the WSO2 Identity Server Vue quickstart guide.
A minimal setup installs the plugin and wraps your app with <AsgardeoProvider>:
import { createApp } from 'vue'
import { AsgardeoPlugin } from '@asgardeo/vue'
import App from './App.vue'
createApp(App).use(AsgardeoPlugin).mount('#app')
<script setup>
import { SignedIn, SignedOut, SignInButton, SignOutButton, UserDropdown } from '@asgardeo/vue'
</script>
<template>
<AsgardeoProvider
client-id="<your-app-client-id>"
base-url="https://localhost:9443"
>
<SignedIn>
<UserDropdown />
<SignOutButton />
</SignedIn>
<SignedOut>
<SignInButton />
</SignedOut>
</AsgardeoProvider>
</template>
Plugin and provider¶
AsgardeoPlugin– The Vue plugin. Install it withapp.use()to register<AsgardeoProvider>globally and add the SDK's styles.<AsgardeoProvider>– The root component that configures the SDK and shares the authentication state with every component inside it.
Components¶
Import components from @asgardeo/vue in the components that use them. Only <AsgardeoProvider> is registered globally by the plugin.
Action components¶
<SignInButton>– A button that starts the sign-in flow.<SignOutButton>– A button that signs the user out.<SignUpButton>– A button that starts the sign-up flow.
Control components¶
<SignedIn>– Renders its content only when the user is signed in.<SignedOut>– Renders its content only when the user is signed out.<Loading>– Renders its content while the SDK is busy.
Authentication components¶
<SignIn>– An embedded sign-in form rendered inside your app.<SignUp>– An embedded self-registration form rendered inside your app.
User self-care components¶
<User>– Exposes the signed-in user through a scoped slot.<UserProfile>– Displays the user's profile and lets them edit it.<UserDropdown>– An avatar button that opens a menu with the user's details, a profile view and sign-out.
Organization components (B2B)¶
<Organization>– Exposes the current organization through a scoped slot.<OrganizationProfile>– Displays the details of the current organization.<OrganizationSwitcher>– A dropdown to switch between the user's organizations.<OrganizationList>– A list of the user's organizations.<CreateOrganization>– A form that creates a new organization.
Internationalization components¶
<LanguageSwitcher>– A dropdown to change the language of the SDK's components.
Composables¶
Call composables from components rendered inside <AsgardeoProvider>.
useAsgardeo()– Authentication state and methods for sign-in, sign-out, tokens and HTTP requests.useUser()– The signed-in user's profile and the schemas that describe it.useOrganization()– The current organization, the user's organizations and organization switching.useI18n()– The current language, language switching and translations.useTheme()– The theme applied to the SDK's components and light or dark mode switching.
Guides¶
- Accessing protected APIs – Call APIs that require the user's access token.
- Protecting routes – Keep signed-out users away from pages with a Vue Router guard.