Class: ApiBrasil::Services::Platform::AuthService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/api_brasil/services/platform/auth_service.rb

Overview

Autenticacao e conta (/auth/*, /profile*, /password/*).

login e verify_2fa guardam automaticamente o Bearer Token retornado no cliente, deixando as proximas chamadas autenticadas.

Instance Attribute Summary

Attributes inherited from BaseService

#http

Instance Method Summary collapse

Methods inherited from BaseService

#delete, #download, #get, #initialize, #patch, #post, #put

Constructor Details

This class inherits a constructor from ApiBrasil::Services::BaseService

Instance Method Details

#change_password(body, options = {}) ⇒ Object

Troca a senha logado: POST /password/change.

Parameters:

  • body (Hash)

    current_password, password, password_confirmation

Returns:

  • (Object)


116
117
118
# File 'lib/api_brasil/services/platform/auth_service.rb', line 116

def change_password(body, options = {})
  post("/password/change", body, options)
end

#login(body, options = {}) ⇒ Object

Autentica com email/senha: POST /auth/login. Se a conta tiver 2FA, retorna {"requires_2fa" => true, "challenge" => ...} - use send_2fa + verify_2fa para concluir.

Parameters:

  • body (Hash)

    email, password, turnstile_token

Returns:

  • (Object)


19
20
21
22
23
# File 'lib/api_brasil/services/platform/auth_service.rb', line 19

def (body, options = {})
  response = post("/auth/login", body, options)
  store_token(response)
  response
end

#logout(options = {}) ⇒ Object

Encerra a sessao: POST /auth/logout.

Returns:

  • (Object)


183
184
185
186
187
# File 'lib/api_brasil/services/platform/auth_service.rb', line 183

def logout(options = {})
  response = post("/auth/logout", nil, options)
  http.bearer_token = nil
  response
end

#me(options = {}) ⇒ Object

Perfil atual: GET /profile/me.

Returns:

  • (Object)


130
131
132
# File 'lib/api_brasil/services/platform/auth_service.rb', line 130

def me(options = {})
  get("/profile/me", options)
end

#password_forgot(body, options = {}) ⇒ Object

Esqueci a senha: POST /auth/password/forgot.

Parameters:

  • body (Hash)

    identifier, method (email|sms|whatsapp)

Returns:

  • (Object)


85
86
87
# File 'lib/api_brasil/services/platform/auth_service.rb', line 85

def password_forgot(body, options = {})
  post("/auth/password/forgot", body, options)
end

#password_resend(body, options = {}) ⇒ Object

Reenvia o codigo de recuperacao: POST /auth/password/resend.

Returns:

  • (Object)


108
109
110
# File 'lib/api_brasil/services/platform/auth_service.rb', line 108

def password_resend(body, options = {})
  post("/auth/password/resend", body, options)
end

#password_reset(body, options = {}) ⇒ Object

Redefine a senha: POST /auth/password/reset.

Parameters:

  • body (Hash)

    reset_token, password, password_confirmation

Returns:

  • (Object)


101
102
103
# File 'lib/api_brasil/services/platform/auth_service.rb', line 101

def password_reset(body, options = {})
  post("/auth/password/reset", body, options)
end

#password_verify_code(body, options = {}) ⇒ Object

Valida o codigo de recuperacao: POST /auth/password/verify-code.

Parameters:

  • body (Hash)

    identifier, code

Returns:

  • (Object)


93
94
95
# File 'lib/api_brasil/services/platform/auth_service.rb', line 93

def password_verify_code(body, options = {})
  post("/auth/password/verify-code", body, options)
end

#profile(options = {}) ⇒ Object

Perfil completo (com estatisticas): POST /profile.

Returns:

  • (Object)


123
124
125
# File 'lib/api_brasil/services/platform/auth_service.rb', line 123

def profile(options = {})
  post("/profile", nil, options)
end

#refresh(options = {}) ⇒ Object

Renova o JWT: POST /refresh.

Returns:

  • (Object)


151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/api_brasil/services/platform/auth_service.rb', line 151

def refresh(options = {})
  response = post("/refresh", nil, options)

  token = nil
  if response.is_a?(Hash)
    authorization = response["authorization"]
    token = authorization["token"] if authorization.is_a?(Hash)
    token ||= response["token"]
  end

  http.bearer_token = token if token.is_a?(String) && !token.empty?

  response
end

#register(body, options = {}) ⇒ Object

Cria uma conta: POST /auth/register.

Parameters:

  • body (Hash)

    first_name, email, cellphone, password, terms_accepted

Returns:

  • (Object)


54
55
56
# File 'lib/api_brasil/services/platform/auth_service.rb', line 54

def register(body, options = {})
  post("/auth/register", body, options)
end

#register_simple(body, options = {}) ⇒ Object

Cadastro simplificado: POST /auth/register/simple.

Returns:

  • (Object)


61
62
63
# File 'lib/api_brasil/services/platform/auth_service.rb', line 61

def register_simple(body, options = {})
  post("/auth/register/simple", body, options)
end

#send_2fa(body, options = {}) ⇒ Object

Envia o codigo 2FA pelo metodo escolhido: POST /auth/2fa/send.

Parameters:

  • body (Hash)

    challenge, method (email|sms|whatsapp|call)

Returns:

  • (Object)


29
30
31
# File 'lib/api_brasil/services/platform/auth_service.rb', line 29

def send_2fa(body, options = {})
  post("/auth/2fa/send", body, options)
end

#token_revoke(options = {}) ⇒ Object

Revoga o token atual: POST /auth/token/revoke.

Returns:

  • (Object)


176
177
178
# File 'lib/api_brasil/services/platform/auth_service.rb', line 176

def token_revoke(options = {})
  post("/auth/token/revoke", nil, options)
end

#token_rotate(options = {}) ⇒ Object

Rotaciona o token: POST /auth/token/rotate.

Returns:

  • (Object)


169
170
171
# File 'lib/api_brasil/services/platform/auth_service.rb', line 169

def token_rotate(options = {})
  post("/auth/token/rotate", nil, options)
end

#two_factor_methods(options = {}) ⇒ Object

Lista os metodos 2FA ativos da conta: GET /auth/2fa/methods.

Returns:

  • (Object)


46
47
48
# File 'lib/api_brasil/services/platform/auth_service.rb', line 46

def two_factor_methods(options = {})
  get("/auth/2fa/methods", options)
end

#update_me(body, options = {}) ⇒ Object

Atualiza o perfil: PUT /profile/me.

Returns:

  • (Object)


137
138
139
# File 'lib/api_brasil/services/platform/auth_service.rb', line 137

def update_me(body, options = {})
  put("/profile/me", body, options)
end

#verification_send(body, options = {}) ⇒ Object

Dispara verificacao de email/celular: POST /auth/verification/send.

Parameters:

  • body (Hash)

    type (email|cellphone)

Returns:

  • (Object)


69
70
71
# File 'lib/api_brasil/services/platform/auth_service.rb', line 69

def verification_send(body, options = {})
  post("/auth/verification/send", body, options)
end

#verification_verify(body, options = {}) ⇒ Object

Confirma o codigo de verificacao: POST /auth/verification/verify.

Parameters:

  • body (Hash)

    code, type

Returns:

  • (Object)


77
78
79
# File 'lib/api_brasil/services/platform/auth_service.rb', line 77

def verification_verify(body, options = {})
  post("/auth/verification/verify", body, options)
end

#verify(options = {}) ⇒ Object

Valida o token atual: GET /auth/verify.

Returns:

  • (Object)


144
145
146
# File 'lib/api_brasil/services/platform/auth_service.rb', line 144

def verify(options = {})
  get("/auth/verify", options)
end

#verify_2fa(body, options = {}) ⇒ Object

Conclui o login com o codigo 2FA: POST /auth/login/verify-2fa.

Parameters:

  • body (Hash)

    challenge, code

Returns:

  • (Object)


37
38
39
40
41
# File 'lib/api_brasil/services/platform/auth_service.rb', line 37

def verify_2fa(body, options = {})
  response = post("/auth/login/verify-2fa", body, options)
  store_token(response)
  response
end