You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/machine-to-machine-applications/organization-scoped-m2m-apps/enforce-org-m2m-access-in-your-api.mdx
+15-19Lines changed: 15 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,6 @@ relatedArticles:
11
11
12
12
If you're using [org-scoped machine-to-machine (M2M) apps](/machine-to-machine-applications/organization-scoped-m2m-apps/m2m-applications-for-organizations/), Kinde will automatically include a trusted `org_code` claim in the token. You can then enforce access control in your own APIs using this claim.
13
13
14
-
15
14
## When to enforce org context
16
15
17
16
You should validate `org_code` in any API route or resource that is **tenant-specific**, such as:
@@ -33,35 +32,31 @@ When you receive a token, decode it and check:
33
32
## Example in Node.js (Express)
34
33
35
34
```js
36
-
constjwt=require('jsonwebtoken')
37
-
35
+
constjwt=require("jsonwebtoken");
38
36
functionverifyOrgAccess(req, res, next) {
39
-
constauthHeader=req.headers.authorization
40
-
consttoken= authHeader?.split('')[1]
41
-
42
-
if (!token) returnres.status(401).send('Missing token')
43
-
44
-
constdecoded=jwt.decode(token)
45
-
37
+
constauthHeader=req.headers.authorization;
38
+
consttoken= authHeader?.split("")[1];
39
+
if (!token) returnres.status(401).send("Missing token");
40
+
// If Kinde is **not** validating the token for you,
41
+
// verify the signature instead of a raw decode.
42
+
//const PUBLIC_KEY = ... // fetch from /.well-known/openid-configuration
0 commit comments