Overview
The WSO2 Identity Server JavaScript SDK (@asgardeo/javascript) is the framework-agnostic core that every WSO2 Identity Server JavaScript SDK is built on. It implements the OpenID Connect authorization code flow with PKCE, token handling, ID token validation and session storage, and ships typed functions for the WSO2 Identity Server REST APIs. It has no dependency on a browser, a server runtime or a UI framework: you plug in the storage and cryptography for your platform.
Warning
Don't use this package directly in an application. Use the SDK for your framework or platform instead. Each one is built on this package and handles storage, cryptography, redirects and session management for you.
Use @asgardeo/javascript only when you build an integration or an SDK for a platform that none of these cover.
Installation¶
Use one of the following options to install the WSO2 Identity Server JavaScript SDK.
How an integration fits together¶
An integration creates an AsgardeoAuthClient, and gives it three things when it calls initialize():
- Configuration – The application's client ID, redirect URLs and the WSO2 Identity Server endpoints.
- A store – An object that implements the
Storageinterface. The client keeps its configuration, the OpenID provider metadata, the PKCE code verifier and the user's tokens in it. - Crypto utilities – An object that implements the
Cryptointerface. The client uses it to create PKCE values, decode tokens and verify the ID token signature.
The client builds URLs and talks to the WSO2 Identity Server token, revocation and JWKS endpoints with fetch. Your integration is responsible for redirecting the user, reading the authorization code from the callback, and deciding where the store keeps its data.
import { AsgardeoAuthClient } from "@asgardeo/javascript";
const auth = new AsgardeoAuthClient();
await auth.initialize(
{
afterSignInUrl: "http://localhost:3000/callback",
afterSignOutUrl: "http://localhost:3000",
clientId: "<your-app-client-id>",
baseUrl: "https://localhost:9443"
},
myStore, // implements Storage
myCrypto // implements Crypto
);
// Send the user to this URL to sign in.
const signInUrl = await auth.getSignInUrl();
APIs¶
The SDK provides the following APIs.
Authentication client¶
AsgardeoAuthClient– The core OpenID Connect client. Builds sign-in and sign-out URLs, exchanges and refreshes tokens, and reads the session.AsgardeoJavaScriptClient– The base class that the Browser and Node.js SDK clients extend. Adds agent and organization token flows on top ofAsgardeoAuthClient.- Configuration – The options that
AsgardeoAuthClient.initialize()accepts.
Interfaces to implement¶
Storage– The key-value store that holds configuration, provider metadata and session data.Crypto– Encoding, hashing, random bytes and JWT verification for the platform.
REST API functions¶
- REST API functions – Standalone functions for the user profile (SCIM2), organization, branding and app-native authentication APIs.
Errors¶
The functions and the client throw these error types:
AsgardeoAuthException– Thrown byAsgardeoAuthClient. Hascode,nameandmessage.AsgardeoAPIError– Thrown by the REST API functions. ExtendsAsgardeoErrorand addsstatusCodeandstatusText.AsgardeoRuntimeError– Thrown for invalid input, for example scopes that are neither a string nor an array. ExtendsAsgardeoErrorand addsdetails.AsgardeoError– The base class ofAsgardeoAPIErrorandAsgardeoRuntimeError. Hascodeandorigin.