// Import for browsers
import { AriesClient } from '@aries-exchange/sdk/browser';
// Initialize (never expose client secret in browser)
const client = new AriesClient({
clientId: 'your_public_client_id',
// No client secret - use PKCE instead
});
// Use OAuth2 flow with PKCE
const codeVerifier = generateCodeVerifier();
const codeChallenge = generateCodeChallenge(codeVerifier);
// Store verifier in sessionStorage
sessionStorage.setItem('code_verifier', codeVerifier);
// Redirect to authorization
window.location.href = await client.oauth2.getAuthorizationUrl({
redirectUri: window.location.origin + '/callback',
codeChallenge,
codeChallengeMethod: 'S256'
});
// In callback page
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const verifier = sessionStorage.getItem('code_verifier');
const tokens = await client.oauth2.exchangeCode({
code,
redirectUri: window.location.origin + '/callback',
codeVerifier: verifier
});
// Store tokens securely
sessionStorage.setItem('access_token', tokens.accessToken);