@myiam.io/web-sdk
v0.5.4
Published
Zero-dependency OAuth2/PKCE authentication SDK for [MyIAM](https://myiam.io).
Downloads
99
Readme
@myiam.io/web-sdk
Zero-dependency OAuth2/PKCE authentication SDK for MyIAM.
- Client (
@myiam.io/web-sdk/client) — Browser-side PKCE authentication - Server (
@myiam.io/web-sdk/server) — Session management + REST API client - Works with Node.js 18+, Edge Runtime, Deno, Bun
Install
npm install @myiam.io/web-sdkQuick Start
Client — Browser PKCE Authentication
import {
myiamInit,
myiamLoginUrl,
myiamHandleCallback,
myiamRefreshToken,
myiamLogoutUrl,
} from '@myiam.io/web-sdk/client'
// 1. Initialize (once at app startup)
myiamInit({
serviceUid: 'YOUR_SERVICE_UID',
oauth2ClientId: 'YOUR_CLIENT_ID',
})
// 2. Login
window.location.href = await myiamLoginUrl('https://example.com/callback')
// 3. Handle callback
const tokens = await myiamHandleCallback()
// 4. Refresh token
const newTokens = await myiamRefreshToken(tokens.refresh_token)
// 5. Logout
window.location.href = myiamLogoutUrl('https://example.com')Server — Session Management (Next.js, etc.)
import { createMyiamServer } from '@myiam.io/web-sdk/server'
const myiam = createMyiamServer({
serviceUid: 'YOUR_SERVICE_UID',
oauth2ClientId: 'YOUR_CLIENT_ID',
cookieSecret: 'YOUR_COOKIE_SECRET_32_CHARS_MIN',
apiKey: 'YOUR_API_KEY',
})
// Login URL
const url = await myiam.login(callbackUrl, cookies)
// Handle callback → sets encrypted session cookie
await myiam.handleCallback(searchParams, cookies)
// Read session
const session = await myiam.getSession(cookies)
// REST API
const tokenInfo = await myiam.api.getTokenInfo(session.accessToken)API Only — Backend Services (Firebase Functions, etc.)
import { createMyiamApi } from '@myiam.io/web-sdk/server'
const api = createMyiamApi({
serviceUid: 'YOUR_SERVICE_UID',
apiKey: 'YOUR_API_KEY',
})
const tokenInfo = await api.getTokenInfo(accessToken)
const user = await api.getUser({ accessToken })
const profile = await api.getServiceUserProfile({ accessToken, serviceUserUid })Documentation
For guides and API reference, visit MyIAM Docs.
