Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for authorization header. #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 a token when the route specifies oauth2 authorization' 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