Adding default scopes

This commit is contained in:
Eugen Rochko 2016-10-23 12:38:42 +02:00
parent 63309f0857
commit 6324b606da
3 changed files with 11 additions and 2 deletions

View File

@ -20,7 +20,7 @@ Example:
```ruby
Rails.application.config.middleware.use OmniAuth::Builder do
provider :mastodon, credentials: lambda { |domain, callback_url|
provider :mastodon, scope: 'read write follow', credentials: lambda { |domain, callback_url|
Rails.logger.info "Requested credentials for #{domain} with callback URL #{callback_url}"
existing = MastodonClient.find_by(domain: domain)

View File

@ -12,7 +12,7 @@ module OmniAuth
end
def patch
0
1
end
def pre

View File

@ -3,10 +3,13 @@ require 'omniauth-oauth2'
module OmniAuth
module Strategies
class Mastodon < OmniAuth::Strategies::OAuth2
DEFAULT_SCOPE = 'read'.freeze
option :name, 'mastodon'
option :credentials
option :identifier
option :authorize_options, [:scope]
option :client_options, {
authorize_url: '/oauth/authorize',
@ -47,6 +50,12 @@ module OmniAuth
full_host + script_name + callback_path
end
def authorize_params
super.tap do |params|
params[:scope] ||= DEFAULT_SCOPE
end
end
private
def get_identifier