Choosing Your OAuth Flow

Two questions, one decision tree — pick the right flow before you write any code.


Choosing Your OAuth Flow

Securely Connect supports three grant types: authorization_code (with PKCE), refresh_token, and client_credentials. Picking the right one comes down to your party type. This guide gives you the decision and points to the exact starting page.

One question

Did one specific business generate these keys for you (second-party), or did you register one set of keys to serve many businesses (third-party)?

That single question almost always decides the flow.

Party typeCanonical flowWhere to start
SECOND_PARTYclient_credentials (server-to-server, no user click)Client Credentials Flow
THIRD_PARTYauthorization_code + PKCE + consent (user picks a business)The PKCE Authorization Code Flow → Business Consent

That's it for the common cases. If you're not sure which you are, re-read Second-Party vs Third-Party.

Full decision table

For completeness — including the less common combinations:

Party typeClient typeGrantWhere to start
SECOND_PARTYCONFIDENTIALclient_credentialsClient Credentials Flow
SECOND_PARTYCONFIDENTIALauthorization_code + PKCE (uncommon — only if you have a user-attached UI)PKCE Authorization Code Flow
THIRD_PARTYPUBLICauthorization_code + PKCE + consentPKCE Authorization Code Flow → Business Consent
THIRD_PARTYCONFIDENTIALauthorization_code + PKCE + consent (secret on token request)PKCE Authorization Code Flow → Business Consent
THIRD_PARTYanyclient_credentials✗ Not allowed

In words

"A business generated keys for me to integrate with their Securely account"

You're SECOND_PARTY. Use client_credentials from your backend. The keys are already scoped to that business; every token you mint inherits the scope. No user is needed because the business consented when they handed you the keys.

If a different business wants the same integration, they'll generate their own keys. Manage credentials per business in a key vault.

"I'm building an app that many businesses will sign up for"

You're THIRD_PARTY. Use PKCE + consent. Your end user will:

  1. Click "Connect to Securely" in your app.
  2. Log in at auth.securely.io.
  3. Pick which of their businesses to give you access to.
  4. Return to your app with an authorization code.
  5. Your app exchanges the code (plus its code_verifier) for an access token and a refresh token.

The access token is scoped to the business the user chose.

Once you have tokens

Regardless of how you obtained the access token, the call pattern to the resource API is the same:

curl https://api.securely.io/v2/merchants/123/payment-links \
  -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..."

The access token's lifetime is short (one hour by default). When it expires, you either:

📘

Refresh tokens are one-time use

Every successful refresh returns a new refresh token and invalidates the previous one. Always replace your stored token. See Access Tokens and Refresh Rotation.



What’s Next

The PKCE Authorization Code Flow — for third-party.
Client Credentials Flow — for second-party.

Did this page help you?