]> git.openstreetmap.org Git - rails.git/blob - lib/oauth.rb
Merge remote-tracking branch 'upstream/pull/4425'
[rails.git] / lib / oauth.rb
1 module Oauth
2   SCOPES = %w[read_prefs write_prefs write_diary write_api read_gpx write_gpx write_notes].freeze
3   PRIVILEGED_SCOPES = %w[read_email skip_authorization].freeze
4   OAUTH2_SCOPES = %w[openid].freeze
5
6   class Scope
7     attr_reader :name
8
9     def initialize(name)
10       @name = name
11     end
12
13     def description
14       I18n.t("oauth.scopes.#{name}")
15     end
16   end
17
18   def self.scopes(oauth2: false, privileged: false)
19     scopes = SCOPES
20     scopes += PRIVILEGED_SCOPES if privileged
21     scopes += OAUTH2_SCOPES if oauth2
22     scopes.collect { |s| Scope.new(s) }
23   end
24 end