Skip to content

Conversation

@hayasaki-shunsuke
Copy link
Contributor

@hayasaki-shunsuke hayasaki-shunsuke commented Jan 15, 2026

問題

difync init 実行時に認証エラーが発生していた:

背景

2026/1/15 に Dify を 1.11.4 にバージョンアップしたところ、difync init 実行時に認証エラーが発生するようになりました。

エラー内容

login API returned error: status=401, body={"code":"authentication_failed","message":"Invalid encrypted data","status":401}

原因

Dify 1.11.4 でログインAPIの仕様が変更され、パスワードをBase64エンコードして送信する必要があるようになりました。

Difyのフロントエンドコードを確認したところ:

  • web/app/signin/components/mail-and-password-auth.tsxencryptPassword(password) を呼び出し
  • web/utils/encryption.ts の実装でパスワードをBase64エンコードして送信

修正内容

Login関数でパスワードをBase64エンコードしてからAPIに送信するよう変更

原因調査

  1. PR fix: Support new Dify API cookie-based authentication #1 (7ed6bd2) でCookie認証に対応したが、ログイン自体が失敗
  2. Dify APIのログインエンドポイントを直接テストしても同じエラー
  3. Difyのフロントエンドコードを調査:
    • web/app/signin/components/mail-and-password-auth.tsx で encryptPassword(password) を呼び出している
    • web/utils/encryption.ts の実装を確認したところ、 パスワードをBase64エンコードして送信していることが判明

修正内容

Login関数でパスワードをBase64エンコードしてからAPIに送信するよう変更

検証

  • difync init が正常に動作することを確認(153アプリを取得)
  • 全テストがパスすることを確認

## 問題
`difync init` 実行時に認証エラーが発生していた:
```
login API returned error: status=401, body={"code":"authentication_failed","message":"Invalid encrypted data","status":401}
```

## 原因調査
1. PR #1 (7ed6bd2) でCookie認証に対応したが、ログイン自体が失敗
2. Dify APIのログインエンドポイントを直接テストしても同じエラー
3. Difyのフロントエンドコードを調査:
   - web/app/signin/components/mail-and-password-auth.tsx で
     `encryptPassword(password)` を呼び出している
   - web/utils/encryption.ts の実装を確認したところ、
     パスワードをBase64エンコードして送信していることが判明

## 修正内容
Login関数でパスワードをBase64エンコードしてからAPIに送信するよう変更

## 検証
- `difync init` が正常に動作することを確認(153アプリを取得)
- 全テストがパスすることを確認

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@hayasaki-shunsuke
Copy link
Contributor Author

テスト実行

⏺ difync init の実行ログです。

  重要な部分:

  Difync - Dify.AI DSL Synchronizer
  ----------------------------
  Initializing app map file...

  # ページネーションでアプリ一覧を取得
  Debug - Parsed 20 apps from page 1 (total so far: 20)
  Debug - Parsed 20 apps from page 2 (total so far: 40)
  Debug - Parsed 20 apps from page 3 (total so far: 60)
  Debug - Parsed 20 apps from page 4 (total so far: 80)
  Debug - Parsed 20 apps from page 5 (total so far: 100)
  Debug - Parsed 20 apps from page 6 (total so far: 120)
  Debug - Parsed 20 apps from page 7 (total so far: 140)
  Debug - Parsed 13 apps from page 8 (total so far: 153)
  Debug - Total apps fetched: 153

  # 最終結果
  Created new app map file at .../app_map.json with 153 applications
  Successfully initialized app map file with 153 applications
  App map file created at: .../app_map.json
  DSL files downloaded to: .../dsl

  PRコメント用:
  ## 動作確認

  - [x] `difync init` が正常に動作することを確認
    - 8ページにわたるページネーションで153アプリを正常に取得
    - DSLファイルのダウンロードと app_map.json の生成を確認
  - [x] 全テストがパスすることを確認 (`go test ./...`)

Comment on lines +51 to +52
// Encode password with Base64 (required by new Dify API)
encodedPassword := base64.StdEncoding.EncodeToString([]byte(password))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下をご検討ください

  • Difyの最低サポートバージョン(1.11.4以上)をREADMEに記載
  • Login関数のユニットテストを追加(モックサーバーを使用)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

70b53cf こちらで対応しました!

対応内容

  1. README.md
  • Difyの最低サポートバージョン(1.11.4以上)を追記

Requirements

  • Dify version 1.11.4 or later (uses Base64-encoded password for authentication)
  1. internal/api/client_test.go
  • TestLogin: Base64エンコーディングの検証を追加
    • リクエストボディを読み取り、パスワードがBase64エンコードされていることを確認
    • デコードして元のパスワードと一致することを検証
  • TestLoginWithCookieAuth: 新規追加
    • 新しいDify APIのCookie認証方式をテスト

テスト結果:
=== RUN TestLogin
--- PASS: TestLogin (0.00s)
=== RUN TestLoginWithCookieAuth
--- PASS: TestLoginWithCookieAuth (0.00s)
=== RUN TestLoginErrors
--- PASS: TestLoginErrors (0.00s)
PASS

- Add Dify version 1.11.4+ requirement to README
- Enhance TestLogin to verify Base64 password encoding
- Add TestLoginWithCookieAuth for new Dify API cookie-based auth

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants