Skip to content

Commit 37de349

Browse files
committed
fix: code samples
1 parent 49bc9b2 commit 37de349

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/content/docs/authenticate/device-authorization-flow/api-calls.mdx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,32 @@ curl -X GET https://<your-subdomain>.kinde.com/oauth2/v2/user_profile \
6464
You can also validate tokens in your own API by verifying the JWT signature and claims:
6565

6666
```javascript
67-
// Node.js example using jsonwebtoken
68-
const jwt = require("jsonwebtoken");
69-
70-
function validateToken(token) {
71-
try {
72-
const decoded = jwt.verify(token, "YOUR_JWT_SECRET");
73-
return {
74-
valid: true,
75-
user: decoded
76-
};
77-
} catch (error) {
78-
return {
79-
valid: false,
80-
error: error.message
81-
};
82-
}
83-
}
67+
+// Node.js example using jsonwebtoken with JWKS
68+
+const jwt = require("jsonwebtoken");
69+
+const jwksClient = require("jwks-rsa");
70+
+
71+
+const client = jwksClient({
72+
+ jwksUri: "https://<your-subdomain>.kinde.com/.well-known/jwks"
73+
+});
74+
+
75+
+function getKey(header, callback) {
76+
+ client.getSigningKey(header.kid, (err, key) => {
77+
+ const signingKey = key.publicKey || key.rsaPublicKey;
78+
+ callback(null, signingKey);
79+
+ });
80+
+}
81+
+
82+
+function validateToken(token) {
83+
+ return new Promise((resolve, reject) => {
84+
+ jwt.verify(token, getKey, { algorithms: ["RS256"] }, (err, decoded) => {
85+
+ if (err) {
86+
+ resolve({ valid: false, error: err.message });
87+
+ } else {
88+
+ resolve({ valid: true, user: decoded });
89+
+ }
90+
+ });
91+
+ });
92+
+}
8493
```
8594

8695
## Scope enforcement for device authorization

src/content/docs/authenticate/device-authorization-flow/overview.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Kinde's device authorization flow adheres to `RFC 8628`, also known as the OAuth
3131

3232
**Parameters**:
3333

34-
- `grant_type`: `urn:ietf:params:oauth:grant-type:device_code`
3534
- `client_id` (optional): Your application's client ID - can be omitted if you have set an application as the default for device flows
3635
- `audience` (optional): The audience to use for the request
3736

@@ -69,12 +68,12 @@ Kinde's device authorization flow adheres to `RFC 8628`, also known as the OAuth
6968
{
7069
"access_token": "eyJ...",
7170
"expires_in": 86400,
72-
"scope": "",
71+
"scope": "",
7372
"token_type": "bearer"
7473
}
7574
```
76-
The scope field may be empty because granted scopes are carried in the access token’s scope claim.
7775

76+
The scope field may be empty because granted scopes are carried in the access token’s scope claim.
7877

7978
**Example error response**:
8079

@@ -109,12 +108,12 @@ The device must poll the token endpoint at regular intervals until the user comp
109108
- **Verification URI**: Users should verify they're on the correct domain.
110109
- **Token expiration**: Access tokens expire after 1 hour by default.
111110

112-
## Specifying an audience in a device authorization request
111+
## Specifying an audience in a device authorization request
113112

114113
If an `audience` is specified in the request, the access token will include the audience in the `aud` claim. Kinde supports requesting multiple audiences.
115114

116115
The API must be authorized for the device authorization application.
117116

118-
## Scopes and permissions for a device authorization request
117+
## Scopes and permissions for a device authorization request
119118

120119
If an audience is specified in the request, any scopes which are belong to that audience that are granted to the user by their role will also be granted to the device. The list of scopes will be displayed on the consent screen. If the user consents, the scopes will be included in the `scope` claim of the access token.

src/content/docs/authenticate/device-authorization-flow/quick-start.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ Request a device code from Kinde's authorization endpoint:
3838
```bash
3939
curl -X POST https://<your-subdomain>.kinde.com/oauth2/device/auth \
4040
-H "Content-Type: application/x-www-form-urlencoded" \
41-
-d "client_id=<YOUR_CLIENT_ID>" \
42-
-d "grant_type=urn:ietf:params:oauth:grant-type:device_code"
41+
-d "client_id=<YOUR_CLIENT_ID>"
4342
```
4443

4544
The response will include a `device_code`, `user_code`, and `verification_uri`:

0 commit comments

Comments
 (0)