createAuthrimオプション
createAuthrim() 関数は AuthrimConfig オブジェクトを受け取ります:
import { createAuthrim } from '@authrim/web';
const auth = await createAuthrim({
issuer: 'https://auth.example.com',
silentLoginRedirectUri: 'https://myapp.com/callback.html',
必須オプション
issuer
| 型 | 必須 | 説明 |
|---|
string | はい | Authrim IdP URL |
AuthrimサーバーのベースURL。SDKはディスカバリー、トークンエンドポイント、Direct Authエンドポイント用のwell-knownパスを自動的に付加します。
issuer: 'https://auth.example.com'
clientId
| 型 | 必須 | 説明 |
|---|
string | はい | OAuthクライアントID |
Authrim管理パネルで登録したクライアントID。
clientId: 'my-application'
オプション
enableOAuth
| 型 | デフォルト | 説明 |
|---|
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 が利用可能
storage
| 型 | デフォルト | 説明 |
|---|
StorageOptions | 下記参照 | ストレージ設定 |
interface StorageOptions {
/** 保存アイテムのキープレフィックス(デフォルト: 'authrim') */
/** ストレージバックエンド(デフォルト: 'sessionStorage') */
storage?: 'memory' | 'sessionStorage' | 'localStorage';
ストレージタイプ
| タイプ | スコープ | 持続性 | セキュリティ |
|---|
'memory' | 現在のタブ | タブを閉じる/遷移で消去 | 最も安全(DOMアクセス不可) |
'sessionStorage' | 現在のタブ | リロード後も保持、タブを閉じると消去 | XSS耐性(タブスコープ) |
'localStorage' | 全タブ | ブラウザ再起動後も永続 | XSS経由でアクセス可能 |
storage: { storage: 'memory' }
storage: { storage: 'sessionStorage' }
storage: { storage: 'localStorage', prefix: 'myapp-auth' }
silentLoginRedirectUri
| 型 | デフォルト | 説明 |
|---|
string | ${window.location.origin}/callback.html | サイレントSSO用のリダイレクトURI |
auth.oauth.trySilentLogin() と auth.oauth.handleSilentCallback() で使用されます。handleSilentCallback() を呼び出すページである必要があります。
silentLoginRedirectUri: 'https://myapp.com/auth/callback'
TypeScript: 条件付き型
Authrim の戻り値の型は enableOAuth に基づいて条件分岐します:
// enableOAuth: false(または省略)
const auth = await createAuthrim({
auth.oauth // ❌ undefined
const auth = await createAuthrim({
API名前空間
ベース(常に利用可能)
| 名前空間 | 説明 |
|---|
auth.passkey | Passkey(WebAuthn)認証 |
auth.emailCode | Email Code(OTP)認証 |
auth.social | ソーシャルプロバイダー認証 |
auth.session | セッション管理 |
auth.signIn | サインインショートカット |
auth.signUp | サインアップショートカット |
auth.signOut() | サインアウト |
auth.on() | イベントサブスクリプション |
OAuth(enableOAuth: true)
| 名前空間 | 説明 |
|---|
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',
silentLoginRedirectUri: 'https://myapp.com/callback',
次のステップ