Cidaas JavaScript SDK

5.1.4 · active · verified Sun Apr 19

The Cidaas JavaScript SDK provides client-side functionality for integrating web applications with the Cidaas Cloud Identity & Access Management solution. It facilitates secure authentication and authorization flows based on industry standards like OAuth 2.0 and OpenID Connect, and supports a comprehensive set of features including Single Sign-On (SSO), Multi-Factor Authentication (MFA) with over 14 methods (e.g., TOTP, FIDO2), passwordless authentication, and various social/enterprise identity providers. The SDK is built upon the `oidc-client-ts` library, abstracting its complexities for Cidaas-specific integrations, allowing developers to focus on application logic rather than intricate identity protocols. The current stable version is 5.1.4. While a precise release cadence is not explicitly stated, the presence of a detailed changelog implies active development and regular updates. Its key differentiators include extensive MFA options, robust security features for Machine-to-Machine (M2M) and IoT scenarios, and a strong emphasis on simplifying complex identity management challenges.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Cidaas SDK, handle both login and logout redirect callbacks, and programmatically initiate authentication and logout flows using browser redirects.

import { Cidaas } from 'cidaas-javascript-sdk';

// Replace with your actual Cidaas tenant details. Ensure these match your Cidaas Admin UI configuration.
const cidaasConfig = {
    authority: 'https://your-cidaas-domain.com', // e.g., 'https://mytenant.cidaas.com'
    client_id: 'YOUR_CLIENT_ID', // Obtain this from Cidaas Admin UI
    redirect_uri: 'http://localhost:3000/callback', // Must be precisely registered in Cidaas
    post_logout_redirect_uri: 'http://localhost:3000/logout-callback', // Must be precisely registered in Cidaas
    scope: 'openid profile email offline_access', // Define required scopes
    response_type: 'code', // Recommended for PKCE flows
    userStore: window.sessionStorage, // Optional: default is sessionStorage, can be localStorage or InMemoryWebStorage
    automaticSilentRenew: true // Optional: default is true for token renewal
};

const cidaas = new Cidaas(cidaasConfig);

async function handleAuthenticationFlow() {
    // Check if the current URL is a login or logout redirect callback
    if (window.location.pathname === '/callback') {
        try {
            await cidaas.handleRedirectCallback(); // Processes the token from the URL hash/query
            const user = await cidaas.getUser();
            console.log('User successfully logged in:', user); //
            // Navigate away from the callback URL to prevent re-processing
            window.history.replaceState({}, document.title, '/');
        } catch (error) {
            console.error('Error handling login callback:', error);
        }
    } else if (window.location.pathname === '/logout-callback') {
        console.log('User successfully logged out.');
        window.history.replaceState({}, document.title, '/');
    } else {
        // If not on a callback page, check current authentication status
        const user = await cidaas.getUser();
        if (!user) {
            console.log('No active user session found. Initiating login...');
            // In a real application, you might trigger this on a button click or route guard
            // cidaas.loginWithRedirect(); 
        } else {
            console.log('User already authenticated:', user.profile.given_name); //
            console.log('Access Token:', user.access_token); //
        }
    }
}

async function login() {
    try {
        await cidaas.loginWithRedirect();
    } catch (error) {
        console.error('Login initiation failed:', error);
    }
}

async function logout() {
    try {
        await cidaas.logout();
    } catch (error) {
        console.error('Logout initiation failed:', error);
    }
}

handleAuthenticationFlow();

// Example usage (typically called from UI events):
// document.getElementById('loginButton').addEventListener('click', login);
// document.getElementById('logoutButton').addEventListener('click', logout);

view raw JSON →