
Machine-to-machine (M2M) authentication is how one piece of software proves its identity to another when no human is involved. A backend service calling an API, a scheduled job, a CI pipeline, or an AI agent invoking a tool all need to say "this is who I am" without a login screen. The standard way to do it is the OAuth 2.0 client credentials grant, where the client authenticates with its own credentials and receives an access token that represents the service itself, not a user.
That last point is the whole difference from normal login. There is no user to consent, no password to type, and no session tied to a person. The token stands for the calling software, and the hard parts are how the machine proves who it is and how you stop its credentials from becoming a skeleton key. This guide covers both.
M2M authentication runs on the client credentials grant, defined in RFC 6749. The flow is short: the client sends its credentials to the authorization server's token endpoint, the server verifies them and checks what the client is allowed to request, and it returns an access token. The client then attaches that token to its API calls, and the receiving API validates it before doing any work.
Because there is no user, there is no redirect and no consent screen, just a direct request for a token. The token carries the client's identity and a set of scopes describing what it may do, such as `invoices.read` or `payments.write`. When the token expires, the client simply requests another. Nothing about the flow depends on a browser or a person being present.
The client credentials grant defines the flow, not how the client authenticates, and the method you pick is where most of the security lives. Three are common, in rough order of strength.
A shared client secret is the simplest: the client holds a `client_id` and a `client_secret` and sends them to the token endpoint. It works everywhere, but the secret is a long-lived password that has to be stored, distributed, and rotated, and anyone who copies it can impersonate the client.
A signed JWT assertion, standardized in RFC 7523, is stronger: the client signs a short-lived token with its private key and sends that instead of a shared secret, so no reusable secret travels on the wire.
Mutual TLS is the strongest for M2M: the client authenticates with a certificate over mTLS, and under RFC 8705 the access token can be bound to that certificate, so even a stolen token cannot be replayed from a client that lacks the matching key.
A shared client secret is a long-lived bearer credential, and that is exactly what attackers hunt for. It ends up in environment variables, config files, CI logs, and source control, and once it leaks it keeps working until someone notices and rotates it. The pattern behind most machine-identity incidents is a static secret that lived too long and reached too far.
The fixes are consistent. Keep access tokens short-lived so a leaked one expires quickly. Prefer credentials that are not reusable secrets, a private key that signs assertions, or a certificate used with mTLS. And for dynamic environments like Kubernetes, replace stored secrets entirely with workload identity such as SPIFFE, where each workload gets a short-lived, automatically rotated identity attested at runtime rather than a secret checked into a cluster.
User authentication answers "who is this person," produces a session, and usually involves a browser, a login, and consent. M2M authentication answers "which service is this," produces a token that represents software, and involves none of those. A user token carries claims about a person; an M2M token carries the client's own identity and its scopes.
The practical consequence is that authorization matters even more for machines. A service token often has broad, standing reach and runs unattended, so deciding exactly what each client may do, and scoping it tightly, is what limits the damage if a credential leaks. This is the same authentication-versus-authorization split covered in authentication vs authorization, applied to non-human callers.
MonoCloud supports the client credentials grant for machine-to-machine access, and it lets you authenticate clients with mutual TLS and issue certificate-bound access tokens (RFC 8705), so a machine's token only works from the client holding the matching certificate. For dynamic workloads, you can register a SPIRE trust bundle and let each workload authenticate with its short-lived SPIFFE identity instead of a stored secret.
The part worth calling out is what happens at token issuance. MonoCloud evaluates a Cedar policy before it issues an M2M access token, so which client may call which API is decided by rule, with full context, rather than left to each service to enforce. It can shape the token's audiences and lifetime per rule and issue revocable reference tokens where central revocation matters, so a compromised client can be cut off centrally rather than waiting out an expiry. To wire it up, start building on MonoCloud for free.
What is machine-to-machine (M2M) authentication?
M2M authentication is how one piece of software proves its identity to another when no human is involved, such as a backend service calling an API, a scheduled job, or an AI agent invoking a tool. It usually uses the OAuth 2.0 client credentials grant, where the client authenticates with its own credentials and receives a token that represents the service itself, not a user.
What is the client credentials grant?
The client credentials grant, defined in RFC 6749, is the OAuth flow for M2M access. The client sends its credentials to the token endpoint, the server verifies them and checks what the client may request, and it returns an access token carrying the client's identity and scopes. There is no user, no redirect, and no consent screen.
How does a machine authenticate without a password?
Three common methods, in rough order of strength: a shared client secret (a stored password, the weakest), a signed JWT assertion where the client signs a short-lived token with its private key (RFC 7523), and mutual TLS where the client authenticates with a certificate and the token is bound to it (RFC 8705). mTLS is the strongest because there is no reusable secret to steal.
What is the most secure way to do M2M authentication?
Certificate-based mTLS with certificate-bound tokens, so a stolen token cannot be replayed from another client, combined with short-lived tokens. For dynamic environments like Kubernetes, workload identity such as SPIFFE replaces stored secrets entirely, giving each workload a short-lived, automatically rotated identity attested at runtime.
How is M2M authentication different from user login?
User login authenticates a person, produces a session, and usually involves a browser and consent. M2M authentication authenticates a piece of software, produces a token that represents the service and its scopes, and involves none of those. Because a service token often has broad, standing, unattended reach, scoping it tightly matters even more than for a user.