Skip to content

Commit

Permalink
Check for oauth2 tokens.
Browse files Browse the repository at this point in the history
It appears that Swagger-UI correctly sets an authorization header when
added in the interface (api key field). However, if the endpoint has
the option "authorizations" set with "oauth2", it will override the
value. See ruby-grape#13.
  • Loading branch information
Sunny Juneja committed Aug 25, 2015
1 parent 7caa399 commit 6155558
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/dummy/app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ class API < Grape::API
request.params.as_json
end

desc 'Return oauth2 token', authorizations: { oauth2: [] }
get '/oauth2' do
request.headers.slice('Authorization').as_json
end

add_swagger_documentation
end
17 changes: 17 additions & 0 deletions spec/features/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@
expect(page).to have_css 'span.string', text: 'dummy'
end
end
context '#api_auth:oauth2' do
before do
GrapeSwaggerRails.options.api_auth = 'bearer'
GrapeSwaggerRails.options.api_key_name = 'Authorization'
GrapeSwaggerRails.options.api_key_type = 'header'
visit '/swagger'
end
it 'adds an Authorization header' do
page.execute_script("$('#input_apiKey').val('token')")
page.execute_script("$('#input_apiKey').trigger('change')")
find('#endpointListTogger_oauth2', visible: true).click
first('a[href="#!/oauth2/GET_api_oauth2_format"]', visible: true).click
click_button 'Try it out!'
expect(page).to have_css 'span.attribute', text: 'Authorization'
expect(page).to have_css 'span.string', text: 'Bearer token'
end
end
context '#before_filter' do
before do
GrapeSwaggerRails.options.before_filter do |_request|
Expand Down

0 comments on commit 6155558

Please sign in to comment.