Skip to content

Commit 4753f67

Browse files
authored
Remove Rack::Auth::Digest (#2361)
* Remove Rack::Auth::Digest * Update README.md to remove digest auth * Update UPGRADING and CHANGELOG * Fix typo * Bump the version up to 2.0.0 * Quote the class name * Update Stable Release version
1 parent de76b5c commit 4753f67

File tree

7 files changed

+15
-112
lines changed

7 files changed

+15
-112
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
### 1.9.0 (Next)
1+
### 2.0.0 (Next)
22

33
#### Features
44

55
* [#2353](https://github.com/ruby-grape/grape/pull/2353): Added Rails 7.1 support - [@ericproulx](https://github.com/ericproulx).
66
* [#2355](https://github.com/ruby-grape/grape/pull/2355): Set response headers based on Rack version - [@schinery](https://github.com/schinery).
77
* [#2360](https://github.com/ruby-grape/grape/pull/2360): Reduce gem size by removing specs - [@ericproulx](https://github.com/ericproulx).
8+
* [#2361](https://github.com/ruby-grape/grape/pull/2361): Remove `Rack::Auth::Digest` - [@ninoseki](https://github.com/ninoseki).
89
* Your contribution here.
910

1011
#### Fixes

README.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
- [Active Model Serializers](#active-model-serializers)
116116
- [Sending Raw or No Data](#sending-raw-or-no-data)
117117
- [Authentication](#authentication)
118-
- [Basic and Digest Auth](#basic-and-digest-auth)
118+
- [Basic Auth](#basic-auth)
119119
- [Register custom middleware for authentication](#register-custom-middleware-for-authentication)
120120
- [Describing and Inspecting an API](#describing-and-inspecting-an-api)
121121
- [Current Route and Endpoint](#current-route-and-endpoint)
@@ -160,7 +160,7 @@ content negotiation, versioning and much more.
160160

161161
## Stable Release
162162

163-
You're reading the documentation for the next release of Grape, which should be **1.9.0**.
163+
You're reading the documentation for the next release of Grape, which should be **2.0.0**.
164164
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
165165
The current stable release is [1.8.0](https://github.com/ruby-grape/grape/blob/v1.8.0/README.md).
166166

@@ -3422,9 +3422,9 @@ end
34223422
34233423
## Authentication
34243424
3425-
### Basic and Digest Auth
3425+
### Basic Auth
34263426
3427-
Grape has built-in Basic and Digest authentication (the given `block`
3427+
Grape has built-in Basic authentication (the given `block`
34283428
is executed in the context of the current `Endpoint`). Authentication
34293429
applies to the current namespace and any children, but not parents.
34303430
@@ -3435,20 +3435,6 @@ http_basic do |username, password|
34353435
end
34363436
```
34373437

3438-
Digest auth supports clear-text passwords and password hashes.
3439-
3440-
```ruby
3441-
http_digest({ realm: 'Test Api', opaque: 'app secret' }) do |username|
3442-
# lookup the user's password here
3443-
end
3444-
```
3445-
3446-
```ruby
3447-
http_digest(realm: { realm: 'Test Api', opaque: 'app secret', passwords_hashed: true }) do |username|
3448-
# lookup the user's password hash here
3449-
end
3450-
```
3451-
34523438
### Register custom middleware for authentication
34533439

34543440
Grape can use custom Middleware for authentication. How to implement these

UPGRADING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Upgrading Grape
22
===============
33

4-
### Upgrading to >= 1.9.0
4+
### Upgrading to >= 2.0.0
55

66
#### Headers
77

@@ -30,6 +30,12 @@ end
3030

3131
See [#2355](https://github.com/ruby-grape/grape/pull/2355) for more information.
3232

33+
#### Digest auth deprecation
34+
35+
Digest auth has been removed along with the deprecation of `Rack::Auth::Digest` in Rack 3.
36+
37+
See [#2294](https://github.com/ruby-grape/grape/issues/2294) for more information.
38+
3339
### Upgrading to >= 1.7.0
3440

3541
#### Exceptions renaming

lib/grape.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require 'rack/builder'
66
require 'rack/accept'
77
require 'rack/auth/basic'
8-
require 'rack/auth/digest/md5'
98
require 'set'
109
require 'bigdecimal'
1110
require 'date'

lib/grape/middleware/auth/strategies.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def add(label, strategy, option_fetcher = ->(_) { [] })
1212

1313
def auth_strategies
1414
@auth_strategies ||= {
15-
http_basic: StrategyInfo.new(Rack::Auth::Basic, ->(settings) { [settings[:realm]] }),
16-
http_digest: StrategyInfo.new(Rack::Auth::Digest::MD5, ->(settings) { [settings[:realm], settings[:opaque]] })
15+
http_basic: StrategyInfo.new(Rack::Auth::Basic, ->(settings) { [settings[:realm]] })
1716
}
1817
end
1918

lib/grape/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module Grape
44
# The current version of Grape.
5-
VERSION = '1.9.0'
5+
VERSION = '2.0.0'
66
end

spec/grape/middleware/auth/strategies_spec.rb

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -29,92 +29,4 @@ def app
2929
expect(last_response.status).to eq(401)
3030
end
3131
end
32-
33-
context 'Digest MD5 Auth' do
34-
RSpec::Matchers.define :be_challenge do
35-
match do |actual_response|
36-
actual_response.status == 401 &&
37-
actual_response['WWW-Authenticate'].start_with?('Digest ') &&
38-
actual_response.body.empty?
39-
end
40-
end
41-
42-
module StrategiesSpec
43-
class PasswordHashed < Grape::API
44-
http_digest(realm: { realm: 'Test Api', opaque: 'secret', passwords_hashed: true }) do |username|
45-
{ 'foo' => Digest::MD5.hexdigest(['foo', 'Test Api', 'bar'].join(':')) }[username]
46-
end
47-
48-
get '/test' do
49-
[{ hey: 'you' }, { there: 'bar' }, { foo: 'baz' }]
50-
end
51-
end
52-
53-
class PasswordIsNotHashed < Grape::API
54-
http_digest(realm: 'Test Api', opaque: 'secret') do |username|
55-
{ 'foo' => 'bar' }[username]
56-
end
57-
58-
get '/test' do
59-
[{ hey: 'you' }, { there: 'bar' }, { foo: 'baz' }]
60-
end
61-
end
62-
end
63-
64-
context 'when password is hashed' do
65-
def app
66-
StrategiesSpec::PasswordHashed
67-
end
68-
69-
it 'is a digest authentication challenge' do
70-
get '/test'
71-
expect(last_response).to be_challenge
72-
end
73-
74-
it 'throws a 401 if no auth is given' do
75-
get '/test'
76-
expect(last_response.status).to eq(401)
77-
end
78-
79-
it 'authenticates if given valid creds' do
80-
digest_authorize 'foo', 'bar'
81-
get '/test'
82-
expect(last_response.status).to eq(200)
83-
end
84-
85-
it 'throws a 401 if given invalid creds' do
86-
digest_authorize 'bar', 'foo'
87-
get '/test'
88-
expect(last_response.status).to eq(401)
89-
end
90-
end
91-
92-
context 'when password is not hashed' do
93-
def app
94-
StrategiesSpec::PasswordIsNotHashed
95-
end
96-
97-
it 'is a digest authentication challenge' do
98-
get '/test'
99-
expect(last_response).to be_challenge
100-
end
101-
102-
it 'throws a 401 if no auth is given' do
103-
get '/test'
104-
expect(last_response.status).to eq(401)
105-
end
106-
107-
it 'authenticates if given valid creds' do
108-
digest_authorize 'foo', 'bar'
109-
get '/test'
110-
expect(last_response.status).to eq(200)
111-
end
112-
113-
it 'throws a 401 if given invalid creds' do
114-
digest_authorize 'bar', 'foo'
115-
get '/test'
116-
expect(last_response.status).to eq(401)
117-
end
118-
end
119-
end
12032
end

0 commit comments

Comments
 (0)