Class: Square::OAuthApi
Overview
OAuthApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#initialize(config, http_call_back: nil) ⇒ OAuthApi
constructor
A new instance of OAuthApi.
-
#obtain_token(body:) ⇒ ObtainTokenResponse Hash
Returns an OAuth access token and a refresh token unless the `short_lived` parameter is set to `true`, in which case the endpoint returns only an access token.
-
#renew_token(client_id:, body:, authorization:) ⇒ RenewTokenResponse Hash
`RenewToken` is deprecated.
-
#retrieve_token_status(authorization:) ⇒ RetrieveTokenStatusResponse Hash
Returns information about an [OAuth access token](developer.squareup.com/docs/build-basics/access-tokens#get- an-oauth-access-token) or an application’s [personal access token](developer.squareup.com/docs/build-basics/access-tokens#get- a-personal-access-token).
-
#revoke_token(body:, authorization:) ⇒ RevokeTokenResponse Hash
Revokes an access token generated with the OAuth flow.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters, #validate_parameters_types
Constructor Details
#initialize(config, http_call_back: nil) ⇒ OAuthApi
Returns a new instance of OAuthApi.
4 5 6 |
# File 'lib/square/api/o_auth_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#obtain_token(body:) ⇒ ObtainTokenResponse Hash
Returns an OAuth access token and a refresh token unless the `short_lived` parameter is set to `true`, in which case the endpoint returns only an access token. The `grant_type` parameter specifies the type of OAuth request. If `grant_type` is `authorization_code`, you must include the authorization code you received when a seller granted you authorization. If `grant_type` is `refresh_token`, you must provide a valid refresh token. If you are using an old version of the Square APIs (prior to March 13, 2019), `grant_type` can be `migration_token` and you must provide a valid migration token. You can use the `scopes` parameter to limit the set of permissions granted to the access token and refresh token. You can use the `short_lived` parameter to create an access token that expires in 24 hours. Note: OAuth tokens should be encrypted and stored on a secure server. Application clients should never interact directly with OAuth tokens. the fields to POST for the request. See the corresponding object definition for field details.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/square/api/o_auth_api.rb', line 144 def obtain_token(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/oauth2/token' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#renew_token(client_id:, body:, authorization:) ⇒ RenewTokenResponse Hash
`RenewToken` is deprecated. For information about refreshing OAuth access tokens, see [Migrate from Renew to Refresh OAuth Tokens](developer.squareup.com/docs/oauth-api/migrate-to-refresh-t okens). Renews an OAuth access token before it expires. OAuth access tokens besides your application's personal access token expire after 30 days. You can also renew expired tokens within 15 days of their expiration. You cannot renew an access token that has been expired for more than 15 days. Instead, the associated user must recomplete the OAuth flow from the beginning. Important: The `Authorization` header for this endpoint must have the following format: “` Authorization: Client APPLICATION_SECRET “` Replace `APPLICATION_SECRET` with the application secret on the Credentials page in the [Developer Dashboard](developer.squareup.com/apps). is available in the OAuth page in the [Developer Dashboard](developer.squareup.com/apps). the fields to POST for the request. See the corresponding object definition for field details. APPLICATION_SECRET
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/square/api/o_auth_api.rb', line 38 def renew_token(client_id:, body:, authorization:) warn 'Endpoint renew_token in OAuthApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/oauth2/clients/{client_id}/access-token/renew' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'client_id' => { 'value' => client_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#retrieve_token_status(authorization:) ⇒ RetrieveTokenStatusResponse Hash
Returns information about an [OAuth access token](developer.squareup.com/docs/build-basics/access-tokens#get- an-oauth-access-token) or an application’s [personal access token](developer.squareup.com/docs/build-basics/access-tokens#get- a-personal-access-token). Add the access token to the Authorization header of the request. Important: The `Authorization` header you provide to this endpoint must have the following format: “` Authorization: Bearer ACCESS_TOKEN “` where `ACCESS_TOKEN` is a [valid production authorization credential](developer.squareup.com/docs/build-basics/access-tokens ). If the access token is expired or not a valid access token, the endpoint returns an `UNAUTHORIZED` error. APPLICATION_SECRET
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/square/api/o_auth_api.rb', line 192 def retrieve_token_status(authorization:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/oauth2/token/status' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Authorization' => } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers ) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#revoke_token(body:, authorization:) ⇒ RevokeTokenResponse Hash
Revokes an access token generated with the OAuth flow. If an account has more than one OAuth access token for your application, this endpoint revokes all of them, regardless of which token you specify. When an OAuth access token is revoked, all of the active subscriptions associated with that OAuth token are canceled immediately. Important: The `Authorization` header for this endpoint must have the following format: “` Authorization: Client APPLICATION_SECRET “` Replace `APPLICATION_SECRET` with the application secret on the OAuth page for your application on the Developer Dashboard. the fields to POST for the request. See the corresponding object definition for field details. APPLICATION_SECRET
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/square/api/o_auth_api.rb', line 94 def revoke_token(body:, authorization:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/oauth2/revoke' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |