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: services/how-to/json-web-token-jwt.md
+35-34Lines changed: 35 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ import TabItem from "@theme/TabItem";
10
10
11
11
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.
12
12
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.
14
14
15
-
:::warning
15
+
:::info
16
16
17
17
Infura supports using JWTs for Web3 networks.
18
18
@@ -24,7 +24,7 @@ Only authenticated users can access Infura projects by including JWTs in request
24
24
25
25
#### Workflow
26
26
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.
28
28
2. A user logs into the project application and receives a JWT.
29
29
3. Each request the user makes to Infura with the application's API key includes the JWT in the header.
30
30
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.
39
39
40
40
### Generate keys
41
41
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.
43
43
44
44
:::warning
45
45
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)!
47
47
48
48
:::
49
49
50
-
The following example creates the key pairs using `openssl`:
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
89
68
90
69
:::
91
70
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.
93
72
94
73
1. Paste the public key into the **JWT Public Key** input box. It looks something like this:
95
74
@@ -131,27 +110,40 @@ To get the request to pass, generate a JWT, and add it to the request.
131
110
132
111
### Generate a JWT
133
112
113
+
Generate a JWT with an online tool, or programmatically:
114
+
115
+
116
+
<Tabs>
117
+
<TabItemvalue="Online tool"default>
118
+
134
119
The following example uses the [jwt.io](https://jwt.io) site to generate the JWT:
135
120
136
121
- Use a supported algorithm (`RS256` or `ES256`) and declare it in the `alg` header field.
137
122
- Specify `JWT` in the `typ` header field.
138
123
- Include the JWT `ID` in the `kid` header field.
139
124
- 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
+

140
129
141
130
:::info
142
131
143
132
To generate a timestamp for testing, use an [online timestamp converter tool](https://www.freeformatter.com/epoch-timestamp-to-date-converter.html).
144
133
145
134
:::
146
135
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
+
<TabItemvalue="Programatically">
149
138
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).
151
140
152
-

141
+
</TabItem>
142
+
</Tabs>
143
+
144
+
### Apply the JWT
153
145
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:
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.
Copy file name to clipboardExpand all lines: services/tutorials/ethereum/authenticate-with-jwt.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,6 @@ This tutorial demonstrates how to create and apply a JSON Web Token (JWT) to aut
13
13
[`eth_blockNumber`](../../api/networks/ethereum/json-rpc-methods/eth_blocknumber.mdx) API request
14
14
with Node.js.
15
15
16
-
Developers can configure the expiry time and scope of JWTs to enhance the security profile of their dapps.
17
-
18
16
## Prerequisites
19
17
20
18
-[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
364
362
Consider following these next steps:
365
363
366
364
-[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).
368
366
- 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/).
369
367
- Add a layer of verification to your call by applying the JWT's **FINGERPRINT** provided in the MetaMask Developer dashboard.
0 commit comments