Class: GrapeTokenAuth::Token
- Inherits:
-
Object
- Object
- GrapeTokenAuth::Token
- Defined in:
- lib/grape_token_auth/token.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#expiry ⇒ Object
readonly
Returns the value of attribute expiry.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(client_id = nil, token = nil, expiry = nil) ⇒ Token
constructor
A new instance of Token.
- #to_h ⇒ Object
- #to_password_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(client_id = nil, token = nil, expiry = nil) ⇒ Token
Returns a new instance of Token.
6 7 8 9 10 |
# File 'lib/grape_token_auth/token.rb', line 6 def initialize(client_id = nil, token = nil, expiry = nil) @client_id = client_id || SecureRandom.urlsafe_base64(nil, false) @token = token || SecureRandom.urlsafe_base64(nil, false) @expiry = expiry || (Time.now + GrapeTokenAuth.token_lifespan).to_i end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/grape_token_auth/token.rb', line 4 def client_id @client_id end |
#expiry ⇒ Object (readonly)
Returns the value of attribute expiry.
4 5 6 |
# File 'lib/grape_token_auth/token.rb', line 4 def expiry @expiry end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/grape_token_auth/token.rb', line 4 def token @token end |
Instance Method Details
#to_h ⇒ Object
16 17 18 |
# File 'lib/grape_token_auth/token.rb', line 16 def to_h { expiry: expiry, token: to_password_hash, updated_at: Time.now } end |
#to_password_hash ⇒ Object
20 21 22 |
# File 'lib/grape_token_auth/token.rb', line 20 def to_password_hash @password_hash ||= BCrypt::Password.create(@token) end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/grape_token_auth/token.rb', line 12 def to_s @token end |