From 6324b606da91300e237b5eb2a7bea7908fb975c8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 23 Oct 2016 12:38:42 +0200 Subject: [PATCH] Adding default scopes --- README.md | 2 +- lib/omniauth/mastodon/version.rb | 2 +- lib/omniauth/strategies/mastodon.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 103862e..77e479d 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/omniauth/mastodon/version.rb b/lib/omniauth/mastodon/version.rb index e29b7c4..0a0941f 100644 --- a/lib/omniauth/mastodon/version.rb +++ b/lib/omniauth/mastodon/version.rb @@ -12,7 +12,7 @@ module OmniAuth end def patch - 0 + 1 end def pre diff --git a/lib/omniauth/strategies/mastodon.rb b/lib/omniauth/strategies/mastodon.rb index 5204bd8..95d4033 100644 --- a/lib/omniauth/strategies/mastodon.rb +++ b/lib/omniauth/strategies/mastodon.rb @@ -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