1 # == Schema Information
3 # Table name: oauth_tokens
5 # id :integer not null, primary key
8 # client_application_id :integer
11 # authorized_at :datetime
12 # invalidated_at :datetime
13 # created_at :datetime
14 # updated_at :datetime
15 # allow_read_prefs :boolean default(FALSE), not null
16 # allow_write_prefs :boolean default(FALSE), not null
17 # allow_write_diary :boolean default(FALSE), not null
18 # allow_write_api :boolean default(FALSE), not null
19 # allow_read_gpx :boolean default(FALSE), not null
20 # allow_write_gpx :boolean default(FALSE), not null
21 # callback_url :string
22 # verifier :string(20)
25 # allow_write_notes :boolean default(FALSE), not null
29 # index_oauth_tokens_on_token (token) UNIQUE
30 # index_oauth_tokens_on_user_id (user_id)
34 # oauth_tokens_client_application_id_fkey (client_application_id => client_applications.id)
35 # oauth_tokens_user_id_fkey (user_id => users.id)
38 class RequestToken < OauthToken
39 attr_accessor :provided_oauth_verifier
42 return false if authorized?
45 self.authorized_at = Time.now.utc
46 self.verifier = OAuth::Helper.generate_key(20)[0, 20] unless oauth10?
51 return false unless authorized?
52 return false unless oauth10? || verifier == provided_oauth_verifier
54 RequestToken.transaction do
55 params = { :user => user, :client_application => client_application }
56 # copy the permissions from the authorised request token to the access token
57 client_application.permissions.each do |p|
61 access_token = AccessToken.create(params)
71 "#{super}&oauth_callback_confirmed=true"
76 callback_url.nil? || callback_url.casecmp("oob").zero?
80 Settings.key?(:oauth_10_support) && Settings.oauth_10_support && callback_url.blank?