Module: MercadoPago::Authentication

Defined in:
lib/mercadopago/authentication.rb

Constant Summary collapse

CONTENT_HEADERS =
{
  content_type: 'application/x-www-form-urlencoded',
  accept: 'application/json'
}.freeze

Class Method Summary collapse

Class Method Details

.access_token(client_id, client_secret) ⇒ Object

Receives the client credentials and makes a request to oAuth API. On success, returns a hash with the access data; on failure, returns nil.

To get your client credentials, access: www.mercadopago.com/mlb/ferramentas/aplicacoes

  • client_id

  • client_secret



19
20
21
22
23
24
25
26
# File 'lib/mercadopago/authentication.rb', line 19

def self.access_token(client_id, client_secret)
  payload = {
    grant_type: 'client_credentials',
    client_id: client_id,
    client_secret: client_secret }

  MercadoPago::Request.wrap_post('/oauth/token', payload, CONTENT_HEADERS)
end

.refresh_access_token(client_id, client_secret, refresh_token) ⇒ Object

Receives the client credentials and a valid refresh token and requests a new access token.

  • client_id

  • client_secret

  • refresh_token



35
36
37
38
39
40
41
42
43
# File 'lib/mercadopago/authentication.rb', line 35

def self.refresh_access_token(client_id, client_secret, refresh_token)
  payload = {
    grant_type: 'refresh_token',
    client_id: client_id,
    client_secret: client_secret,
    refresh_token: refresh_token }

  MercadoPago::Request.wrap_post('/oauth/token', payload, CONTENT_HEADERS)
end