OASIS Avatar SSO SDK - Vanilla JavaScript
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-ssoQuick 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
Methods
login(username, password, provider)
login(username, password, provider)logout()
logout()isAuthenticated()
isAuthenticated()getCurrentUser()
getCurrentUser()refreshToken()
refreshToken()getAuthToken()
getAuthToken()Features
Browser Support
Examples
With jQuery
With Fetch API
License
Last updated