{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/identity-access-management/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial","admonition"]},"type":"markdown"},"seo":{"title":"OAuth 2.0 access tokens | Sinch","siteUrl":"https://developers.sinch.com","llmstxt":{"title":"Sinch Developer Documentation","description":"LLMs.txt containing a map of all the documentation files for Sinch.","sections":[{"title":"Numbers API","description":"The Numbers API enables you to search for, view, and activate numbers. It's considered a precursor to other APIs in the Sinch product family. The numbers API can be used in tandem with any of our APIs that perform messaging or calling.","includeFiles":["docs/numbers/**/*.md","docs/numbers/**/*.yaml"],"excludeFiles":["docs/numbers/index.md"]},{"title":"Conversation API","description":"Send and receive messages globally on many popular channels with ease and confidence when using Sinch's Conversation API. Conversation API is the preferred API for sending mobile messages on SMS and other social channels with Sinch. It is a simple API with unified error messages, consistent request payloads, and common webhook payloads that are channel-agnostic.","includeFiles":["docs/conversation/**/*.md","docs/conversation/**/*.yaml"],"excludeFiles":["docs/conversation/index.md"]},{"title":"Voice API","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice/**/*.md","docs/voice/**/*.yaml"],"excludeFiles":["docs/voice/index.md"]},{"title":"Verification API","description":"The Verification API is a platform for phone number verification. It consists of the API and different software development kits (the Sinch SDKs) that you integrate with your smartphone or web application and cloud based back-end services. Together they enable SMS, Flashcall, Phone Call and Data verification in your application.","includeFiles":["docs/verification/**/*.md","docs/verification/**/*.yaml"],"excludeFiles":["docs/verification/index.md"]},{"title":"Provisioning API","description":"Provisioning API allows you to programmatically set up your senders, accounts and templates on your favorite messaging platforms on the Conversation API. For now, you can create your first WhatsApp channel through Meta's Embedded sign up, you can configure your first SMS App and configure your webhooks. As development continues, we will be adding the most commonly used channels.","includeFiles":["docs/provisioning-api/**/*.md","docs/provisioning-api/**/*.json"],"excludeFiles":["docs/provisioning-api/index.md"]},{"title":"Elastic SIP Trunking API","description":"With Elastic SIP Trunking you can create and manage your SIP trunks and phone numbers programmatically.","includeFiles":["docs/est/**/*.md","docs/est/**/*.yaml"],"excludeFiles":["docs/est/index.md"]},{"title":"Fax API","description":"Send and receive HIPAA compliant faxes on our modern fax platform using our developer-friendly API.","includeFiles":["docs/fax/**/*.md","docs/fax/**/*.yaml"],"excludeFiles":["docs/fax/index.md"]},{"title":"In-app Voice and Video SDK","description":"The In-app Voice and Video SDK enables you to add voice and video calling capabilities directly into your mobile or web application using the Sinch SDKs.","includeFiles":["docs/in-app-calling/**/*.md"],"excludeFiles":["docs/in-app-calling/index.md"]},{"title":"Number Lookup API","description":"The Number Lookup API is designed to provide in-depth information about phone numbers, helping enterprises enhance their communication strategies and prevent fraud. By identifying the type of phone line (for example, mobile, landline, VoIP) and the associated carrier, the API allows businesses to optimize routing, reduce unnecessary costs, and improve customer engagement.","includeFiles":["docs/number-lookup-api-v2/**/*.md","docs/number-lookup-api-v2/**/*.yaml"],"excludeFiles":["docs/number-lookup-api-v2/index.md"]},{"title":"Functions","description":"Serverless compute for voice and messaging. Deploy your code and Sinch routes live calls and messages to it — no infrastructure to run.","includeFiles":["docs/functions/functions/**/*.md","docs/functions/concepts/**/*.md","docs/functions/reference/**/*.md"],"excludeFiles":["docs/functions/functions/index.md"]},{"title":"CLI","description":"One command line for every Sinch API and the full Functions lifecycle — scaffold, run locally, deploy, and manage.","includeFiles":["docs/functions/cli/**/*.md"],"excludeFiles":["docs/functions/cli/index.md"]}]},"description":"Learn about how to create and use OAuth 2.0 access tokens with Sinch APIs."},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"oauth-20-access-tokens","__idx":0},"children":["OAuth 2.0 access tokens"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"ConnectButton","attributes":{"title":"Sinch Agentic Tools","icon":"aiCode","option":[{"title":"Sinch Plugins","description":"Install Sinch Plugins","icon":"connection","link":"https://github.com/sinch/sinch-plugins#installation"},{"title":"Sinch Skills","description":"Install Sinch Skills","icon":"ai","link":"https://github.com/sinch/skills#installation"}]},"children":[]}," ",{"$$mdtype":"Tag","name":"ConnectButton","attributes":{"title":"Sinch SDKs","icon":"code","option":[{"title":"Sinch Node.js SDK","description":"Install Sinch Node.js SDK","icon":"node","link":"/docs/sdks/node#installation"},{"title":"Sinch Java SDK","description":"Install Sinch Java SDK","icon":"java","link":"/docs/sdks/java#installation"},{"title":"Sinch .NET SDK","description":"Install Sinch .NET SDK","icon":"dotnet","link":"/docs/sdks/dotnet#installation"},{"title":"Sinch Python SDK","description":"Install Sinch Python SDK","icon":"python","link":"/docs/sdks/python#installation"}]},"children":[]}," ",{"$$mdtype":"Tag","name":"ConnectButton","attributes":{"title":"Sinch CLI & Functions","icon":"window","option":[{"title":"Sinch CLI","description":"Install Sinch CLI","icon":"cli","link":"/docs/functions/cli/installation"},{"title":"Sinch Functions","description":"Quickstart Sinch Functions","icon":"code","link":"/docs/functions/functions/quickstart"}]},"children":[]}," ",{"$$mdtype":"Tag","name":"ConnectMCP","attributes":{"placement":"bottom","alignment":"start","options":["cursor","vscode","copy"]},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch APIs authenticate with short-lived OAuth2 access tokens (bearer tokens). You obtain one by presenting your access key to the token endpoint using the client credentials grant, then send the token on each API request."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/access-token.1535d248573f3217eff418640d0fa528aa67dd98d9b578f5aa04899aba340aa1.90190c10.png","alt":"access token diagram"},"children":[]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You authenticate with the access key only once per token, not on every request. The token is what travels on your API calls."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-1-request-a-token","__idx":1},"children":["Step 1: Request a token"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Send a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST"]}," to the token endpoint with grant_type=client_credentials, authenticating with your Key ID and Key Secret via HTTP Basic auth:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"curl https://auth.sinch.com/oauth2/token \\\n  -X POST \\\n  -d \"grant_type=client_credentials\" \\\n  -u \"YOUR_key_id:YOUR_key_secret\"\n","lang":"shell"},"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":"Placeholder"},"children":["Placeholder"]},{"$$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":["YOUR_key_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Your access key's Key ID."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["YOUR_key_secret"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Your access key's Key Secret."]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A successful response returns a JSON body:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"access_token\": \"eyJhbGciOi...\",\n  \"token_type\": \"Bearer\",\n  \"expires_in\": 3600,\n  \"scope\": \"\"\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":"Field"},"children":["Field"]},{"$$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 bearer token to send on API requests."]}]},{"$$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":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["expires_in"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Token lifetime in seconds. Access tokens are short lived, typically one hour."]}]}]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Access tokens are short lived for security. Request a new one when the current token nears expiry, rather than trying to extend it."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-2-call-an-api-with-the-token","__idx":2},"children":["Step 2: Call an API with the token"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Send the token in the Authorization header as a bearer credential. For example, a call to retrieve available numbers:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"curl https://numbers.api.sinch.com/v1/projects/YOUR_project_id/availableNumbers \\\n  -H \"Authorization: Bearer YOUR_access_token\"\n","lang":"shell"},"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":"Placeholder"},"children":["Placeholder"]},{"$$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":["YOUR_project_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The project that owns the resource."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["YOUR_access_token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The access_token value from Step 1."]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Now you're ready to call any Sinch API with your token."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"cache-and-reuse-tokens","__idx":3},"children":["Cache and reuse tokens"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Access tokens are valid for its full ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["expires_in"]}," window. Cache the token and reuse it until shortly before it expires, rather than fetching one per API call."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A simple strategy:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Request a token and store it with its expiry time."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["On each API call, reuse the cached token if it isn't near expiry."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["When it's within ~60 seconds of expiry, request a new token. If a request returns a 401, check the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["WWW-Authenticate"]}," header to determine whether the access token has expired, is invalid, or is missing. If the token has expired, request a new token and retry the request."]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Tip:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treat a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["401 Unauthorized"]}," as your signal to refresh the token once and retry. If the retry also fails, the problem is the credentials or scope, not expiry."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"troubleshooting","__idx":4},"children":["Troubleshooting"]},{"$$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":"Symptom"},"children":["Symptom"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Likely cause"},"children":["Likely cause"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Fix"},"children":["Fix"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["401 from the token endpoint"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Wrong Key ID/Secret, or secret mistyped"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Re-copy the Key Secret, or create a new access key."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["401 from an API call"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Missing or invalid authentication, such as no Authorization header or an invalid/expired token Token expired, malformed header."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Refresh the token; confirm the header is ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization: Bearer <token>"]},"."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["403 from an API call"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Key's project doesn't own the resource"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Use a key from the project that owns the resource."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Invalid credentials error"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Invalid credentials when using APIs that follow the new Sinch REST API standards"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["See the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/errors/registry/invalid-credentials"},"children":["Sinch API error registry"]}," for details."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"next-step","__idx":5},"children":["Next step"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Manage who can create keys and projects in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/identity-access-management/access/team-management"},"children":["Team & access management"]},"."]}]},"headings":[{"value":"OAuth 2.0 access tokens","id":"oauth-20-access-tokens","depth":1},{"value":"Step 1: Request a token","id":"step-1-request-a-token","depth":2},{"value":"Step 2: Call an API with the token","id":"step-2-call-an-api-with-the-token","depth":2},{"value":"Cache and reuse tokens","id":"cache-and-reuse-tokens","depth":2},{"value":"Troubleshooting","id":"troubleshooting","depth":2},{"value":"Next step","id":"next-step","depth":2}],"frontmatter":{"seo":{"title":"OAuth 2.0 access tokens | Sinch","description":"Learn about how to create and use OAuth 2.0 access tokens with Sinch APIs."}},"lastModified":"2026-08-18T14:45:01.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/identity-access-management/authenticate/oauth2","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}