Class: Mercadopago::OAuth
- Defined in:
- lib/mercadopago/resources/oauth.rb
Overview
Manages the OAuth 2.0 authorization code flow.
Use this resource when your application needs to operate on behalf of other MercadoPago sellers (marketplace or platform scenarios). The flow involves redirecting the seller to the authorization URL, receiving an authorization code, and exchanging it for access and refresh tokens.
Instance Method Summary collapse
-
#create(oauth_data, request_options: nil) ⇒ Hash{Symbol => Object}
Exchanges an authorization code for an access token.
-
#get_authorization_url(app_id, redirect_uri, random_id) ⇒ String
Builds the MercadoPago authorization URL for the OAuth flow.
-
#refresh(oauth_data, request_options: nil) ⇒ Hash{Symbol => Object}
Refreshes an expired access token.
Methods inherited from MPBase
#_check_headers, #_check_request_options, #_delete, #_get, #_post, #_put, #initialize
Constructor Details
This class inherits a constructor from Mercadopago::MPBase
Instance Method Details
#create(oauth_data, request_options: nil) ⇒ Hash{Symbol => Object}
Exchanges an authorization code for an access token.
Call this after receiving the code parameter in your redirect_uri callback. The returned access token can be used to make API requests on behalf of the authorizing seller.
57 58 59 60 61 |
# File 'lib/mercadopago/resources/oauth.rb', line 57 def create(oauth_data, request_options: nil) raise TypeError, 'Param oauth_data must be a Hash' unless oauth_data.is_a?(Hash) _post(uri: '/oauth/token', data: oauth_data, request_options: ) end |
#get_authorization_url(app_id, redirect_uri, random_id) ⇒ String
Builds the MercadoPago authorization URL for the OAuth flow.
Redirect the seller to this URL to start the authorization process. After granting permission, MercadoPago redirects back to redirect_uri with a code query parameter.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mercadopago/resources/oauth.rb', line 31 def (app_id, redirect_uri, random_id) params = URI.encode_www_form( client_id: app_id, response_type: 'code', platform_id: 'mp', state: random_id, redirect_uri: redirect_uri ) "#{AUTH_URL}?#{params}" end |
#refresh(oauth_data, request_options: nil) ⇒ Hash{Symbol => Object}
Refreshes an expired access token.
Use this to extend the seller’s session without requiring them to re-authorize. The refresh_token is obtained from the initial #create response.
77 78 79 80 81 |
# File 'lib/mercadopago/resources/oauth.rb', line 77 def refresh(oauth_data, request_options: nil) raise TypeError, 'Param oauth_data must be a Hash' unless oauth_data.is_a?(Hash) _post(uri: '/oauth/token', data: oauth_data, request_options: ) end |