Class: Square::OAuthApi

Inherits:
BaseApi show all
Defined in:
lib/square/api/o_auth_api.rb

Overview

OAuthApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

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.

Parameters:

  • body (ObtainTokenRequest)

    Required parameter: An object containing

Returns:

  • (ObtainTokenResponse Hash)

    response from the API call



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/square/api/o_auth_api.rb', line 114

def obtain_token(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/oauth2/token',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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

Parameters:

  • client_id (String)

    Required parameter: Your application ID, which

  • body (RenewTokenRequest)

    Required parameter: An object containing

  • authorization (String)

    Required parameter: Client

Returns:

  • (RenewTokenResponse Hash)

    response from the API call



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/square/api/o_auth_api.rb', line 34

def renew_token(client_id:,
                body:,
                authorization:)
  warn 'Endpoint renew_token in OAuthApi is deprecated'
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/oauth2/clients/{client_id}/access-token/renew',
                                 'default')
               .template_param(new_parameter(client_id, key: 'client_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter(authorization, key: 'Authorization'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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

Parameters:

  • authorization (String)

    Required parameter: Client

Returns:

  • (RetrieveTokenStatusResponse Hash)

    response from the API call



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/square/api/o_auth_api.rb', line 150

def retrieve_token_status(authorization:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/oauth2/token/status',
                                 'default')
               .header_param(new_parameter(authorization, key: 'Authorization'))
               .header_param(new_parameter('application/json', key: 'accept')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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

Parameters:

  • body (RevokeTokenRequest)

    Required parameter: An object containing

  • authorization (String)

    Required parameter: Client

Returns:

  • (RevokeTokenResponse Hash)

    response from the API call



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/square/api/o_auth_api.rb', line 76

def revoke_token(body:,
                 authorization:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/oauth2/revoke',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter(authorization, key: 'Authorization'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end