Commit 4638481
Fix UnknownAuthStrategy raised when custom auth strategy inherits from Grape::Middleware::Auth::Base (#2674)
When a custom auth strategy class inherits from Grape::Middleware::Auth::Base
and is registered via Grape::Middleware::Auth::Strategies.add, it would raise
Grape::Exceptions::UnknownAuthStrategy with a blank strategy name upon being
instantiated by StrategyInfo#create.
The root cause: PR #2563 moved the strategy lookup from request-time (_call)
to initialization-time (initialize). When StrategyInfo#create instantiates
the custom class via auth_class.new(app) (without options), the inherited
initialize tries to look up options[:type] which is nil, causing the error.
The fix: guard the strategy lookup so it only runs when :type is present in
options. This preserves compile-time validation for the outer middleware
wrapper while allowing subclasses to be instantiated as actual strategies.
Fixes #2669.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent fe3b4f8 commit 4638481
File tree
3 files changed
+38
-0
lines changed- lib/grape/middleware/auth
- spec/grape/middleware/auth
3 files changed
+38
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
45 | 80 | | |
0 commit comments