Class: RequestToken

Inherits:
OauthToken
  • Object
show all
Defined in:
lib/generators/mongoid/oauth_provider_templates/request_token.rb,
lib/generators/active_record/oauth_provider_templates/request_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OauthToken

#authorized?, #invalidate!, #invalidated?

Instance Attribute Details

#provided_oauth_verifierObject

Returns the value of attribute provided_oauth_verifier.



2
3
4
# File 'lib/generators/mongoid/oauth_provider_templates/request_token.rb', line 2

def provided_oauth_verifier
  @provided_oauth_verifier
end

Instance Method Details

#authorize!(user) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/generators/mongoid/oauth_provider_templates/request_token.rb', line 4

def authorize!(user)
  return false if authorized?
  self.user           = user
  self.authorized_at  = Time.now
  self.verifier       = OAuth::Helper.generate_key(20)[0,20] unless oauth10?
  self.save
end

#exchange!Object



12
13
14
15
16
17
18
19
# File 'lib/generators/mongoid/oauth_provider_templates/request_token.rb', line 12

def exchange!
  return false unless authorized?
  return false unless oauth10? || verifier == provided_oauth_verifier

  AccessToken.create(:user => user, :client_application => client_application).tap do
    invalidate!
  end
end

#oauth10?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/generators/mongoid/oauth_provider_templates/request_token.rb', line 33

def oauth10?
  (defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
end

#oob?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/generators/mongoid/oauth_provider_templates/request_token.rb', line 29

def oob?
  callback_url.nil? || callback_url.downcase == 'oob'
end

#to_queryObject



21
22
23
24
25
26
27
# File 'lib/generators/mongoid/oauth_provider_templates/request_token.rb', line 21

def to_query
  if oauth10?
    super
  else
    "#{super}&oauth_callback_confirmed=true"
  end
end