createAuthrim() 関数は AuthrimConfig オブジェクトを受け取ります:
import { createAuthrim } from '@authrim/web';
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
browserPublicClientMode: 'strict',
browserRefreshTokenPolicy: 'disabled',
silentLoginRedirectUri: 'https://myapp.com/callback.html',
| 型 | 必須 | 説明 |
|---|
string | はい | Authrim IdP URL |
AuthrimサーバーのベースURL。SDKはディスカバリー、トークンエンドポイント、Direct Authエンドポイント用のwell-knownパスを自動的に付加します。
issuer: 'https://auth.example.com'
| 型 | 必須 | 説明 |
|---|
string | はい | OAuthクライアントID |
Authrim管理パネルで登録したクライアントID。
clientId: 'my-application'
| 型 | デフォルト | 説明 |
|---|
boolean | false | OAuth/OIDC機能を有効にする |
true にすると auth.oauth 名前空間が利用可能になり、以下を提供:
auth.oauth.popup.login() — ポップアップベースのOAuthログイン
auth.oauth.silentAuth.check() — iframeベースのサイレント認証
auth.oauth.trySilentLogin() — トップレベルナビゲーションSSO
auth.oauth.handleSilentCallback() — SSOコールバックハンドラー
auth.oauth.buildAuthorizationUrl() — 認可URL手動構築
auth.oauth.handleCallback() — コールバック手動処理
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
// auth.oauth は undefined
const authWithOAuth = await createAuthrim({
issuer: 'https://auth.example.com',
// authWithOAuth.oauth が利用可能
| 型 | デフォルト | 説明 |
|---|
string | — | ブラウザDPoP鍵マテリアルのscopeに使うテナントID |
SDKクライアント作成前にactive tenantが分かる場合に設定してください。同じissuer/client idで、browser-held DPoP keyがテナントをまたいで再利用されるのを防ぎます。
| 型 | デフォルト | 説明 |
|---|
StorageOptions | 下記参照 | ストレージ設定 |
interface StorageOptions {
/** 保存アイテムのキープレフィックス(デフォルト: 'authrim') */
/** ストレージバックエンド(デフォルト: 'memory') */
storage?: 'memory' | 'sessionStorage' | 'localStorage';
| タイプ | スコープ | 持続性 | セキュリティ |
|---|
'memory' | 現在のページライフサイクル | リロード/遷移で消去 | 最も安全(DOMストレージを使わない) |
'sessionStorage' | 現在のタブ | リロード後も保持、タブを閉じると消去 | タブ内のJSから参照可能 |
'localStorage' | 全タブ | ブラウザ再起動後も永続 | タブをまたいでJSから参照可能 |
storage: { storage: 'memory' }
storage: { storage: 'sessionStorage' }
// Direct Auth token は sessionStorage を選ばない限り memory です。
storage: { storage: 'localStorage', prefix: 'myapp-auth' }
| 型 | デフォルト | 説明 |
|---|
'token' | 'cookie' | 'token' | ブラウザセッションプロファイル |
@authrim/web はブラウザトークンプロファイルをデフォルトにします。profile: 'cookie' は、同一オリジンのtoken-handlerやBFFがHttpOnly Cookieセッションを管理する構成でのみ使用してください。profile: 'auto' は @authrim/sveltekit などのフレームワークアダプター向けで、@authrim/web から直接使う値ではありません。
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
| 型 | デフォルト | 説明 |
|---|
'strict' | 'cookie_fallback' | 'legacy' | 'strict' | ブラウザ公開クライアントのセキュリティモード |
カスタムブラウザSDKクライアントは strict がデフォルトです。ホスト済みフローやBFF連携では、統合境界で cookie_fallback を選択できます。
| 型 | デフォルト | 説明 |
|---|
'disabled' | 'dpop_bound' | 'disabled' | ブラウザリフレッシュトークンポリシー |
dpop_bound は、このissuerとclientに対してブラウザが安定した非抽出可能DPoP鍵を保持できる場合だけ使用してください。
| 型 | デフォルト | 説明 |
|---|
{ cookieName?: string; headerName?: string } | { cookieName: 'authrim_csrf', headerName: 'X-Authrim-CSRF' } | Cookieプロファイルリクエスト向けのdouble-submit CSRF連携 |
| 型 | デフォルト | 説明 |
|---|
string | ${window.location.origin}/callback.html | サイレントSSO用のリダイレクトURI |
auth.oauth.trySilentLogin() と auth.oauth.handleSilentCallback() で使用されます。handleSilentCallback() を呼び出すページである必要があります。
silentLoginRedirectUri: 'https://myapp.com/auth/callback'
Authrim の戻り値の型は enableOAuth に基づいて条件分岐します:
// enableOAuth: false(または省略)
const auth = await createAuthrim({
auth.oauth // ❌ undefined
const auth = await createAuthrim({
| 名前空間 | 説明 |
|---|
auth.passkey | Passkey(WebAuthn)認証 |
auth.emailCode | Email Code(OTP)認証 |
auth.social | ソーシャルプロバイダー認証 |
auth.session | セッション管理 |
auth.handoff | Smart Handoff SSO tokenの検証 |
auth.stepUp | Step-up challengeの開始、再送、完了 |
auth.customerProfiles | delegated/elevated customer profileの読み書き |
auth.devices | trusted deviceの一覧、名前変更、unlink |
auth.fetch() | tokenまたはcookie profileでprotected resourceを呼び出し |
auth.signIn | サインインショートカット |
auth.signUp | サインアップショートカット |
auth.signOut() | サインアウト |
auth.signOutApplicationGroup() | 現在のapplication groupからサインアウト |
auth.signOutAll() | グローバルサインアウト |
auth.on() | イベントサブスクリプション |
| 名前空間 | 説明 |
|---|
auth.oauth.popup | ポップアップベースのOAuthログイン |
auth.oauth.silentAuth | iframeベースのサイレント認証 |
auth.oauth.trySilentLogin() | トップレベルナビゲーションSSO |
auth.oauth.handleSilentCallback() | SSOコールバックハンドラー |
auth.oauth.buildAuthorizationUrl() | 認可URL手動構築 |
auth.oauth.handleCallback() | コールバック手動処理 |
SDKは一般的な操作のショートカットメソッドを提供します:
// ショートカット: auth.signIn.passkey()
// 同等: auth.passkey.login()
const { data, error } = await auth.signIn.passkey();
// ショートカット: auth.signIn.social('google')
// 同等: auth.social.loginWithPopup('google')
const { data, error } = await auth.signIn.social('google');
// ショートカット: auth.signUp.passkey({ email })
// 同等: auth.passkey.signUp({ email })
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
storage: 'sessionStorage',
browserPublicClientMode: 'strict',
browserRefreshTokenPolicy: 'disabled',
cookieName: 'authrim_csrf',
headerName: 'X-Authrim-CSRF',
silentLoginRedirectUri: 'https://myapp.com/callback',