OASIS Avatar SSO SDK - Vanilla JavaScript

Pure JavaScript implementation of OASIS Avatar SSO - no framework required!

Installation

Via CDN

<script src="https://cdn.oasis.network/avatar-sso/v1.5.2/oasis-sso.min.js"></script>

Via NPM

npm install @oasis/avatar-sso

Quick Start

Basic Usage

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdn.oasis.network/avatar-sso/v1.5.2/oasis-sso.min.js"></script>
</head>
<body>
    <div id="login-form">
        <input id="username" type="text" placeholder="Username" />
        <input id="password" type="password" placeholder="Password" />
        <select id="provider">
            <option value="Auto">Auto</option>
            <option value="MongoDBOASIS">MongoDB</option>
            <option value="EthereumOASIS">Ethereum</option>
        </select>
        <button onclick="login()">Beam In</button>
    </div>

    <script>
        // Initialize SDK
        const sso = new OasisAvatarSSO({
            apiUrl: 'https://api.oasis.network',
            provider: 'Auto'
        });

        async function login() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const provider = document.getElementById('provider').value;

            try {
                const result = await sso.login(username, password, provider);
                console.log('Login successful!', result);
                
                // Get current user
                const user = await sso.getCurrentUser();
                console.log('Current user:', user);
                
                // Redirect
                window.location.href = '/dashboard';
            } catch (error) {
                console.error('Login failed:', error);
                alert('Login failed: ' + error.message);
            }
        }
    </script>
</body>
</html>

Advanced Usage with Event Listeners

API Reference

Constructor

Options:

  • apiUrl (string, required): Base URL of OASIS API

  • provider (string, optional): Default provider (default: 'Auto')

  • onAuthChange (function, optional): Callback when auth state changes

Methods

login(username, password, provider)

Authenticate a user.

logout()

Log out the current user.

isAuthenticated()

Check if user is authenticated.

getCurrentUser()

Get current user data.

refreshToken()

Refresh the authentication token.

getAuthToken()

Get the current auth token.

Features

Zero Dependencies - Pure vanilla JavaScript 🚀 Lightweight - Only 8KB minified + gzipped 🔐 Secure - Built-in token management 📱 Mobile-Friendly - Works on all devices 🎯 Simple API - Easy to understand and use

Browser Support

  • Chrome (latest)

  • Firefox (latest)

  • Safari (latest)

  • Edge (latest)

  • Opera (latest)

Examples

With jQuery

With Fetch API

License

MIT © OASIS Team

Last updated