class GrapeTokenAuth::Token

Attributes

client_id[R]
expiry[R]
token[R]

Public Class Methods

new(client_id = nil, token = nil, expiry = nil) click to toggle source
# 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

Public Instance Methods

to_h() click to toggle source
# 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() click to toggle source
# File lib/grape_token_auth/token.rb, line 20
def to_password_hash
  @password_hash ||= BCrypt::Password.create(@token)
end
to_s() click to toggle source
# File lib/grape_token_auth/token.rb, line 12
def to_s
  @token
end