Class: ApiBrasil::Services::Platform::AuthService
- Inherits:
-
BaseService
- Object
- BaseService
- ApiBrasil::Services::Platform::AuthService
- 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
Instance Method Summary collapse
-
#change_password(body, options = {}) ⇒ Object
Troca a senha logado:
POST /password/change. -
#login(body, options = {}) ⇒ Object
Autentica com email/senha:
POST /auth/login. -
#logout(options = {}) ⇒ Object
Encerra a sessao:
POST /auth/logout. -
#me(options = {}) ⇒ Object
Perfil atual:
GET /profile/me. -
#password_forgot(body, options = {}) ⇒ Object
Esqueci a senha:
POST /auth/password/forgot. -
#password_resend(body, options = {}) ⇒ Object
Reenvia o codigo de recuperacao:
POST /auth/password/resend. -
#password_reset(body, options = {}) ⇒ Object
Redefine a senha:
POST /auth/password/reset. -
#password_verify_code(body, options = {}) ⇒ Object
Valida o codigo de recuperacao:
POST /auth/password/verify-code. -
#profile(options = {}) ⇒ Object
Perfil completo (com estatisticas):
POST /profile. -
#refresh(options = {}) ⇒ Object
Renova o JWT:
POST /refresh. -
#register(body, options = {}) ⇒ Object
Cria uma conta:
POST /auth/register. -
#register_simple(body, options = {}) ⇒ Object
Cadastro simplificado:
POST /auth/register/simple. -
#send_2fa(body, options = {}) ⇒ Object
Envia o codigo 2FA pelo metodo escolhido:
POST /auth/2fa/send. -
#token_revoke(options = {}) ⇒ Object
Revoga o token atual:
POST /auth/token/revoke. -
#token_rotate(options = {}) ⇒ Object
Rotaciona o token:
POST /auth/token/rotate. -
#two_factor_methods(options = {}) ⇒ Object
Lista os metodos 2FA ativos da conta:
GET /auth/2fa/methods. -
#update_me(body, options = {}) ⇒ Object
Atualiza o perfil:
PUT /profile/me. -
#verification_send(body, options = {}) ⇒ Object
Dispara verificacao de email/celular:
POST /auth/verification/send. -
#verification_verify(body, options = {}) ⇒ Object
Confirma o codigo de verificacao:
POST /auth/verification/verify. -
#verify(options = {}) ⇒ Object
Valida o token atual:
GET /auth/verify. -
#verify_2fa(body, options = {}) ⇒ Object
Conclui o login com o codigo 2FA:
POST /auth/login/verify-2fa.
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.
116 117 118 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 116 def change_password(body, = {}) post("/password/change", body, ) 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.
19 20 21 22 23 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 19 def login(body, = {}) response = post("/auth/login", body, ) store_token(response) response end |
#logout(options = {}) ⇒ Object
Encerra a sessao: POST /auth/logout.
183 184 185 186 187 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 183 def logout( = {}) response = post("/auth/logout", nil, ) http.bearer_token = nil response end |
#me(options = {}) ⇒ Object
Perfil atual: GET /profile/me.
130 131 132 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 130 def me( = {}) get("/profile/me", ) end |
#password_forgot(body, options = {}) ⇒ Object
Esqueci a senha: POST /auth/password/forgot.
85 86 87 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 85 def password_forgot(body, = {}) post("/auth/password/forgot", body, ) end |
#password_resend(body, options = {}) ⇒ Object
Reenvia o codigo de recuperacao: POST /auth/password/resend.
108 109 110 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 108 def password_resend(body, = {}) post("/auth/password/resend", body, ) end |
#password_reset(body, options = {}) ⇒ Object
Redefine a senha: POST /auth/password/reset.
101 102 103 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 101 def password_reset(body, = {}) post("/auth/password/reset", body, ) end |
#password_verify_code(body, options = {}) ⇒ Object
Valida o codigo de recuperacao: POST /auth/password/verify-code.
93 94 95 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 93 def password_verify_code(body, = {}) post("/auth/password/verify-code", body, ) end |
#profile(options = {}) ⇒ Object
Perfil completo (com estatisticas): POST /profile.
123 124 125 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 123 def profile( = {}) post("/profile", nil, ) end |
#refresh(options = {}) ⇒ Object
Renova o JWT: POST /refresh.
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( = {}) response = post("/refresh", nil, ) token = nil if response.is_a?(Hash) = response["authorization"] token = ["token"] if .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.
54 55 56 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 54 def register(body, = {}) post("/auth/register", body, ) end |
#register_simple(body, options = {}) ⇒ Object
Cadastro simplificado: POST /auth/register/simple.
61 62 63 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 61 def register_simple(body, = {}) post("/auth/register/simple", body, ) end |
#send_2fa(body, options = {}) ⇒ Object
Envia o codigo 2FA pelo metodo escolhido: POST /auth/2fa/send.
29 30 31 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 29 def send_2fa(body, = {}) post("/auth/2fa/send", body, ) end |
#token_revoke(options = {}) ⇒ Object
Revoga o token atual: POST /auth/token/revoke.
176 177 178 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 176 def token_revoke( = {}) post("/auth/token/revoke", nil, ) end |
#token_rotate(options = {}) ⇒ Object
Rotaciona o token: POST /auth/token/rotate.
169 170 171 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 169 def token_rotate( = {}) post("/auth/token/rotate", nil, ) end |
#two_factor_methods(options = {}) ⇒ Object
Lista os metodos 2FA ativos da conta: GET /auth/2fa/methods.
46 47 48 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 46 def two_factor_methods( = {}) get("/auth/2fa/methods", ) end |
#update_me(body, options = {}) ⇒ Object
Atualiza o perfil: PUT /profile/me.
137 138 139 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 137 def update_me(body, = {}) put("/profile/me", body, ) end |
#verification_send(body, options = {}) ⇒ Object
Dispara verificacao de email/celular: POST /auth/verification/send.
69 70 71 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 69 def verification_send(body, = {}) post("/auth/verification/send", body, ) end |
#verification_verify(body, options = {}) ⇒ Object
Confirma o codigo de verificacao: POST /auth/verification/verify.
77 78 79 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 77 def verification_verify(body, = {}) post("/auth/verification/verify", body, ) end |
#verify(options = {}) ⇒ Object
Valida o token atual: GET /auth/verify.
144 145 146 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 144 def verify( = {}) get("/auth/verify", ) end |
#verify_2fa(body, options = {}) ⇒ Object
Conclui o login com o codigo 2FA: POST /auth/login/verify-2fa.
37 38 39 40 41 |
# File 'lib/api_brasil/services/platform/auth_service.rb', line 37 def verify_2fa(body, = {}) response = post("/auth/login/verify-2fa", body, ) store_token(response) response end |