Keep metadata trustworthy
Use a fixed provider issuer and registered client identifier. Fetch discovery documents over HTTPS in production and never turn arbitrary user-supplied issuer URLs into authentication requests.
Browser-side authentication built on oidc-client-ts with authorization code + PKCE.
Construct MagnexisAuth with the exact identity issuer and redirect URI registered for your client. The SDK uses OIDC discovery and PKCE automatically.
import { MagnexisAuth } from '@magnexis/identity';
const auth = new MagnexisAuth({
issuer: 'https://YOUR_AUTH_HOST/realms/magnexis',
clientId: 'client-id-from-magnexis',
redirectUri: 'https://your-website.example/auth/callback',
postLogoutRedirectUri: 'https://your-website.example/',
scope: 'openid profile email',
});auth.signIn()auth.handleCallback()auth.getUser()auth.getAccessToken()auth.signOut()auth.clearLocalSession()Initiate sign-in only after user interaction. Sign-in sends the browser to the identity provider; the current app never collects Magnexis passwords.
const button = document.getElementById('magnexis-signin');
button.addEventListener('click', async () => {
try {
await auth.signIn();
} catch (error) {
console.error('Could not begin sign-in', error);
}
});
// Your callback route executes await auth.handleCallback().For the browser demonstration, the SDK stores transient authorization state and session data in sessionStorage, not permanent localStorage. Tokens remain accessible to JavaScript, so an XSS flaw can compromise a session. For sensitive systems, prefer a backend-for-frontend exchanging codes on a trusted server and issuing HttpOnly, Secure, SameSite cookies. Never treat a decoded ID token as authorization for a backend API; validate tokens server-side against issuer, audience, signature, and expiry.
A short API can still have important operational edges.
Use a fixed provider issuer and registered client identifier. Fetch discovery documents over HTTPS in production and never turn arbitrary user-supplied issuer URLs into authentication requests.
The SDK uses authorization code with PKCE. Applications should preserve their state and nonce validation requirements and avoid exposing tokens in logs, URL query strings, or third-party analytics.
Prefer secure, short-lived sessions and bounded refresh behavior. Clear stale local state during sign-out and plan for a revoked or expired provider session.