Skip to content

Latest commit

 

History

History
252 lines (173 loc) · 7.49 KB

o-auth.md

File metadata and controls

252 lines (173 loc) · 7.49 KB

O Auth

o_auth_api = client.o_auth

Class Name

OAuthApi

Methods

Renew Token

This endpoint is deprecated.

RenewToken is deprecated. For information about refreshing OAuth access tokens, see Migrate from Renew to Refresh OAuth Tokens.

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.

ℹ️ Note This endpoint does not require authentication.

def renew_token(self,
               client_id,
               body,
               authorization)

Parameters

Parameter Type Tags Description
client_id str Template, Required Your application ID, which is available on the OAuth page in the Developer Dashboard.
body Renew Token Request Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.
authorization str Header, Required Client APPLICATION_SECRET

Response Type

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Renew Token Response.

Example Usage

client_id = 'client_id8'

body = {
    'access_token': 'ACCESS_TOKEN'
}

authorization = 'Client CLIENT_SECRET'

result = o_auth_api.renew_token(
    client_id,
    body,
    authorization
)
print(result)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)

Revoke Token

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.

ℹ️ Note This endpoint does not require authentication.

def revoke_token(self,
                body,
                authorization)

Parameters

Parameter Type Tags Description
body Revoke Token Request Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.
authorization str Header, Required Client APPLICATION_SECRET

Response Type

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Revoke Token Response.

Example Usage

body = {
    'client_id': 'CLIENT_ID',
    'access_token': 'ACCESS_TOKEN'
}

authorization = 'Client CLIENT_SECRET'

result = o_auth_api.revoke_token(
    body,
    authorization
)
print(result)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)

Obtain Token

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're 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.

ℹ️ Note This endpoint does not require authentication.

def obtain_token(self,
                body)

Parameters

Parameter Type Tags Description
body Obtain Token Request Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Obtain Token Response.

Example Usage

body = {
    'client_id': 'APPLICATION_ID',
    'grant_type': 'authorization_code',
    'client_secret': 'APPLICATION_SECRET',
    'code': 'CODE_FROM_AUTHORIZE'
}

result = o_auth_api.obtain_token(body)
print(result)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)

Retrieve Token Status

Returns information about an OAuth access token or an application’s 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.

If the access token is expired or not a valid access token, the endpoint returns an UNAUTHORIZED error.

ℹ️ Note This endpoint does not require authentication.

def retrieve_token_status(self,
                         authorization)

Parameters

Parameter Type Tags Description
authorization str Header, Required Client APPLICATION_SECRET

Response Type

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Retrieve Token Status Response.

Example Usage

authorization = 'Client CLIENT_SECRET'

result = o_auth_api.retrieve_token_status(authorization)
print(result)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)