]> git.openstreetmap.org Git - rails.git/blob - lib/oauth.rb
Merge remote-tracking branch 'upstream/pull/4272'
[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   MODERATOR_SCOPES = %w[write_redactions].freeze
5   OAUTH2_SCOPES = %w[write_redactions openid].freeze
6
7   class Scope
8     attr_reader :name
9
10     def initialize(name)
11       @name = name
12     end
13
14     def description
15       I18n.t("oauth.scopes.#{name}")
16     end
17   end
18
19   def self.scopes(oauth2: false, privileged: false)
20     scopes = SCOPES
21     scopes += PRIVILEGED_SCOPES if privileged
22     scopes += OAUTH2_SCOPES if oauth2
23     scopes.collect { |s| Scope.new(s) }
24   end
25 end