Access Tokens and Other Square Credentials

Learn about the different types of access tokens and other credentials used to identify, authenticate, or authorize an application for Square development.

Link to section

Overview

Access tokens are credentials that allow applications to securely interact with Square APIs. An access token authenticates your application and authorizes access to resources (such as customers, orders, and payments) in a Square account. Proper credential management and storage is critical for maintaining security.

Link to section

Access token types

You must provide a valid access token when using Square APIs to access resources in your own Square account or other Square accounts.

There are two types of access token:

  • Personal access token - Provides unrestricted Square API access to resources in a Square account. For example, you can use your own personal access token in Square API calls to perform any activity on any resource in your Square account.
  • OAuth access token - Provides authenticated and scoped Square API access to resources in a Square account. Applications use OAuth access tokens in Square API calls to access resources on behalf of account owners. For example, when Square sellers sign up to use an application, they grant the specific permissions (scopes) that the application needs to perform some activity on their account resources.
Link to section

Get a personal access token

Each application you create in the Developer Console provides a personal access token for testing in the production environment and a separate Sandbox access token for testing in the Square Sandbox. These tokens grant full access to the resources in your own Square account.

  1. Sign in to the Developer Console and open an application. If needed, follow the steps in Get Started to create a Square account and an application.

  2. In the left pane, choose Credentials.

  3. Get your production or Sandbox access token:

    1. At the top of the page, choose Production.
    2. In the Production Access token box, choose Show and copy your token.

The following animation shows how to copy your Sandbox access token from the Credentials page in Sandbox mode.

An animation showing the process for getting the Sandbox access token from the Developer Dashboard.

Did you know?

When you're signed in to API Explorer, the access tokens associated with your account are available in the Access token dropdown.

The following guidelines apply to protecting personal access tokens:

  • Don't hardcode access tokens in your code. Consult relevant documentation to find best practices for securely storing credentials, including framework-specific considerations (for example, encrypted credentials for Ruby on Rail) and platform-specific considerations (web or mobile applications). One option might be to use your cloud provider's secrets manager, such as AWS Secrets Manager, Google Cloud Secret Manager, or Azure Key Vault.

  • Don't share access tokens. A personal access token can be used to impersonate the account owner and gain full access to account resources. For example, if you paste a cURL code snippet when debugging an issue with Square support or on community forums, make sure to redact the access token used in the Authorization header.

Link to section

Get an OAuth access token

The process of getting an OAuth access token depends on whether the token is used for an in-production application or for testing in the Square Sandbox during development.

In-production applications start the OAuth flow by sending each seller to the Square Authorize endpoint. On successful flow completion, Square returns an OAuth access token to your application.

The OAuth flow includes the following high-level stages:

Stage 1: AuthorizationStage 2: CallbackStage 3: Token request
Using an authorization URL, your application sends the seller to the Square authorization page where they can sign in to Square and grant the permissions you requested.Square redirects the seller to the redirect URL that you registered for your application and includes an authorization code in the code query parameter.Your application calls ObtainToken and sends the authorization code, your application ID, and other fields. Square returns an OAuth access token and refresh token.

Store the OAuth access token and refresh token in a secure storage solution. Don't expose them in client-side code or version control systems. You must refresh OAuth access tokens periodically before they expire. For more information, see OAuth API and OAuth Best Practices.

Note

When you're ready to test the code flow in your application, see OAuth Walkthrough: Test Authorization with a Web Server. When your application is ready for production, see Move OAuth from the Sandbox to Production.

Link to section

Use an access token in your code

Access tokens are sent as bearer tokens in the Authorization header of Square API requests.

  • Production requests use the https://connect.squareup.com/v2 base URL with an access token that's valid for the production environment, as shown in the following cURL request:

    curl https://connect.squareup.com/v2/locations \ -H 'Square-Version: 2024-07-17' \ -H 'Authorization: Bearer {PRODUCTION_ACCESS_TOKEN}' \ -H 'Content-Type: application/json'
  • Sandbox requests use the https://connect.squareupsandbox.com/v2 base URL with an access token that's valid for the Sandbox environment, as shown in the following cURL request:

    curl https://connect.squareupsandbox.com/v2/locations \ -H 'Square-Version: 2024-07-17' \ -H 'Authorization: Bearer {SANDBOX_ACCESS_TOKEN}' \ -H 'Content-Type: application/json'

Using the wrong access token for the production or Sandbox environment results in an AUTHENTICATION_ERROR error with the UNAUTHORIZED error code.

Link to section

Using access tokens with Square SDKs

When using a backend Square SDK, the client is initialized with an access token and target environment, as shown in the following PHP SDK snippet:

$client = SquareClientBuilder::init() ->bearerAuthCredentials( BearerAuthCredentialsBuilder::init( $_ENV['SANDBOX_ACCESS_TOKEN'] ) ) ->environment(Environment::SANDBOX) ->build();

For more information, see the following:

Link to section

Credential types

The following table lists the access tokens and other credentials used for Square development. Credential use is dependent on your development scenario.

Credential TypeDescriptionUseObtained from
Application IDIdentificationRandom, unique ID assigned by SquareIdentifies your application in select Square API and SDK calls against the production environment. Also called a client ID.Developer Console Credentials application page
OAuth access tokenAuthorizationScoped access tokenGrants seller-scoped and limited access to production resources in a Square account by asking an authenticated user for explicit permissions.Programmatically using the OAuth API
OAuth refresh tokenAuthorizationSpecial-purpose tokenUsed to obtain a new access token when the current one expires.Programmatically using the OAuth API
Application secretAuthenticationOAuth authentication credentialVerifies the identity of your application in OAuth API requests to get or refresh an OAuth access token. Also called a client secret.Developer Console OAuth application page
Personal access tokenAuthorizationFull-access (unscoped) access tokenGrants unrestricted access to production resources in the corresponding Square account. Also called a production access token.Developer Console Credentials application page
Repository passwordAuthorizationRandom, unique ID assigned by SquareGrants your development environment access to the remote repositories that serve Reader SDK binariesDeveloper Console Reader SDK application page
Sandbox application IDIdentificationRandom, unique ID assigned by SquareIdentifies your application in select Square API and SDK calls against the Sandbox environment. Also called a Sandbox client ID.Developer Console Credentials application page
Sandbox access tokenAuthorizationFull-access (unscoped) access tokenGrants unrestricted access to Sandbox resources in the corresponding Square account.Developer Console Credentials application page
Sandbox OAuth access tokenAuthorizationScoped access token for a Sandbox accountGrants scoped access to resources for a Sandbox application/account pair based on a specified set of permissions.Developer Console OAuth application page or Sandbox test accounts page
Sandbox OAuth refresh tokenAuthorizationSpecial-purpose tokenUsed to obtain a new access token when the current one expires.Developer Console OAuth application page
Location IDN/ARandom, unique ID assigned by SquareNot a type of credential, but required for many Square API requests.Developer Console Locations application page or programmatically using the Locations API or Merchants API
Link to section

See also