Class: OAuth2::AuthCode
- Inherits:
-
Object
- Object
- OAuth2::AuthCode
- Defined in:
- lib/oauth20/auth_code.rb
Overview
Authorization code class represents short-lived authorization for user which should be exchanged for access token until it expires.
Constant Summary collapse
- EXPIRES_IN =
Expires in 10 minutes.
10 * 60
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_key ⇒ Object
readonly
Returns the value of attribute client_key.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Check if the authorization code is still valid to generate new access token.
-
#initialize(data) ⇒ AuthCode
constructor
Initialize new authorization code.
- #invalidate(access_token) ⇒ Object
- #save ⇒ Object
- #used? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ AuthCode
Initialize new authorization code.
17 18 19 20 21 22 23 24 |
# File 'lib/oauth20/auth_code.rb', line 17 def initialize(data) @key = data[:key] @created_at = data[:created_at] || Time.now @expires_at = data[:expires_at] || Time.now + EXPIRES_IN @access_token = data[:access_token] @user_id = data[:user_id] @client_key = data[:client_key] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/oauth20/auth_code.rb', line 7 def access_token @access_token end |
#client_key ⇒ Object (readonly)
Returns the value of attribute client_key.
7 8 9 |
# File 'lib/oauth20/auth_code.rb', line 7 def client_key @client_key end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/oauth20/auth_code.rb', line 7 def created_at @created_at end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
7 8 9 |
# File 'lib/oauth20/auth_code.rb', line 7 def expires_at @expires_at end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/oauth20/auth_code.rb', line 7 def key @key end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
7 8 9 |
# File 'lib/oauth20/auth_code.rb', line 7 def user_id @user_id end |
Class Method Details
.find_by_key(key) ⇒ Object
42 43 44 |
# File 'lib/oauth20/auth_code.rb', line 42 def self.find_by_key(key) Storage.instance.auth_code_find_by_key(key) end |
Instance Method Details
#expired? ⇒ Boolean
Check if the authorization code is still valid to generate new access token.
29 30 31 |
# File 'lib/oauth20/auth_code.rb', line 29 def expired? Time.now > @expires_at end |
#invalidate(access_token) ⇒ Object
37 38 39 40 |
# File 'lib/oauth20/auth_code.rb', line 37 def invalidate(access_token) @access_token = access_token.key save end |
#save ⇒ Object
46 47 48 |
# File 'lib/oauth20/auth_code.rb', line 46 def save Storage.instance.auth_code_save(self) end |
#used? ⇒ Boolean
33 34 35 |
# File 'lib/oauth20/auth_code.rb', line 33 def used? not @access_token.nil? end |