Class: SignIn::AccessToken

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/sign_in/access_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_handle:, client_id:, user_uuid:, audience:, refresh_token_hash:, anti_csrf_token:, last_regeneration_time:, uuid: nil, parent_refresh_token_hash: nil, version: nil, expiration_time: nil, created_time: nil, user_attributes: nil, device_secret_hash: nil) ⇒ AccessToken

rubocop:disable Metrics/ParameterLists



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/sign_in/access_token.rb', line 42

def initialize(session_handle:,
               client_id:,
               user_uuid:,
               audience:,
               refresh_token_hash:,
               anti_csrf_token:,
               last_regeneration_time:,
               uuid: nil,
               parent_refresh_token_hash: nil,
               version: nil,
               expiration_time: nil,
               created_time: nil,
               user_attributes: nil,
               device_secret_hash: nil)
  @uuid = uuid || create_uuid
  @session_handle = session_handle
  @client_id = client_id
  @user_uuid = user_uuid
  @audience = audience
  @refresh_token_hash = refresh_token_hash
  @anti_csrf_token = anti_csrf_token
  @last_regeneration_time = last_regeneration_time
  @parent_refresh_token_hash = parent_refresh_token_hash
  @version = version || Constants::AccessToken::CURRENT_VERSION
  @expiration_time = expiration_time || set_expiration_time
  @created_time = created_time || set_created_time
  @user_attributes = filter_user_attributes(user_attributes:)
  @device_secret_hash = device_secret_hash

  validate!
end

Instance Attribute Details

#anti_csrf_tokenObject (readonly)

Returns the value of attribute anti_csrf_token.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def anti_csrf_token
  @anti_csrf_token
end

#audienceObject (readonly)

Returns the value of attribute audience.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def audience
  @audience
end

#client_idObject (readonly)

Returns the value of attribute client_id.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def client_id
  @client_id
end

#created_timeObject (readonly)

Returns the value of attribute created_time.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def created_time
  @created_time
end

#device_secret_hashObject (readonly)

Returns the value of attribute device_secret_hash.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def device_secret_hash
  @device_secret_hash
end

#expiration_timeObject (readonly)

Returns the value of attribute expiration_time.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def expiration_time
  @expiration_time
end

#last_regeneration_timeObject (readonly)

Returns the value of attribute last_regeneration_time.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def last_regeneration_time
  @last_regeneration_time
end

#parent_refresh_token_hashObject (readonly)

Returns the value of attribute parent_refresh_token_hash.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def parent_refresh_token_hash
  @parent_refresh_token_hash
end

#refresh_token_hashObject (readonly)

Returns the value of attribute refresh_token_hash.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def refresh_token_hash
  @refresh_token_hash
end

#session_handleObject (readonly)

Returns the value of attribute session_handle.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def session_handle
  @session_handle
end

#user_attributesObject (readonly)

Returns the value of attribute user_attributes.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def user_attributes
  @user_attributes
end

#user_uuidObject (readonly)

Returns the value of attribute user_uuid.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def user_uuid
  @user_uuid
end

#uuidObject (readonly)

Returns the value of attribute uuid.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def uuid
  @uuid
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'app/models/sign_in/access_token.rb', line 7

def version
  @version
end

Instance Method Details

#client_configObject (private)



117
118
119
# File 'app/models/sign_in/access_token.rb', line 117

def client_config
  @client_config ||= ClientConfig.find_by(client_id:)
end

#create_uuidObject (private)



95
96
97
# File 'app/models/sign_in/access_token.rb', line 95

def create_uuid
  SecureRandom.uuid
end

#filter_user_attributes(user_attributes:) ⇒ Object (private)



111
112
113
114
115
# File 'app/models/sign_in/access_token.rb', line 111

def filter_user_attributes(user_attributes:)
  return nil unless user_attributes.presence

  user_attributes.with_indifferent_access.select { |key| client_config&.access_token_attributes&.include?(key) }
end

#persisted?Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


75
76
77
# File 'app/models/sign_in/access_token.rb', line 75

def persisted?
  false
end

#set_created_timeObject (private)



103
104
105
# File 'app/models/sign_in/access_token.rb', line 103

def set_created_time
  Time.zone.now
end

#set_expiration_timeObject (private)



99
100
101
# File 'app/models/sign_in/access_token.rb', line 99

def set_expiration_time
  Time.zone.now + validity_length
end

#to_sObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/sign_in/access_token.rb', line 79

def to_s
  {
    uuid:,
    user_uuid:,
    session_handle:,
    client_id:,
    audience:,
    version:,
    last_regeneration_time: last_regeneration_time.to_i,
    created_time: created_time.to_i,
    expiration_time: expiration_time.to_i
  }
end

#validity_lengthObject (private)



107
108
109
# File 'app/models/sign_in/access_token.rb', line 107

def validity_length
  client_config.access_token_duration
end