Skip to content

Commit d6f4c7d

Browse files
Jwt duplicate fix (#1762)
* fixes: 1757 duplication and reconciliation for JWT * Update services/how-to/json-web-token-jwt.md * Update services/how-to/json-web-token-jwt.md * Update eth_feeHistory (#1761) Signed-off-by: bgravenorst <[email protected]> * Fix json. Signed-off-by: bgravenorst <[email protected]> --------- Signed-off-by: bgravenorst <[email protected]> Co-authored-by: m4sterbunny <[email protected]>
1 parent 3791548 commit d6f4c7d

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

services/how-to/json-web-token-jwt.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import TabItem from "@theme/TabItem";
1010

1111
JSON Web Token (JWT) is an internet standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) that defines a process for secure data exchange between two parties.
1212

13-
Infura projects can use [JSON Web Tokens](https://jwt.io) to authorize users and external parties.
13+
Infura projects can use [JSON Web Tokens](https://jwt.io) to authorize users and external parties. This allows developers to enhance the security profile of their dapps by configuring the expiry time and scope of JWTs.
1414

15-
:::warning
15+
:::info
1616

1717
Infura supports using JWTs for Web3 networks.
1818

@@ -24,7 +24,7 @@ Only authenticated users can access Infura projects by including JWTs in request
2424

2525
#### Workflow
2626

27-
1. Infura security settings enforce authorized access with JWTs.
27+
1. Set up your project's Infura security settings to enforce authorized access with JWTs.
2828
2. A user logs into the project application and receives a JWT.
2929
3. Each request the user makes to Infura with the application's API key includes the JWT in the header.
3030
4. The JWT is verified and the request is successful, or the request is rejected if the JWT is invalid.
@@ -39,35 +39,14 @@ JWTs may also include allowlists that enforce further restrictions.
3939

4040
### Generate keys
4141

42-
You can generate your private and public key pair using a tool such as [OpenSSL](https://www.openssl.org). Infura supports the [RS256](https://datatracker.ietf.org/doc/html/rfc7518#section-3.3) and [ES256](https://datatracker.ietf.org/doc/html/rfc7518#section-3.4) cryptographic algorithms.
42+
Generate your private and public key pair. Infura supports the [RS256](https://datatracker.ietf.org/doc/html/rfc7518#section-3.3) and [ES256](https://datatracker.ietf.org/doc/html/rfc7518#section-3.4) cryptographic algorithms. If you are unfamiliar with generating keys, follow the [Authenticate with JWT](../tutorials/ethereum/authenticate-with-jwt.md#21-generate-your-private-key) tutorial.
4343

4444
:::warning
4545

46-
Ensure your private key stays private!
46+
Ensure your [private key stays private](https://www.infura.io/blog/post/best-practises-for-infura-api-key-management)!
4747

4848
:::
4949

50-
The following example creates the key pairs using `openssl`:
51-
52-
<Tabs>
53-
<TabItem value="RSA key pair" label="RSA key pair" default>
54-
55-
```bash
56-
openssl genrsa -out private.pem 2048
57-
openssl rsa -in private.pem -outform PEM -pubout -out public.pembas
58-
```
59-
60-
</TabItem>
61-
<TabItem value="EC (256) key pair" label="EC (256) key pair" >
62-
63-
```bash
64-
openssl ecparam -name prime256v1 -genkey -noout -out private.pem
65-
openssl ec -in private.pem -pubout -out public.pembash
66-
```
67-
68-
</TabItem>
69-
</Tabs>
70-
7150
### Upload the public key
7251

7352
Upload the contents of the public key file that you [generated earlier](json-web-token-jwt.md#generate-keys):
@@ -89,7 +68,7 @@ Upload the contents of the public key file that you [generated earlier](json-web
8968

9069
:::
9170

92-
1. Give the public key a name.
71+
1. Provide a unique name for your JWT public key, which can help you manage multiple keys.
9372

9473
1. Paste the public key into the **JWT Public Key** input box. It looks something like this:
9574

@@ -131,27 +110,40 @@ To get the request to pass, generate a JWT, and add it to the request.
131110

132111
### Generate a JWT
133112

113+
Generate a JWT with an online tool, or programmatically:
114+
115+
116+
<Tabs>
117+
<TabItem value="Online tool" default>
118+
134119
The following example uses the [jwt.io](https://jwt.io) site to generate the JWT:
135120

136121
- Use a supported algorithm (`RS256` or `ES256`) and declare it in the `alg` header field.
137122
- Specify `JWT` in the `typ` header field.
138123
- Include the JWT `ID` in the `kid` header field.
139124
- Have an unexpired `exp` timestamp in the payload data.
125+
- Specify `infura.io` in the `aud` field.
126+
- Add the public key and private key created earlier into the **Verify Signature** section.
127+
128+
![Generate a JWT online](../images/jwt.png)
140129

141130
:::info
142131

143132
To generate a timestamp for testing, use an [online timestamp converter tool](https://www.freeformatter.com/epoch-timestamp-to-date-converter.html).
144133

145134
:::
146135

147-
- Specify `infura.io` in the `aud` field.
148-
- Add the public key and private key created earlier into the **Verify Signature** section.
136+
</TabItem>
137+
<TabItem value="Programatically">
149138

150-
To see how this works, go to a site like [jwt.io](https://jwt.io) and enter the data.
139+
Developers typically create the JWT token from their keys programmatically. To learn more, follow the tutorial demonstrating how to [create and apply a JWT with Node.js](../tutorials/ethereum/authenticate-with-jwt.md).
151140

152-
![Generate a JWT online](../images/jwt.png)
141+
</TabItem>
142+
</Tabs>
143+
144+
### Apply the JWT
153145

154-
Copy the encoded token as part of the `-H "Authorization: Bearer` entry:
146+
Pass the encoded token as part of the `-H "Authorization: Bearer` entry:
155147

156148
```bash
157149
curl -X POST \
@@ -165,6 +157,9 @@ curl -X POST \
165157
{"jsonrpc": "2.0", "id": 1, "result": "0x1cc23d4"}
166158
```
167159

160+
161+
## Next steps
162+
168163
### Set up allowlists
169164

170165
Allowlists restrict specific activity to users without JWTs. For example, in a system with proxy contracts, allowlists can restrict a user to sending requests to their own proxy only.
@@ -216,10 +211,10 @@ curl -X POST \
216211
```
217212

218213
```bash
219-
{"jsonrpc": "2.0", "id": 1, "result": "0x1a66d865b7f200"}%
214+
{"jsonrpc": "2.0", "id": 1, "result": "0x1a66d865b7f200"}
220215
```
221216

222-
## Verify JWTs
217+
### Verify JWTs
223218

224219
To identify the public key you have used to create a JWT, verify it with the `FINGERPRINT`.
225220

@@ -241,3 +236,9 @@ openssl ec -in private.pem -pubout -outform DER | openssl sha256 -binary | opens
241236

242237
</TabItem>
243238
</Tabs>
239+
240+
### Learn more
241+
242+
- Learn more about [keeping your Infura secrets safe](https://www.infura.io/blog/post/best-practises-for-infura-api-key-management).
243+
- Follow a [tutorial](../tutorials/ethereum/authenticate-with-jwt.md) to create and apply a JWT to authenticate an
244+
`eth_blockNumber` API request.

services/tutorials/ethereum/authenticate-with-jwt.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ This tutorial demonstrates how to create and apply a JSON Web Token (JWT) to aut
1313
[`eth_blockNumber`](../../api/networks/ethereum/json-rpc-methods/eth_blocknumber.mdx) API request
1414
with Node.js.
1515

16-
Developers can configure the expiry time and scope of JWTs to enhance the security profile of their dapps.
17-
1816
## Prerequisites
1917

2018
- [Node](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) version 20+
@@ -364,7 +362,7 @@ You can run this request yourself to make the call. Your console outputs the res
364362
Consider following these next steps:
365363

366364
- [Configure your JWT](../../how-to/json-web-token-jwt.md) to control its scope.
367-
<!-- - Read this blog post about [keeping your Infura secrets safe]({when blog is up}) -->
365+
- Learn more about [keeping your Infura secrets safe](https://www.infura.io/blog/post/best-practises-for-infura-api-key-management).
368366
- Decode your JWT: Copy the JWT provided in the console by the [optional curl equivalent step](#optional-examine-the-curl-equivalent), and paste it into the **Encoded** field in [jwt.io](https://jwt.io/).
369367
- Add a layer of verification to your call by applying the JWT's **FINGERPRINT** provided in the MetaMask Developer dashboard.
370368

0 commit comments

Comments
 (0)