Skip to content

Commit 2cb7b3a

Browse files
committed
docs: update verifyRequestByKeyId
1 parent 5397672 commit 2cb7b3a

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

README.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,46 @@ try {
7777

7878
Verify the request payload using the provided signature and key ID. The method will request the public key from GitHub's API for the given keyId and then verify the payload.
7979

80-
The `options` argument is optional. It can contain a `token` to authenticate the request to GitHub's API, or a custom `request` instance to use for the request.
80+
The [`requestOptions`] argument is optional. It can contain:
81+
82+
- a `token` to authenticate the request to GitHub's API
83+
- a custom `request` instance to use for the request
84+
- a `cache` to use cached keys
8185

8286
```js
8387
import { verifyRequestByKeyId } from "@copilot-extensions/preview-sdk";
8488

85-
const payloadIsVerified = await verifyRequestByKeyId(
89+
const { isValid, cache } = await verifyRequestByKeyId(
8690
request.body,
8791
signature,
88-
key,
92+
keyId,
8993
);
9094

9195
// with token
92-
await verifyRequestByKeyId(request.body, signature, key, { token: "ghp_1234" });
96+
const { isValid, cache } = await verifyRequestByKeyId(
97+
request.body,
98+
signature,
99+
keyId,
100+
{ token: "ghp_1234" }
101+
);
93102

94103
// with custom octokit request instance
95-
await verifyRequestByKeyId(request.body, signature, key, { request });
96-
```
104+
const { isValid, cache } = await verifyRequestByKeyId(
105+
request.body,
106+
signature,
107+
keyId,
108+
{ request }
109+
);
97110

111+
// with cache
112+
const cache = { id: "etag_value", keys: [{ key_identifier: "key1", key: "public_key1" }] };
113+
const { isValid, cache } = await verifyRequestByKeyId(
114+
request.body,
115+
signature,
116+
keyId,
117+
{ cache }
118+
);
119+
```
98120
#### `async fetchVerificationKeys(options)`
99121

100122
Fetches public keys for verifying copilot extension requests [from GitHub's API](https://api.github.com/meta/public_keys/copilot_api)

0 commit comments

Comments
 (0)