Class: Pageflow::AuthenticationToken

Inherits:
ApplicationRecord show all
Defined in:
app/models/pageflow/authentication_token.rb

Overview

AuthenticationToken stores the tokens with expiry time against user and provider

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_auth_token(user_id, auth_provider, auth_token, expiry_time) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'app/models/pageflow/authentication_token.rb', line 17

def self.create_auth_token(user_id, auth_provider, auth_token, expiry_time)
  token = AuthenticationToken.new
  token.user_id = user_id
  token.provider = auth_provider
  token.auth_token = auth_token
  token.expiry_time = Time.at(expiry_time) if expiry_time.present? && expiry_time.is_a?(Integer)
  token.save!
  token
end

.find_auth_token(current_user, provider) ⇒ Object



32
33
34
35
# File 'app/models/pageflow/authentication_token.rb', line 32

def self.find_auth_token(current_user, provider)
  where(user_id: current_user.id,
        provider: provider)
end

.update_token(record, token, expiry_time) ⇒ Object



27
28
29
30
# File 'app/models/pageflow/authentication_token.rb', line 27

def self.update_token(record, token, expiry_time)
  record.update(auth_token: token,
                expiry_time: Time.at(expiry_time))
end

Instance Method Details

#auth_tokenObject



9
10
11
# File 'app/models/pageflow/authentication_token.rb', line 9

def auth_token
  SymmetricEncryption.decrypt(read_attribute(:auth_token))
end

#auth_token=(token) ⇒ Object



13
14
15
# File 'app/models/pageflow/authentication_token.rb', line 13

def auth_token=(token)
  write_attribute(:auth_token, SymmetricEncryption.encrypt(token))
end