Skip to content

EcAuthLogin2 プラグイン実装計画 #1

@nanasess

Description

@nanasess

EC-CUBE 2系(2.13, 2.17, 2.25)向け EcAuth OpenID Connect RP プラグイン

概要

EcAuth IdP と連携し、ソーシャルログイン機能を EC-CUBE 2系サイトに追加するプラグイン。
MockIdP のフェデレーション機能で動作確認済み。

ディレクトリ構成

ec-cube2-ecauth/
├── .github/
│   └── workflows/
│       ├── ci.yml                        # CI(PHPStan, Rector, CS Fixer)
│       └── release.yml                   # リリース(パッケージング)
├── data/
│   ├── class/
│   │   ├── helper/
│   │   │   └── SC_Helper_EcAuth.php
│   │   └── pages/ecauth/
│   │       ├── LC_Page_EcAuth_Authorize.php
│   │       └── LC_Page_EcAuth_Callback.php
│   └── class_extends/page_extends/ecauth/
│       ├── LC_Page_EcAuth_Authorize_Ex.php
│       └── LC_Page_EcAuth_Callback_Ex.php
├── html/ecauth/
│   ├── authorize.php
│   └── callback.php
├── plugin/
│   └── EcAuthLogin2/
│       ├── plugin_info.php
│       └── EcAuthLogin2.php
├── Dockerfile
├── docker-compose.yml
├── install-plugin.sh
├── package.json
├── playwright.config.ts
└── tests/
    └── ecauth-login.spec.ts

実装計画

Phase 1: 基盤作成

  • リポジトリ作成
  • README.md 作成
  • composer.json 作成
  • 静的解析・コード品質ツール設定
    • phpstan.neon 作成(PHPStan設定)
    • rector.php 作成(Rector設定)
    • .php-cs-fixer.dist.php 作成(PHP CS Fixer設定)

Phase 2: OAuth2/OIDC クライアント

  • data/class/helper/SC_Helper_EcAuth.php 作成
    • getConfig() - dtb_plugin から設定取得
    • saveConfig() - dtb_plugin に設定保存
    • getAuthorizationUrl() - 認可URL生成(PKCE対応)
    • exchangeCodeForTokens() - トークン交換
    • getUserInfo() - UserInfo取得
    • getExternalUserInfo() - External UserInfo取得
    • findOrCreateCustomer() - JITプロビジョニング(PostgreSQL対応)
    • loginCustomer() - セッション開始
    • validateState() - state パラメータ検証
    • getAndClearCodeVerifier() - PKCE code_verifier 取得

Phase 3: コールバックエンドポイント

  • data/class/pages/ecauth/LC_Page_EcAuth_Callback.php 作成
  • data/class_extends/page_extends/ecauth/LC_Page_EcAuth_Callback_Ex.php 作成
  • html/ecauth/callback.php 作成

Phase 4: プラグイン本体

  • plugin/EcAuthLogin2/plugin_info.php 作成
  • plugin/EcAuthLogin2/EcAuthLogin2.php 作成
    • install() - DB拡張(ecauth_subject カラム追加)
    • uninstall() - クリーンアップ
    • prefilterTransform() - ログインボタン挿入
    • copyFiles() / removeFiles() - ファイル管理

Phase 5: テンプレート・JavaScript

  • ログインボタンは prefilterTransform() で動的に生成(テンプレートファイル不要)

Phase 6: Docker環境・E2Eテスト

  • docker-compose.yml 作成
  • Dockerfile 作成(EC-CUBE 2.25 公式イメージベース)
  • install-plugin.sh 作成
    • プラグイン登録(dtb_plugin, dtb_plugin_hookpoint)
    • ecauth_subject カラム追加
    • EcAuth 接続設定の自動登録
  • package.json 作成
  • playwright.config.ts 作成
  • tests/ecauth-login.spec.ts 作成

Phase 7: CI/CD

  • .github/workflows/ci.yml 作成
    • PHPStan 実行
    • Rector --dry-run 実行
    • PHP CS Fixer --dry-run 実行
    • PHPUnit 実行(将来)
  • .github/workflows/release.yml 作成
    • release トリガー
    • プラグインパッケージング(tar.gz)
    • GitHub Release にアセット添付

Phase 8: 認可フロー分離 ✅

セッション state 保存問題を解決するため、認可フローを専用エンドポイントに分離。

  • data/class/pages/ecauth/LC_Page_EcAuth_Authorize.php 作成
  • data/class_extends/page_extends/ecauth/LC_Page_EcAuth_Authorize_Ex.php 作成
  • html/ecauth/authorize.php 作成
  • ログインボタンのリンク先を /ecauth/authorize.php に変更
  • 外部 URL リダイレクトのため header() を直接使用

技術仕様

設定項目

dtb_plugin.free_field1 に JSON 形式で保存:

{
    "client_id": "xxx",
    "client_secret": "xxx",
    "authorization_endpoint": "https://ecauth.example.com/authorization",
    "token_endpoint": "https://ecauth.example.com/token",
    "userinfo_endpoint": "https://ecauth.example.com/userinfo",
    "external_userinfo_endpoint": "https://ecauth.example.com/api/external-userinfo",
    "provider_name": "staging-mockidp"
}

DB拡張

ALTER TABLE dtb_customer ADD ecauth_subject VARCHAR(255);
CREATE INDEX idx_customer_ecauth_subject ON dtb_customer(ecauth_subject);

対象テンプレート(ボタン挿入先)

  • mypage/login.tpl - マイページログイン
  • shopping/index.tpl - 購入手続き画面

EC-CUBE 2.25 の変更点

  • dtb_plugin: descriptionplugin_descriptiondel_flg 削除
  • plugin_id に明示的シーケンス必要
  • SC_Plugin_Base 継承で PHP 8 エラー(EC-CUBE Issue #551
  • HTTP/HTTPS でセッションが分離される

Known Issues

解決済み

  • EcAuth Issue #210: state パラメータが保持されないPR #211 で修正済み
  • セッション state 保存問題: prefilter でのテンプレートコンパイル時に state が生成される問題 → Phase 8 で解決
  • PostgreSQL NOT NULL 制約: customer_id, secret_key, point, email の設定が必要 → SC_Helper_EcAuth で対応

備考

  • PHP 7.4 互換(EC-CUBE 2.25 公式イメージ使用)
  • 環境変数は使用せず、dtb_plugin テーブルに設定保存
  • パッチファイルは使用しない(プラグインフックのみで実装)
  • prefilterTransform でテンプレートにボタンを挿入
  • Docker 起動時にプラグイン自動インストール
  • PKCE (S256) 対応
  • JIT プロビジョニング対応

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions