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

Update doorkeeper to be used with grape >= 0.10 #915

Merged
Merged
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ You can pass any option `before_action` accepts, such as `if`, `only`,

### Protect your API with OAuth when using Grape

As of [PR 567] doorkeeper has helpers for Grape. One of them is
As of [PR 567] doorkeeper has helpers for Grape >= 0.10. One of them is
`doorkeeper_authorize!` and can be used in a similar way as an example above.
Note that you have to use `require 'doorkeeper/grape/helpers'` and
`helpers Doorkeeper::Grape::Helpers`.
Expand All @@ -198,6 +198,11 @@ module API
doorkeeper_authorize!
end

route_setting :scopes, ['user:email']
get :emails do
[{'email' => current_user.email}]
end

# ...
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/doorkeeper/grape/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
module Doorkeeper
module Grape
module Helpers
# These helpers are for grape >= 0.10
extend ::Grape::API::Helpers
include Doorkeeper::Rails::Helpers

# endpoint specific scopes > parameter scopes > default scopes
def doorkeeper_authorize!(*scopes)
endpoint_scopes = env['api.endpoint'].options[:route_options][:scopes]
endpoint_scopes = env["api.endpoint"].route_setting(:scopes)
scopes = if endpoint_scopes
Doorkeeper::OAuth::Scopes.from_array(endpoint_scopes)
elsif scopes && !scopes.empty?
Expand Down