Class: Square::OAuth::Client
- Inherits:
-
Object
- Object
- Square::OAuth::Client
- Defined in:
- lib/square/o_auth/client.rb
Instance Method Summary collapse
- #authorize(request_options: {}, **_params) ⇒ untyped
- #initialize(client:) ⇒ Square::OAuth::Client constructor
-
#obtain_token(request_options: {}, **params) ⇒ Square::Types::ObtainTokenResponse
Returns an OAuth access token and refresh token using the ‘authorization_code` or `refresh_token` grant type.
-
#retrieve_token_status(request_options: {}, **_params) ⇒ Square::Types::RetrieveTokenStatusResponse
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(request_options: {}, **params) ⇒ Square::Types::RevokeTokenResponse
Revokes an access token generated with the OAuth flow.
Constructor Details
#initialize(client:) ⇒ Square::OAuth::Client
7 8 9 |
# File 'lib/square/o_auth/client.rb', line 7 def initialize(client:) @client = client end |
Instance Method Details
#authorize(request_options: {}, **_params) ⇒ untyped
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/square/o_auth/client.rb', line 111 def (request_options: {}, **_params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "oauth2/authorize" ) _response = @client.send(_request) return if _response.code >= "200" && _response.code < "300" raise _response.body end |
#obtain_token(request_options: {}, **params) ⇒ Square::Types::ObtainTokenResponse
Returns an OAuth access token and refresh token using the ‘authorization_code` or `refresh_token` grant type.
When ‘grant_type` is `authorization_code`:
-
With the [code flow](developer.squareup.com/docs/oauth-api/overview#code-flow),
provide ‘code`, `client_id`, and `client_secret`.
-
With the [PKCE flow](developer.squareup.com/docs/oauth-api/overview#pkce-flow),
provide ‘code`, `client_id`, and `code_verifier`.
When ‘grant_type` is `refresh_token`:
-
With the code flow, provide ‘refresh_token`, `client_id`, and `client_secret`.
The response returns the same refresh token provided in the request.
-
With the PKCE flow, provide ‘refresh_token` and `client_id`. The response returns
a new refresh token.
You can use the ‘scopes` parameter to limit the set of permissions authorized by the access token. You can use the `short_lived` parameter to create an access token that expires in 24 hours.
Important: OAuth tokens should be encrypted and stored on a secure server. Application clients should never interact directly with OAuth tokens.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/square/o_auth/client.rb', line 65 def obtain_token(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "oauth2/token", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::ObtainTokenResponse.load(_response.body) end raise _response.body end |
#retrieve_token_status(request_options: {}, **_params) ⇒ Square::Types::RetrieveTokenStatusResponse
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.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/square/o_auth/client.rb', line 96 def retrieve_token_status(request_options: {}, **_params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "oauth2/token/status" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::RetrieveTokenStatusResponse.load(_response.body) end raise _response.body end |
#revoke_token(request_options: {}, **params) ⇒ Square::Types::RevokeTokenResponse
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.
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 in the Developer Dashboard.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/square/o_auth/client.rb', line 27 def revoke_token(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "oauth2/revoke", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::RevokeTokenResponse.load(_response.body) end raise _response.body end |