]> git.openstreetmap.org Git - rails.git/blob - app/models/oauth2_verifier.rb
Made rubocop happy by formatting and minor syntax tweaks.
[rails.git] / app / models / oauth2_verifier.rb
1 class Oauth2Verifier < OauthToken
2   validates :user, :presence => true, :associated => true
3
4   attr_accessor :state
5
6   def exchange!(_params = {})
7     OauthToken.transaction do
8       token = Oauth2Token.create! :user => user, :client_application => client_application, :scope => scope
9       invalidate!
10       token
11     end
12   end
13
14   def code
15     token
16   end
17
18   def redirect_url
19     callback_url
20   end
21
22   def to_query
23     q = "code=#{token}"
24     q << "&state=#{URI.escape(state)}" if @state
25     q
26   end
27
28   protected
29
30   def generate_keys
31     self.token = OAuth::Helper.generate_key(20)[0, 20]
32     self.expires_at = 10.minutes.from_now
33     self.authorized_at = Time.now
34   end
35 end