Class: NubankSdk::Auth
- Inherits:
-
Object
- Object
- NubankSdk::Auth
- Defined in:
- lib/nubank_sdk/auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#refresh_before ⇒ Object
readonly
Returns the value of attribute refresh_before.
-
#refresh_token ⇒ Object
readonly
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) ⇒ 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
12 13 14 15 16 17 18 |
# File 'lib/nubank_sdk/auth.rb', line 12 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 || NubankSdk::ApiRoutes.new @connection_adapter = connection_adapter end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/nubank_sdk/auth.rb', line 3 def access_token @access_token end |
#refresh_before ⇒ Object (readonly)
Returns the value of attribute refresh_before.
3 4 5 |
# File 'lib/nubank_sdk/auth.rb', line 3 def refresh_before @refresh_before end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
3 4 5 |
# File 'lib/nubank_sdk/auth.rb', line 3 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
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nubank_sdk/auth.rb', line 34 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 = response_hash[:refresh_token] @refresh_before = response_hash[:refresh_before] @access_token = response_hash[:access_token] update_api_routes(response_hash[:_links]) end |
#certificate ⇒ NubankSdk::Certificate
Return the instance of user certificate
24 25 26 |
# File 'lib/nubank_sdk/auth.rb', line 24 def certificate @certificate ||= NubankSdk::Certificate.new(@cpf) end |
#exchange_certs(email_code, password) ⇒ File
Verify communication with the nubank api
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nubank_sdk/auth.rb', line 66 def exchange_certs(email_code, password) response = default_connection.post(@gen_certificate_path, payload(password).merge({ code: email_code, 'encrypted-code': @encrypted_code }) ) response_data = Client.get_body(response) certificate.process_decoded(key, response_data[:certificate]) end |
#request_email_code(password) ⇒ String
Request to nubank api to generate a new certificate
53 54 55 56 57 58 59 60 |
# File 'lib/nubank_sdk/auth.rb', line 53 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[:sent_to] end |