|
| 1 | +--- |
| 2 | +page_id: bbcccc7e-2a7a-44f2-8069-1c4bd37141b1 |
| 3 | +title: Machine-to-Machine (M2M) access scoped to organizations |
| 4 | +sidebar: |
| 5 | + order: 10 |
| 6 | +relatedArticles: |
| 7 | + - 815f10b0-7bd2-407a-9ac2-9fb582862a5b |
| 8 | + - 8f6af95a-14ef-436d-862f-bfa82e836558 |
| 9 | + - 263176d3-d823-4bba-a95f-02f6df00bd10 |
| 10 | +--- |
| 11 | + |
| 12 | +<Aside type="upgrade"> |
| 13 | + |
| 14 | +This is an advanced feature that is only available on the [Kinde Plus or Scale plans](https://kinde.com/pricing/) |
| 15 | + |
| 16 | +</Aside> |
| 17 | + |
| 18 | +Kinde supports creating machine-to-machine (M2M) applications that are scoped to a specific organization. This lets you securely issue access tokens tied to an organization, ensuring that any automation or service calling your APIs is restricted to the correct customer context. |
| 19 | + |
| 20 | +Global (unscoped) M2M applications are still supported for broader use cases, such as internal automation across multiple orgs. |
| 21 | + |
| 22 | +## When to use an org-scoped M2M application |
| 23 | + |
| 24 | +You should use an organization-scoped M2M app when: |
| 25 | + |
| 26 | +- You are building automation that acts on behalf of a specific customer or tenant. |
| 27 | +- You are deploying AI agents, bots, or backend services that must be restricted to a single organization’s data. |
| 28 | +- You want to issue different tokens with separate scopes or permissions per organization. |
| 29 | +- You need to simplify tenant isolation and avoid passing or validating org codes manually. |
| 30 | + |
| 31 | +## How it works |
| 32 | + |
| 33 | +1. Create an M2M application inside an organization in the Kinde dashboard. |
| 34 | +2. Assign scopes that define what the app can access (e.g. `read:users`, `write:flags`). |
| 35 | +3. Use the client credentials flow to request an access token using the generated `client_id` and `client_secret`. |
| 36 | +4. Kinde returns a token with trusted claims about the organization and app. |
| 37 | +5. The token can be used to interact with Kinde APIs on behalf of that organization. |
| 38 | + |
| 39 | +Each org-scoped app is tightly bound to a single organization. Tokens issued from that app cannot be used across orgs. |
| 40 | + |
| 41 | +## Token structure |
| 42 | + |
| 43 | +An example tokens issued to an org-scoped M2M app may include the following claims: |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "aud": ["https://api.foobar.com/v1/"], |
| 48 | + "azp": "12ce25d1109d4c66b0f469e47d33f8eb", |
| 49 | + "exp": 1751212288, |
| 50 | + "gty": ["client_credentials"], |
| 51 | + "iat": 1751125888, |
| 52 | + "iss": "https://example.kinde.com", |
| 53 | + "jti": "28a8d6a8-fe7c-4c90-84a6-1b3ccaaeabf2", |
| 54 | + "org_code": "org_1234567890", |
| 55 | + "scope": "read:users write:flags", |
| 56 | + "scp": ["read:users", "write:flags"], |
| 57 | + "v": "2" |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +These claims can be used by your backend services to authorize access to specific APIs or resources. |
| 62 | + |
| 63 | +## Org-scoped vs global M2M applications |
| 64 | + |
| 65 | +| Feature | Global M2M app | Org-scoped M2M app | |
| 66 | +| --------------------- | ---------------------------------- | ------------------------------ | |
| 67 | +| Org context in token | No | Yes | |
| 68 | +| Tenant data isolation | Manual | Enforced | |
| 69 | +| Use case | Admin scripts, internal automation | Per-tenant agents, scoped APIs | |
| 70 | +| Token restrictions | None | Scoped to one org | |
| 71 | +| Token claims | Basic | Includes `org_code`, `scope` | |
| 72 | + |
| 73 | +## Create an org-scoped M2M app |
| 74 | + |
| 75 | +1. In Kinde, go to **Organizations**, then view an organization. |
| 76 | +2. Select **M2M apps**. |
| 77 | +3. Select **Add M2M application** |
| 78 | +4. Enter a name for the application |
| 79 | +5. Select **Save**. |
| 80 | + |
| 81 | +Kinde generates a `client_id` and `client_secret` tied to the selected organization. |
| 82 | +Use the credentials in a standard client credentials flow to request a token. |
| 83 | + |
| 84 | +## Best practices |
| 85 | + |
| 86 | +- Use separate M2M apps for different scopes or services. |
| 87 | +- Limit the [scopes](https://docs.kinde.com/developer-tools/your-apis/custom-api-scopes/) assigned to each M2M app to the minimum required for its function. |
| 88 | +- [Rotate client secrets](https://docs.kinde.com/build/applications/rotate-client-secret/) periodically using the UI. |
| 89 | +- Audit token usage by tracking `client_id` and `org_code` in logs. |
| 90 | +- Avoid including any personally identifiable information (PII) in token claims. |
0 commit comments