Class: SignIn::ServiceAccountAccessToken

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_account_id:, audience:, user_identifier:, scopes: [], user_attributes: {}, uuid: nil, version: nil, expiration_time: nil, created_time: nil) ⇒ ServiceAccountAccessToken

rubocop:disable Metrics/ParameterLists



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/sign_in/service_account_access_token.rb', line 33

def initialize(service_account_id:,
               audience:,
               user_identifier:,
               scopes: [],
               user_attributes: {},
               uuid: nil,
               version: nil,
               expiration_time: nil,
               created_time: nil)
  @uuid = uuid || create_uuid
  @service_account_id = 
  @user_attributes = user_attributes
  @user_identifier = user_identifier
  @scopes = scopes
  @audience = audience
  @version = version || Constants::ServiceAccountAccessToken::CURRENT_VERSION
  @expiration_time = expiration_time || set_expiration_time
  @created_time = created_time || set_created_time

  validate!
end

Instance Attribute Details

#audienceObject (readonly)

Returns the value of attribute audience.



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

def audience
  @audience
end

#created_timeObject (readonly)

Returns the value of attribute created_time.



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

def created_time
  @created_time
end

#expiration_timeObject (readonly)

Returns the value of attribute expiration_time.



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

def expiration_time
  @expiration_time
end

#scopesObject (readonly)

Returns the value of attribute scopes.



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

def scopes
  @scopes
end

#service_account_idObject (readonly)

Returns the value of attribute service_account_id.



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

def 
  @service_account_id
end

#user_attributesObject (readonly)

Returns the value of attribute user_attributes.



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

def user_attributes
  @user_attributes
end

#user_identifierObject (readonly)

Returns the value of attribute user_identifier.



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

def user_identifier
  @user_identifier
end

#uuidObject (readonly)

Returns the value of attribute uuid.



7
8
9
# File 'app/models/sign_in/service_account_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/service_account_access_token.rb', line 7

def version
  @version
end

Instance Method Details

#create_uuidObject (private)



76
77
78
# File 'app/models/sign_in/service_account_access_token.rb', line 76

def create_uuid
  SecureRandom.uuid
end

#persisted?Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


56
57
58
# File 'app/models/sign_in/service_account_access_token.rb', line 56

def persisted?
  false
end

#service_account_configObject (private)



92
93
94
# File 'app/models/sign_in/service_account_access_token.rb', line 92

def 
  @service_account_config ||= ServiceAccountConfig.find_by(service_account_id:)
end

#set_created_timeObject (private)



84
85
86
# File 'app/models/sign_in/service_account_access_token.rb', line 84

def set_created_time
  Time.zone.now
end

#set_expiration_timeObject (private)



80
81
82
# File 'app/models/sign_in/service_account_access_token.rb', line 80

def set_expiration_time
  Time.zone.now + validity_length
end

#to_sObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/sign_in/service_account_access_token.rb', line 60

def to_s
  {
    uuid:,
    service_account_id:,
    user_attributes:,
    user_identifier:,
    scopes:,
    audience:,
    version:,
    created_time: created_time.to_i,
    expiration_time: expiration_time.to_i
  }
end

#validity_lengthObject (private)



88
89
90
# File 'app/models/sign_in/service_account_access_token.rb', line 88

def validity_length
  .access_token_duration
end