Adding default scopes
This commit is contained in:
parent
63309f0857
commit
6324b606da
|
@ -20,7 +20,7 @@ Example:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
Rails.application.config.middleware.use OmniAuth::Builder do
|
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}"
|
Rails.logger.info "Requested credentials for #{domain} with callback URL #{callback_url}"
|
||||||
|
|
||||||
existing = MastodonClient.find_by(domain: domain)
|
existing = MastodonClient.find_by(domain: domain)
|
||||||
|
|
|
@ -12,7 +12,7 @@ module OmniAuth
|
||||||
end
|
end
|
||||||
|
|
||||||
def patch
|
def patch
|
||||||
0
|
1
|
||||||
end
|
end
|
||||||
|
|
||||||
def pre
|
def pre
|
||||||
|
|
|
@ -3,10 +3,13 @@ require 'omniauth-oauth2'
|
||||||
module OmniAuth
|
module OmniAuth
|
||||||
module Strategies
|
module Strategies
|
||||||
class Mastodon < OmniAuth::Strategies::OAuth2
|
class Mastodon < OmniAuth::Strategies::OAuth2
|
||||||
|
DEFAULT_SCOPE = 'read'.freeze
|
||||||
|
|
||||||
option :name, 'mastodon'
|
option :name, 'mastodon'
|
||||||
|
|
||||||
option :credentials
|
option :credentials
|
||||||
option :identifier
|
option :identifier
|
||||||
|
option :authorize_options, [:scope]
|
||||||
|
|
||||||
option :client_options, {
|
option :client_options, {
|
||||||
authorize_url: '/oauth/authorize',
|
authorize_url: '/oauth/authorize',
|
||||||
|
@ -47,6 +50,12 @@ module OmniAuth
|
||||||
full_host + script_name + callback_path
|
full_host + script_name + callback_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authorize_params
|
||||||
|
super.tap do |params|
|
||||||
|
params[:scope] ||= DEFAULT_SCOPE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_identifier
|
def get_identifier
|
||||||
|
|
Loading…
Reference in New Issue