Class: SignIn::RefreshTokenEncryptor

Inherits:
Object
  • Object
show all
Defined in:
app/services/sign_in/refresh_token_encryptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(refresh_token:) ⇒ RefreshTokenEncryptor

Returns a new instance of RefreshTokenEncryptor.



7
8
9
10
11
12
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 7

def initialize(refresh_token:)
  @refresh_token = refresh_token
  validate_input
  @version = refresh_token.version
  @nonce = refresh_token.nonce
end

Instance Attribute Details

#nonceObject (readonly)

Returns the value of attribute nonce.



5
6
7
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 5

def nonce
  @nonce
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



5
6
7
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 5

def refresh_token
  @refresh_token
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 5

def version
  @version
end

Instance Method Details

#build_refresh_token_string(encrypted_refresh_token) ⇒ Object (private)



27
28
29
30
31
32
33
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 27

def build_refresh_token_string(encrypted_refresh_token)
  string_array = []
  string_array[Constants::RefreshToken::ENCRYPTED_POSITION] = encrypted_refresh_token
  string_array[Constants::RefreshToken::NONCE_POSITION] = nonce
  string_array[Constants::RefreshToken::VERSION_POSITION] = version
  string_array.join('.')
end

#message_encryptorObject (private)



40
41
42
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 40

def message_encryptor
  KmsEncrypted::Box.new
end

#performObject



14
15
16
17
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 14

def perform
  encrypted_refresh_token = serialize_and_encrypt_refresh_token
  build_refresh_token_string(encrypted_refresh_token)
end

#serialize_and_encrypt_refresh_tokenObject (private)



35
36
37
38
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 35

def serialize_and_encrypt_refresh_token
  serialized_refresh_token = refresh_token.to_json
  message_encryptor.encrypt(serialized_refresh_token)
end

#validate_inputObject (private)



21
22
23
24
25
# File 'app/services/sign_in/refresh_token_encryptor.rb', line 21

def validate_input
  unless refresh_token.version && refresh_token.nonce
    raise Errors::RefreshTokenMalformedError.new message: 'Refresh token is malformed'
  end
end