{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-products/direct-integration/guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition","tabs","tab","img"]},"type":"markdown"},"seo":{"title":"OAuth integration","description":"Adfin's APIs for invoicing, payments and credit contol.","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"oauth-integration","__idx":0},"children":["OAuth integration"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Adfin uses OAuth 2.0 for secure authentication and authorisation. Before you can make requests to the Adfin API, you must get an access token."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Prerequisites"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Your Adfin Integration Manager will share encrypted app credentials containing your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_secret"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"oauth-20-flows-supported","__idx":1},"children":["OAuth 2.0 flows supported"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Client credentials flow"]}," (for platform-to-platform communication)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Authorization code flow"]}," (for biller authorisation on behalf of your platform)"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"authentication-in-adfin","__idx":2},"children":["Authentication in Adfin"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You must supply your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_secret"]}," either in the HTTP Basic Auth header or as form parameters. If you include them in both places, they must match exactly."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"how-to-use-header-authentication","__idx":3},"children":["How to use header authentication"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Base64 authentication"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The authorization header string is ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Basic Base64Encode(client_id:client_secret)"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example, for client ID ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xyz123clientid"]}," and client secret ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["secret987654321"]},", first Base64-encode the string:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"xyz123clientid:secret987654321\n→ eHl6MTIzY2xpZW50aWQ6c2VjcmV0OTg3NjU0MzIx\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Then your header becomes:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"Authorization: Basic eHl6MTIzY2xpZW50aWQ6c2VjcmV0OTg3NjU0MzIx\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"request-example","__idx":4},"children":["Request example"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","data-title":"Request","header":{"title":"Request","controls":{"copy":{}}},"source":"curl -X POST \"https://api.staging.adfin.com/api/oauth2/token\" \\\n-H \"Authorization: Basic $(echo -n 'YOUR_ID:YOUR_SECRET' | base64)\" \\\n-H \"Content-Type: application/x-www-form-urlencoded\" \\\n-d 'grant_type=client_credentials'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"client-credentials-flow-platform-token","__idx":5},"children":["Client credentials flow (platform token)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use this flow when your platform must access Adfin resources directly."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","data-title":"Request","header":{"title":"Request","controls":{"copy":{}}},"source":"curl -X POST \"https://api.staging.adfin.com/api/oauth2/token\" \\\n-H \"Content-Type: application/x-www-form-urlencoded\" \\\n-d 'grant_type=client_credentials&client_id={your_client_id}&client_secret={your_client_secret}'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Body"]},":"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["grant_type"]}," to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_credentials"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{your_client_id}"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{your_client_secret}"]}," with your credentials."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the request is successful, Adfin responds with an access token:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","data-title":"Response","header":{"title":"Response","controls":{"copy":{}}},"source":"{\n  \"access_token\": \"your_access_token\",\n  \"token_type\": \"Bearer\",\n  \"expires_in\": 3600\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"authorization-code-flow","__idx":6},"children":["Authorization code flow"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This flow allows your platform to request an access token after receiving an authorization code from a biller's login session."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"1. Initial redirect","disable":false},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The biller is prompted to log in to their account."]},{"$$mdtype":"Tag","name":"Image","attributes":{"src":"/assets/login_page.f83d1d36db2ece2692dcdaf692ddec72b691c0897fd3cce8ab92d4b68af68527.cfa4363d.png","alt":"Adfin login page","withLightbox":true},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"2. Login","disable":false},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Adfin supports multiple accounts for a biller. The biller must also log in to their account at this step."]},{"$$mdtype":"Tag","name":"Image","attributes":{"src":"/assets/login_page_god_mode.f44de0d39f1cac4ba969a372747686523147b5767da6da17be23d52cdfd68d88.cfa4363d.png","alt":"Account selection","withLightbox":true},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"3. Authorise screen","disable":false},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The biller authorises your application. This screen shows the details of your app, such as its name."]},{"$$mdtype":"Tag","name":"Image","attributes":{"src":"/assets/authorise_app.69c8e2ecede7caf42431772cf296971c7a46efcf9bdded5c51c012fb3e775036.cfa4363d.png","alt":"Authorise screen","withLightbox":true},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"step-1-redirect-the-biller-to-adfins-authorisation-page","__idx":7},"children":["Step 1: Redirect the biller to Adfin's authorisation page"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use the hosts for the environment your credentials belong to. The biller login runs on the Adfin Console. Every other call goes to the API."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Step"},"children":["Step"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Staging"},"children":["Staging"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Production"},"children":["Production"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Biller login and consent"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://staging.adfin.com/auth/login"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://console.adfin.com/auth/login"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Token and refresh"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.staging.adfin.com/api/oauth2/token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.adfin.com/api/oauth2/token"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Revoke"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.staging.adfin.com/api/oauth2/revoke"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.adfin.com/api/oauth2/revoke"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["API calls"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.staging.adfin.com/api"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.adfin.com/api"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Redirect the biller to Adfin's authorisation page. Construct your unique authorisation URL:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Staging:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"https://staging.adfin.com/auth/login?&client_id={your_client_id}&scope=invoices%20customers&redirect_uri={your_redirect_uri}&state={random_state_value}\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Production:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"https://console.adfin.com/auth/login?&client_id={your_client_id}&scope=invoices%20customers&redirect_uri={your_redirect_uri}&state={random_state_value}\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Login address"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use exactly the login addresses above. Adfin's login page builds its return address from the address it is opened on. If you open it on a different address, such as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["app.adfin.com"]},", the result is a \"Callback URL mismatch\" error, even when your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["redirect_uri"]}," is correct. If your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["redirect_uri"]}," is not registered, the biller sees \"Invalid redirect URI.\" when they approve access."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Properties required for the OAuth redirect"]},":"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"URI property"},"children":["URI property"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}," of your platform, as provisioned by Adfin"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["redirect_uri"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The address Adfin sends the biller to after they grant permission"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["scope"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Use the scopes ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["invoices"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["customers"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["state"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Required. A random value you generate and check on the callback. Without it, a biller who is already signed in to Adfin goes to their dashboard instead of the consent screen"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"step-2-handle-the-callback","__idx":8},"children":["Step 2: Handle the callback"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["After the biller logs in and approves the authorisation, Adfin redirects them to the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["redirect_uri"]}," from ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Step 1"]},". Adfin appends a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["code"]}," to the query string, for example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"https://your-platform.com/callback?code=[your_authorization_code]&state=random_state_value\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"step-3-exchange-the-authorization-code-for-tokens","__idx":9},"children":["Step 3: Exchange the authorization code for tokens"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use this request to exchange the authorization code for an access token and a refresh token."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can use header authentication or form parameter authentication, as described in ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#authentication-in-adfin"},"children":["Authentication in Adfin"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","data-title":"Request","header":{"title":"Request","controls":{"copy":{}}},"source":"curl -X POST \"https://api.staging.adfin.com/api/oauth2/token\" \\\n-H \"Content-Type: application/x-www-form-urlencoded\" \\\n-d 'grant_type=authorization_code&client_id={your_client_id}&client_secret={your_client_secret}&code={authorization_code}&redirect_uri={your_redirect_uri}'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","data-title":"Response","header":{"title":"Response","controls":{"copy":{}}},"source":"{\n  \"access_token\": \"your_access_token\",\n  \"refresh_token\": \"your_refresh_token\",\n  \"expires_in\": 3600,\n  \"token_type\": \"Bearer\"\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Request data"},"children":["Request data"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["grant_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["authorization_code"]}," in this step"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The credentials of your Adfin app"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_secret"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The credentials of your Adfin app"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["code"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The authorization code from step 2"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["redirect_uri"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Must be the same URI used in the initial request"]}]}]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Response data"},"children":["Response data"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["access_token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The access token for the biller"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["refresh_token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The refresh token for the biller's account"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["expires_in"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["How long the access token is valid for, in seconds"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Always ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Bearer"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can now use the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["access_token"]}," to make authorised requests on behalf of the biller, for example to create customers."]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"managing-refresh-tokens","__idx":10},"children":["Managing refresh tokens"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use the refresh token to get a new access token when the current access token expires. This keeps the session active, so the biller does not have to log in again."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"OAuth with refresh token rotation"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Our integration uses OAuth 2.0 with refresh token rotation. This means:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["You must use each newly issued refresh token from then on."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Discard old refresh tokens immediately."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Concurrent requests must not reuse or fall back to expired tokens."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If you send a refresh token that was already used, Adfin can revoke every refresh token on that connection. The biller must then authorise again."]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"using-refresh-tokens","__idx":11},"children":["Using refresh tokens"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use refresh tokens to get new access tokens and new refresh tokens."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","data-title":"Request","header":{"title":"Request","controls":{"copy":{}}},"source":"curl -X POST \"https://api.staging.adfin.com/api/oauth2/token\" \\\n-H \"Content-Type: application/x-www-form-urlencoded\" \\\n-d 'grant_type=refresh_token&client_id={your_client_id}&client_secret={your_client_secret}&refresh_token={your_refresh_token}'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","data-title":"Response","header":{"title":"Response","controls":{"copy":{}}},"source":"{\n  \"access_token\": \"new_access_token\",\n  \"refresh_token\": \"new_refresh_token\",\n  \"expires_in\": 3600,\n  \"token_type\": \"Bearer\"\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Request data"},"children":["Request data"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["grant_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Set to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["refresh_token"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Your platform's ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_secret"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Your platform's ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_secret"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["refresh_token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The refresh token you received during the last token exchange"]}]}]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Response data"},"children":["Response data"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["access_token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The access token for the biller"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["refresh_token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The new refresh token for the biller's account"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["expires_in"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["How long the access token is valid for, in seconds"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Always ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Bearer"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"token-expiry","__idx":12},"children":["Token expiry"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["access_token"]},": Expires after 1 hour."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["refresh_token"]},": Expires if it is not used for 5 days. Every refresh returns a new refresh token with a new 5-day window. A connection can stay active for up to 1 year from when the biller authorised it. After 1 year, the biller must authorise again."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"error-handling","__idx":13},"children":["Error handling"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["401 Unauthorized"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["INVALID_REFRESH_TOKEN"]},"): The refresh token has expired, has been revoked or is not valid. Ask the biller to authorise again with the authorization code flow."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["400 Bad Request"]},": The request format is incorrect, or a required parameter is missing."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"best-practices-for-using-refresh-tokens","__idx":14},"children":["Best practices for using refresh tokens"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Token rotation:"]}," When the response contains a new refresh token, replace the old one in your system."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Scheduled refresh:"]}," Refresh each connection at least once a day, even when there is no activity for that biller. This makes sure that a refresh token is never unused for 5 days."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Token storage:"]}," Store refresh tokens securely, for example encrypted, to protect them from theft."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Expiry handling:"]}," When an access token expires, use the refresh token to get a new one. This prevents login interruptions for the biller."]}]}]},"headings":[{"value":"OAuth integration","id":"oauth-integration","depth":1},{"value":"OAuth 2.0 flows supported","id":"oauth-20-flows-supported","depth":2},{"value":"Authentication in Adfin","id":"authentication-in-adfin","depth":2},{"value":"How to use header authentication","id":"how-to-use-header-authentication","depth":3},{"value":"Request example","id":"request-example","depth":3},{"value":"Client credentials flow (platform token)","id":"client-credentials-flow-platform-token","depth":2},{"value":"Authorization code flow","id":"authorization-code-flow","depth":2},{"value":"Step 1: Redirect the biller to Adfin's authorisation page","id":"step-1-redirect-the-biller-to-adfins-authorisation-page","depth":3},{"value":"Step 2: Handle the callback","id":"step-2-handle-the-callback","depth":3},{"value":"Step 3: Exchange the authorization code for tokens","id":"step-3-exchange-the-authorization-code-for-tokens","depth":3},{"value":"Managing refresh tokens","id":"managing-refresh-tokens","depth":2},{"value":"Using refresh tokens","id":"using-refresh-tokens","depth":3},{"value":"Token expiry","id":"token-expiry","depth":3},{"value":"Error handling","id":"error-handling","depth":3},{"value":"Best practices for using refresh tokens","id":"best-practices-for-using-refresh-tokens","depth":3}],"frontmatter":{"seo":{"title":"OAuth integration"}},"lastModified":"2026-11-10T17:09:57.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/direct-integration/guides/get-started/oauth","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}