Class: Bs2Api::Request::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/bs2_api/request/auth.rb

Constant Summary collapse

SCOPES =

TODO: See which scopes are required.

[
  'saldo',
  'extrato',
  'pagamento',
  'transferencia',
  'cobv.write',
  'cobv.read',
  'comprovante',
  'webhook-mov-conta',
  'aprovacoes',
  'pagamento-tributo',
  'webhook-conclusao-transf',
  'webhook-conclusao-pag',
  'cob.write',
  'cob.read',
  'pix.write',
  'pix.read',
  'dict.write',
  'dict.read',
  'webhook.read',
  'webhook.write',
].freeze

Class Method Summary collapse

Class Method Details

.token(client_id: Bs2Api.configuration.client_id, client_secret: Bs2Api.configuration.client_secret) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bs2_api/request/auth.rb', line 31

def token(
  client_id: Bs2Api.configuration.client_id,
  client_secret: Bs2Api.configuration.client_secret
)
  Bs2Api.configuration.valid?

  response = create_session(client_id, client_secret)

  raise Bs2Api::Errors::Unauthorized, response['error_description'] if response.unauthorized?
  raise Bs2Api::Errors::BadRequest, response['error_description'] if response.bad_request?
  raise Bs2Api::Errors::ServerError, response.body unless response.success?

  response['access_token']
end