EcAuth ステージング環境 フェデレーション認証確認手順
フェデレーション認証のステージング環境での検証手順。Playwright と Mock IdP の連携。
概要
EcAuth ステージング環境と MockIdP(staging organization)間の OAuth2/OpenID Connect フェデレーション認証の確認手順をまとめたドキュメントです。
環境情報
| 環境 | URL |
|---|---|
| EcAuth ステージング | https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/ |
| MockIdP (staging org) | https://mock-openid-provider.mangoplant-f8a75293.japaneast.azurecontainerapps.io/ |
1Password アイテム構成
mockidp-staging
MockIdP 自体の設定情報。
| フィールド | 説明 |
|---|---|
default_client_id |
MockIdP の staging クライアント ID |
default_client_secret |
MockIdP の staging クライアントシークレット |
default_user_email |
テストユーザーのメールアドレス |
default_user_password |
テストユーザーのパスワード |
redirect_uri |
EcAuth のコールバック URL(/v1/auth/callback
付き) |
authorization_endpoint |
認可エンドポイント(?org=staging 付き) |
token_endpoint |
トークンエンドポイント(?org=staging 付き) |
userinfo_endpoint |
ユーザー情報エンドポイント(?org=staging 付き) |
ecauth-staging-app
EcAuth ステージング環境のアプリケーション設定。
| フィールド | 説明 |
|---|---|
organization_code |
Organization コード |
organization_name |
Organization 名 |
organization_tenant_name |
テナント名 |
client_id |
EcAuth クライアント ID |
client_secret |
EcAuth クライアントシークレット |
redirect_uri |
クライアントへのリダイレクト URI |
ecauth-staging-mockidp
EcAuth から MockIdP に接続するための設定。
| フィールド | 説明 |
|---|---|
app_name |
プロバイダー名(staging-mockidp) |
client_id |
MockIdP のクライアント ID(staging-mockclientid) |
client_secret |
MockIdP のクライアントシークレット |
フェデレーション認証フロー
sequenceDiagram
participant Client as クライアント
(EC-CUBE等)
participant EcAuth as EcAuth
ステージング
participant MockIdP as MockIdP
staging
Client->>EcAuth: 1. /v1/authorization
EcAuth->>MockIdP: 2. リダイレクト
Note right of MockIdP: 3. Basic認証
MockIdP->>EcAuth: 4. 認可コード
EcAuth->>Client: 5. 認可画面
Client->>EcAuth: 6. 承認
EcAuth->>Client: 7. 認可コード
Client->>EcAuth: 8. /v1/token
EcAuth->>Client: 9. トークン
Client->>EcAuth: 10. /v1/userinfo
EcAuth->>Client: 11. ユーザー情報
ブラウザでの確認手順
Step 1: 認証情報の確認
# テストユーザー情報を取得
op read "op://EcAuth/mockidp-staging/default_user_email"
op read "op://EcAuth/mockidp-staging/default_user_password"Step 2: 認可エンドポイントにアクセス
ブラウザで以下の URL にアクセス:
https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/authorization?client_id=staging-client-id&redirect_uri=https%3A%2F%2Flocalhost%3A8081%2Fv1%2Fauth%2Fcallback&response_type=code&scope=openid%20profile%20email&provider_name=staging-mockidp&state=test123
Step 3: MockIdP で認証
Basic 認証ダイアログが表示されるので、Step 1 で取得した認証情報を入力。
Step 4: EcAuth 認可画面
EcAuth の認可画面が表示されるので「承認」ボタンをクリック。
Step 5: 認可コードの確認
localhost:8081
にリダイレクトされる(接続エラーになる)。 URL
バーに認可コードが含まれていれば成功:
https://localhost:8081/v1/auth/callback?code=<認可コード>&state=test123
curl での確認手順(完全自動化)
以下の手順で curl のみでフェデレーション認証フロー全体を確認できます。
Step 1: 認証情報の取得
# 1Password から認証情報を取得
MOCK_USER=$(op read "op://EcAuth/mockidp-staging/default_user_email")
MOCK_PASS=$(op read "op://EcAuth/mockidp-staging/default_user_password")
CLIENT_ID=$(op read "op://EcAuth/ecauth-staging-app/client_id")
CLIENT_SECRET=$(op read "op://EcAuth/ecauth-staging-app/client_secret")
echo "MockIdP User: $MOCK_USER"
echo "EcAuth Client ID: $CLIENT_ID"Step 2: EcAuth 認可エンドポイントにアクセス
# EcAuth → MockIdP リダイレクト URL を取得
MOCKIDP_URL=$(curl -s -i "https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/authorization?client_id=${CLIENT_ID}&redirect_uri=https%3A%2F%2Flocalhost%3A8081%2Fv1%2Fauth%2Fcallback&response_type=code&scope=openid%20profile%20email&provider_name=staging-mockidp&state=test123" 2>&1 | grep -i "^location:" | sed 's/location: //i' | tr -d '\r')
echo "MockIdP URL: $MOCKIDP_URL"期待される結果: MockIdP の認可エンドポイントへのリダイレクト URL が表示される。
Step 3: MockIdP で認証
# MockIdP で Basic 認証して EcAuth コールバック URL を取得
ECAUTH_CALLBACK=$(curl -s -i -u "${MOCK_USER}:${MOCK_PASS}" "$MOCKIDP_URL" 2>&1 | grep -i "^location:" | sed 's/location: //i' | tr -d '\r')
echo "EcAuth Callback URL: $ECAUTH_CALLBACK"期待される結果: EcAuth の
/v1/auth/callback への URL(MockIdP からの認可コードと
state を含む)が表示される。
Step 4: EcAuth 認可画面で承認
# コールバック URL から code と state を抽出
MOCKIDP_CODE=$(echo "$ECAUTH_CALLBACK" | sed -n 's/.*code=\([^&]*\).*/\1/p')
STATE=$(echo "$ECAUTH_CALLBACK" | sed -n 's/.*state=\([^&]*\).*/\1/p')
echo "MockIdP Code: $MOCKIDP_CODE"
echo "State: $STATE"
# EcAuth 認可画面の承認を POST リクエストで実行
FINAL_REDIRECT=$(curl -s -i -X POST "https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/auth/callback" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "code=${MOCKIDP_CODE}" \
-d "state=${STATE}" \
-d "scope=" \
-d "action=authorize" 2>&1 | grep -i "^location:" | sed 's/location: //i' | tr -d '\r')
echo "Final Redirect: $FINAL_REDIRECT"
# EcAuth が発行した認可コードを抽出
ECAUTH_CODE=$(echo "$FINAL_REDIRECT" | sed -n 's/.*code=\([^&]*\).*/\1/p')
echo "EcAuth Authorization Code: $ECAUTH_CODE"期待される結果: クライアントの redirect_uri へのリダイレクト URL と EcAuth が発行した認可コードが表示される。
Step 5: トークン取得
# トークンエンドポイントにリクエスト
curl -s -X POST https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=${ECAUTH_CODE}" \
-d "redirect_uri=https://localhost:8081/v1/auth/callback" \
-d "client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}" | jq .期待されるレスポンス:
{
"access_token": "2CCAAA1330EE930D087275C1CB07979838CF7DB89786444D9D4430471EF472CA",
"token_type": "Bearer",
"expires_in": 3600,
"id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh_token": null
}Step 6: ユーザー情報取得
# Step 5 で取得した access_token を使用
ACCESS_TOKEN="<Step 5 で取得した access_token>"
curl -s https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/userinfo \
-H "Authorization: Bearer ${ACCESS_TOKEN}" | jq .期待されるレスポンス:
{
"sub": "09657885-8351-4797-a0a5-a94e0e1c3e58"
}一括実行スクリプト
上記の手順を一括で実行するスクリプト:
#!/bin/bash
set -e
echo "=== Step 1: 認証情報の取得 ==="
MOCK_USER=$(op read "op://EcAuth/mockidp-staging/default_user_email")
MOCK_PASS=$(op read "op://EcAuth/mockidp-staging/default_user_password")
CLIENT_ID=$(op read "op://EcAuth/ecauth-staging-app/client_id")
CLIENT_SECRET=$(op read "op://EcAuth/ecauth-staging-app/client_secret")
echo "=== Step 2: EcAuth 認可エンドポイント ==="
MOCKIDP_URL=$(curl -s -i "https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/authorization?client_id=${CLIENT_ID}&redirect_uri=https%3A%2F%2Flocalhost%3A8081%2Fv1%2Fauth%2Fcallback&response_type=code&scope=openid%20profile%20email&provider_name=staging-mockidp&state=test123" 2>&1 | grep -i "^location:" | sed 's/location: //i' | tr -d '\r')
echo "=== Step 3: MockIdP で認証 ==="
ECAUTH_CALLBACK=$(curl -s -i -u "${MOCK_USER}:${MOCK_PASS}" "$MOCKIDP_URL" 2>&1 | grep -i "^location:" | sed 's/location: //i' | tr -d '\r')
echo "=== Step 4: EcAuth 認可画面で承認 ==="
MOCKIDP_CODE=$(echo "$ECAUTH_CALLBACK" | sed -n 's/.*code=\([^&]*\).*/\1/p')
STATE=$(echo "$ECAUTH_CALLBACK" | sed -n 's/.*state=\([^&]*\).*/\1/p')
FINAL_REDIRECT=$(curl -s -i -X POST "https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/auth/callback" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "code=${MOCKIDP_CODE}" \
-d "state=${STATE}" \
-d "scope=" \
-d "action=authorize" 2>&1 | grep -i "^location:" | sed 's/location: //i' | tr -d '\r')
ECAUTH_CODE=$(echo "$FINAL_REDIRECT" | sed -n 's/.*code=\([^&]*\).*/\1/p')
echo "Authorization Code: $ECAUTH_CODE"
echo "=== Step 5: トークン取得 ==="
TOKEN_RESPONSE=$(curl -s -X POST https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=${ECAUTH_CODE}" \
-d "redirect_uri=https://localhost:8081/v1/auth/callback" \
-d "client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}")
echo "$TOKEN_RESPONSE" | jq .
ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.access_token')
echo "=== Step 6: ユーザー情報取得 ==="
curl -s https://ecauth-staging-w4bctmxhutunk9kc.azurewebsites.net/v1/userinfo \
-H "Authorization: Bearer ${ACCESS_TOKEN}" | jq .
echo "=== 確認完了 ==="トラブルシューティング
invalid_request_uri エラー
症状: MockIdP から invalid_request_uri
エラーが返される。
原因と対処:
redirect_uri の不一致
- MockIdP に登録されている
redirect_uriと EcAuth が送信するredirect_uriが一致しているか確認 - 1Password
mockidp-staging/redirect_uriに/v1/auth/callbackが含まれているか確認
- MockIdP に登録されている
org パラメータの欠落
- MockIdP のエンドポイントに
?org=stagingが含まれているか確認 - 1Password
mockidp-staging/authorization_endpoint等を確認
- MockIdP のエンドポイントに
Organization not found エラー
症状: EcAuth から「Organization not found」エラーが返される。
原因と対処:
DEFAULT_ORGANIZATION_TENANT_NAME 未設定
- Azure App Service の環境変数を確認
az webapp config appsettings list --name ecauth-staging-w4bCTMXhuTuNK9KC --resource-group ec-auth
TenantMiddleware の問題
- PR #203 がマージされているか確認(Azure プラットフォームドメインの除外)
認証失敗(401 Unauthorized)
症状: MockIdP で認証が失敗する。
原因と対処:
ユーザー名/パスワードの誤り
- 1Password
mockidp-staging/default_user_emailとdefault_user_passwordを確認
- 1Password
org パラメータの欠落
- MockIdP へのリクエストに
org=stagingが含まれているか確認 orgがないとデフォルト organization(dev)が使用され、staging ユーザーでは認証できない
- MockIdP へのリクエストに
idp_client_id の不一致
症状: MockIdP から「Client not found」エラーが返される。
原因と対処:
- EcAuth の open_id_provider 設定確認
idp_client_idがstaging-mockclientidになっているか確認- 1Password
ecauth-staging-mockidp/client_idを確認
関連ドキュメント
- CLAUDE.md - アーキテクチャ概要
- requirements.md - 要件定義書
- user-management-architecture.md - ユーザー管理設計