M2M requirements and best practices
Obtaining, using, and rotating credentials for service-to-service calls
A machine-to-machine client authenticates with the client credentials grant: there is no user present, and the client itself is the caller. This page covers how to get a token, what a receiving API checks, and how to handle rotation and failures. For a tool acting on behalf of a signed-in person instead of a service, use authorization code with PKCE, covered under Login options.
Requesting a token
What the API validates
Every request is checked for:
- A valid signature against the tenant JWKS
- The expected issuer and audience
- An unexpired token
- The scopes the specific endpoint requires
Scopes
Scopes are granted per client and are enforced per endpoint. A client should hold only the scopes it uses.
Caching tokens
Request a token once, cache it in memory, and refresh it shortly before expiry. Minting a token per request wastes the token endpoint’s rate budget and adds latency to every call.
Rotating secrets
Rotating a client secret invalidates the previous one immediately, so every consumer of that client has to be updated in the same change window.
Troubleshooting
See Error codes for the full list.