lib/nubank_sdk/auth.rb in nubank_sdk-0.7.1 vs lib/nubank_sdk/auth.rb in nubank_sdk-0.7.2
- old
+ new
@@ -5,11 +5,11 @@
module NubankSdk
#
# Auth method to connect with the nubank api
#
class Auth
- attr_accessor :refresh_token, :refresh_before, :access_token
+ attr_accessor :refresh_token, :refresh_before, :access_token, :encrypted_code, :p_key
#
# Auth method to connect with the nubank api
#
# @param [String] cpf the cpf to authenticate
@@ -20,10 +20,11 @@
@cpf = cpf
@device_id = device_id || generate_device_id
@api_routes = api_routes || ApiRoutes.new
@connection_adapter = connection_adapter
+ @p_key = OpenSSL::PKey::RSA.new 2048
end
#
# Return the instance of user certificate
#
@@ -73,11 +74,11 @@
new_payload = payload(password)
.merge({ code: email_code, 'encrypted-code': @encrypted_code })
response = default_connection.post(@gen_certificate_path, new_payload)
response_data = Client.get_body(response)
- certificate.process_decoded(key, response_data[:certificate])
+ certificate.process_decoded(@p_key, response_data[:certificate])
end
private
# @!visibility private
@@ -108,11 +109,11 @@
# @return [Hash] the payload to generate a new certificate
def payload(password)
{
login: @cpf,
password: password,
- public_key: key.public_key.to_pem,
+ public_key: @p_key.public_key.to_pem,
device_id: @device_id,
model: "NubankSdk Client (#{@device_id})"
}
end
@@ -131,18 +132,10 @@
'password': password
}
end
# @!visibility private
- # Generates a new key for the certificate communication
- #
- # @return [OpenSSL::PKey::RSA] a new key
- def generate_key
- OpenSSL::PKey::RSA.new 2048
- end
-
- # @!visibility private
# Add the new links to the api routes
#
# @param [Hash] links the new links to add
#
# @return [NubankSdk::ApiRoutes] the api routes with the new links
@@ -198,17 +191,9 @@
# Create a new ssl connection to the nubank api
#
# @return [Client::HTTPS] a new ssl connection
def ssl_connection
@ssl_connection ||= Client::HTTPS.new(certificate.encoded, @connection_adapter)
- end
-
- # @!visibility private
- # return the key of the certificate communication
- #
- # @return [OpenSSL::PKey::RSA] the key of the certificate
- def key
- @key ||= generate_key
end
# @!visibility private
# Generates a random device id
#