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 type | Canonical flow | Where to start |
|---|---|---|
| SECOND_PARTY | client_credentials (server-to-server, no user click) | Client Credentials Flow |
| THIRD_PARTY | authorization_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 type | Client type | Grant | Where to start |
|---|---|---|---|
| SECOND_PARTY | CONFIDENTIAL | client_credentials | Client Credentials Flow |
| SECOND_PARTY | CONFIDENTIAL | authorization_code + PKCE (uncommon — only if you have a user-attached UI) | PKCE Authorization Code Flow |
| THIRD_PARTY | PUBLIC | authorization_code + PKCE + consent | PKCE Authorization Code Flow → Business Consent |
| THIRD_PARTY | CONFIDENTIAL | authorization_code + PKCE + consent (secret on token request) | PKCE Authorization Code Flow → Business Consent |
| THIRD_PARTY | any | client_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:
- Click "Connect to Securely" in your app.
- Log in at
auth.securely.io. - Pick which of their businesses to give you access to.
- Return to your app with an authorization code.
- 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:
- Use the refresh token to get a new one (Access Tokens and Refresh Rotation).
- Or re-run
client_credentialsif that's how you originally got it.
Refresh tokens are one-time useEvery successful refresh returns a new refresh token and invalidates the previous one. Always replace your stored token. See Access Tokens and Refresh Rotation.
Updated 5 months ago
What’s Next
The PKCE Authorization Code Flow — for third-party.
Client Credentials Flow — for second-party.
