diff --git a/NEWS.md b/NEWS.md index 8993137e1..1c35e8fdf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ User-visible changes worth mentioning. ## master +- [#1214]: Scopes field accepts array. - [#1209] Fix tokens validation for Token Introspection request. - [#1202] Use correct HTTP status codes for error responses. diff --git a/lib/doorkeeper/models/concerns/scopes.rb b/lib/doorkeeper/models/concerns/scopes.rb index cdec0b656..b0633df4e 100644 --- a/lib/doorkeeper/models/concerns/scopes.rb +++ b/lib/doorkeeper/models/concerns/scopes.rb @@ -7,6 +7,14 @@ def scopes OAuth::Scopes.from_string(scopes_string) end + def scopes=(value) + if value.is_a? Array + super value.join(' ') + else + super value + end + end + def scopes_string self[:scopes] end diff --git a/spec/requests/protected_resources/private_api_spec.rb b/spec/requests/protected_resources/private_api_spec.rb index c0fbed8cf..c09cda55e 100644 --- a/spec/requests/protected_resources/private_api_spec.rb +++ b/spec/requests/protected_resources/private_api_spec.rb @@ -73,7 +73,7 @@ end scenario 'access token with both allowed scopes' do - @token.update_attribute :scopes, 'write admin' + @token.update_attribute :scopes, %w[write admin] with_access_token_header @token.token visit '/full_protected_resources/1.json' expect(page.body).to have_content('show')