Auth0::Algorithm is not loaded by `require "auth0"`, so ID token validation raises NameError

未關閉 適合新手
#844 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
83/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
ruby

研究方向

閱讀 lib/auth0/mixins/validation.rb、lib/auth0/api/authentication_endpoints.rb 和頂層 require 路徑,了解 Auth0::Algorithm 如何載入。新增一個回歸測試,只使用 require "auth0" 載入函式庫並執行 ID token 驗證。完成標準是演算法常數可用,且虛構的 token 會觸發預期的 Auth0::InvalidIdToken 錯誤。

由索引模型根據 Issue 內容生成。

描述

Description

In v6.7.0, require "auth0" does not load auth0/algorithm, so Auth0::Algorithm is undefined. Auth0::Mixins::Validation::IdTokenValidator refers to Auth0::Algorithm::RS256 and Auth0::Algorithm::HS256 (lib/auth0/mixins/validation.rb), and validate_id_token uses Auth0::Algorithm::RS256 as its default (lib/auth0/api/authentication_endpoints.rb). Validating an ID token therefore raises a NameError, unless the application requires auth0/algorithm itself.

EXAMPLES.md documents algorithm: Auth0::Algorithm::RS256.jwks_url(...) and Auth0::Algorithm::HS256.secret(...), which do not work after a plain require "auth0" either.

Reproduction
require "auth0"

defined?(Auth0::Algorithm)
# => nil

alg = Auth0::Mixins::Validation::Algorithm::RS256.jwks_url("https://samples.auth0.com/.well-known/jwks.json")
validator = Auth0::Mixins::Validation::IdTokenValidator.new(
  algorithm: alg, leeway: 60, issuer: "https://samples.auth0.com/", audience: "x"
)
validator.validate("eyJhbGciOiJSUzI1NiIsImtpZCI6ImsxIn0.e30.c2ln")
# => NameError: uninitialized constant Auth0::Algorithm

require "auth0/algorithm"
validator.validate("eyJhbGciOiJSUzI1NiIsImtpZCI6ImsxIn0.e30.c2ln")
# => Auth0::InvalidIdToken (the expected error for this made-up token)
Cause

v5's lib/auth0.rb contained require 'auth0/algorithm'. The v6 rewrite (e7c21e79) did not carry the require over, and nothing else requires lib/auth0/algorithm.rb.

Suggested fix

Require auth0/algorithm where the validation mixin is loaded (for example from lib/auth0/mixins.rb or lib/auth0/auth_client.rb), and add a test that validates an ID token after only requiring auth0.

Environment
  • auth0 gem v6.7.0 (repository at 18167468), Ruby 3.3.14
主要語言
Ruby
星號
205
分支
144
平均合併
1 天 13 小時
30 天內合併 PR
9

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

auth0/ruby-auth0 的其他 Issue

查看 auth0/ruby-auth0 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。