Class: NubankSdk::Auth
- Inherits:
-
Object
- Object
- NubankSdk::Auth
- Defined in:
- lib/nubank_sdk/auth.rb
Overview
Auth method to connect with the nubank api
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#encrypted_code ⇒ Object
Returns the value of attribute encrypted_code.
-
#p_key ⇒ Object
Returns the value of attribute p_key.
-
#refresh_before ⇒ Object
Returns the value of attribute refresh_before.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Instance Method Summary collapse
-
#authenticate_with_certificate(password) ⇒ NubankSdk::ApiRoutes
Authenticate with the nubank api to get a new access token.
-
#certificate ⇒ NubankSdk::Certificate
Return the instance of user certificate.
-
#exchange_certs(email_code, password, custom_encryption = nil) ⇒ File
Verify communication with the nubank api.
-
#initialize(cpf:, device_id: nil, api_routes: nil, connection_adapter: nil) ⇒ Auth
constructor
Auth method to connect with the nubank api.
-
#request_email_code(password) ⇒ String
Request to nubank api to generate a new certificate.
Constructor Details
#initialize(cpf:, device_id: nil, api_routes: nil, connection_adapter: nil) ⇒ Auth
Auth method to connect with the nubank api
19 20 21 22 23 24 25 26 27 |
# File 'lib/nubank_sdk/auth.rb', line 19 def initialize(cpf:, device_id: nil, api_routes: nil, connection_adapter: nil) @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 @encrypted_code = '' end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/nubank_sdk/auth.rb', line 10 def access_token @access_token end |
#encrypted_code ⇒ Object
Returns the value of attribute encrypted_code.
10 11 12 |
# File 'lib/nubank_sdk/auth.rb', line 10 def encrypted_code @encrypted_code end |
#p_key ⇒ Object
Returns the value of attribute p_key.
10 11 12 |
# File 'lib/nubank_sdk/auth.rb', line 10 def p_key @p_key end |
#refresh_before ⇒ Object
Returns the value of attribute refresh_before.
10 11 12 |
# File 'lib/nubank_sdk/auth.rb', line 10 def refresh_before @refresh_before end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
10 11 12 |
# File 'lib/nubank_sdk/auth.rb', line 10 def refresh_token @refresh_token end |
Instance Method Details
#authenticate_with_certificate(password) ⇒ NubankSdk::ApiRoutes
Authenticate with the nubank api to get a new access token
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nubank_sdk/auth.rb', line 43 def authenticate_with_certificate(password) token_url = @api_routes.entrypoint(path: :app, entrypoint: :token) response = ssl_connection.post(token_url, token_payload(password)) response_hash = Client.get_body(response) @refresh_token, @refresh_before, @access_token = response_hash.values_at(:refresh_token, :refresh_before, :access_token) update_api_routes(response_hash[:_links]) end |
#certificate ⇒ NubankSdk::Certificate
Return the instance of user certificate
33 34 35 |
# File 'lib/nubank_sdk/auth.rb', line 33 def certificate @certificate ||= Certificate.new(@cpf) end |
#exchange_certs(email_code, password, custom_encryption = nil) ⇒ File
Verify communication with the nubank api
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nubank_sdk/auth.rb', line 74 def exchange_certs(email_code, password, custom_encryption = nil) = custom_encryption || @encrypted_code || '' raise Errors::InvalidEncryptedCode if .empty? new_payload = payload(password) .merge({ code: email_code, 'encrypted-code': }) response = default_connection.post(@gen_certificate_path, new_payload) response_data = Client.get_body(response) certificate.process_decoded(@p_key, response_data[:certificate]) end |
#request_email_code(password) ⇒ String
Request to nubank api to generate a new certificate
61 62 63 64 65 66 67 68 |
# File 'lib/nubank_sdk/auth.rb', line 61 def request_email_code(password) response = default_connection.post(@gen_certificate_path, payload(password)) response_parsed = parse_authenticate_headers(response.headers['WWW-Authenticate']) @encrypted_code = response_parsed[:device_authorization_encrypted_code] response_parsed end |