Skip to content
  • Workflows
  • Bindings

kinde.m2mToken

The kinde.m2mToken binding lets you modify M2M (machine-to-machine) tokens. When you add custom claims, these are included in the M2M token returned to the client.

setCustomClaim(name: string, value: any): void

Link to this section

Adds a custom claim to the M2M token. The claim is available when the token is returned to the client.

Available in workflows

Link to this section
export const workflowSettings = {
// ...other settings
bindings: {"kinde.m2mToken": {}}
};
Link to this section

The Kinde infrastructure library provides type-safe M2M token modification:

import { m2mTokenCustomClaims } from "@kinde/infrastructure";
export default async function (event: onM2mTokenGeneratedEvent) {
const m2mToken = m2mTokenCustomClaims<{
applicationId: string;
apiVersion: string;
permissions: string[];
}>();
m2mToken.applicationId = event.application.id;
m2mToken.apiVersion = "v2";
m2mToken.permissions = ["read:data", "write:data"];
};

Using the low-level API

Link to this section

If you’re not using the infrastructure library, you can modify the M2M token directly:

kinde.m2mToken.setCustomClaim("applicationId", event.application.id);
kinde.m2mToken.setCustomClaim("apiVersion", "v2");
kinde.m2mToken.setCustomClaim("permissions", ["read:data", "write:data"]);