Skip to content

Commit a286459

Browse files
authored
Merge pull request #101 from harvesthq/pu-www-authenticate-extra-attributes
Add support for resource_metadata in the WWW-Authenticate header
2 parents 19f6366 + c31ec90 commit a286459

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/rack/oauth2/server/abstract/error.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ module OAuth2
33
module Server
44
module Abstract
55
class Error < StandardError
6-
attr_accessor :status, :error, :description, :uri, :realm
6+
attr_accessor :status, :error, :description, :uri, :realm, :resource_metadata
77

88
def initialize(status, error, description = nil, options = {})
99
@status = status
1010
@error = error
1111
@description = description
1212
@uri = options[:uri]
1313
@realm = options[:realm]
14+
@resource_metadata = options[:resource_metadata]
1415
super [error, description].compact.join(' :: ')
1516
end
1617

lib/rack/oauth2/server/resource/error.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def finish
1919
headers << ", error_description=\"#{description}\"" if description.present?
2020
headers << ", error_uri=\"#{uri}\"" if uri.present?
2121
end
22+
headers << ", resource_metadata=\"#{resource_metadata}\"" if resource_metadata.present?
2223
end
2324
end
2425
end

spec/rack/oauth2/server/resource/error_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ def scheme
7777
response.first.should include '"error":"something"'
7878
end
7979
end
80+
81+
context 'when resource_metadata is specified' do
82+
let(:resource_metadata) { "https://resource.example.com/.well-known/oauth-protected-resource" }
83+
let(:error) { Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new(:something, nil, resource_metadata: resource_metadata) }
84+
85+
it 'should include resource_metadata in WWW-Authenticate header' do
86+
_, headers, response = error_with_scheme.finish
87+
headers['WWW-Authenticate'].should include %(resource_metadata="#{resource_metadata}")
88+
response.first.should include '"error":"something"'
89+
end
90+
end
8091
end
8192
end
8293
end

0 commit comments

Comments
 (0)