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