コンテンツにスキップ

設定リファレンス

createAuthrim() 関数は AuthrimConfig オブジェクトを受け取ります:

import { createAuthrim } from '@authrim/web';
const auth = await createAuthrim({
// 必須
issuer: 'https://auth.example.com',
clientId: 'my-app',
// オプション
tenantId: 'tenant_123',
enableOAuth: false,
storage: { ... },
profile: 'token',
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'
デフォルト説明
booleanfalseOAuth/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() — コールバック手動処理
// OAuth無効(デフォルト)
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
clientId: 'my-app',
});
// auth.oauth は undefined
// OAuth有効
const authWithOAuth = await createAuthrim({
issuer: 'https://auth.example.com',
clientId: 'my-app',
enableOAuth: true,
});
// authWithOAuth.oauth が利用可能
デフォルト説明
stringブラウザDPoP鍵マテリアルのscopeに使うテナントID

SDKクライアント作成前にactive tenantが分かる場合に設定してください。同じissuer/client idで、browser-held DPoP keyがテナントをまたいで再利用されるのを防ぎます。

デフォルト説明
StorageOptions下記参照ストレージ設定
interface StorageOptions {
/** 保存アイテムのキープレフィックス(デフォルト: 'authrim') */
prefix?: string;
/** ストレージバックエンド(デフォルト: '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',
clientId: 'my-app',
profile: 'token',
});
デフォルト説明
'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(または省略)
// 型: AuthrimBase
const auth = await createAuthrim({
issuer: '...',
clientId: '...',
});
auth.passkey // ✅ 利用可能
auth.emailCode // ✅ 利用可能
auth.social // ✅ 利用可能
auth.session // ✅ 利用可能
auth.oauth // ❌ undefined
// enableOAuth: true
// 型: AuthrimWithOAuth
const auth = await createAuthrim({
issuer: '...',
clientId: '...',
enableOAuth: true,
});
auth.passkey // ✅ 利用可能
auth.oauth // ✅ 利用可能
名前空間説明
auth.passkeyPasskey(WebAuthn)認証
auth.emailCodeEmail Code(OTP)認証
auth.socialソーシャルプロバイダー認証
auth.sessionセッション管理
auth.handoffSmart Handoff SSO tokenの検証
auth.stepUpStep-up challengeの開始、再送、完了
auth.customerProfilesdelegated/elevated customer profileの読み書き
auth.devicestrusted 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.silentAuthiframeベースのサイレント認証
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 { data, error } = await auth.signUp.passkey({ email: '[email protected]' });
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
clientId: 'my-app',
});
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
clientId: 'my-app',
enableOAuth: true,
tenantId: 'tenant_123',
storage: {
prefix: 'myapp',
storage: 'sessionStorage',
},
profile: 'token',
browserPublicClientMode: 'strict',
browserRefreshTokenPolicy: 'disabled',
csrf: {
cookieName: 'authrim_csrf',
headerName: 'X-Authrim-CSRF',
},
silentLoginRedirectUri: 'https://myapp.com/callback',
});