@@ -8,34 +8,42 @@ npm install --save @chronicleprotocol/api-auth
8
8
9
9
## Usage
10
10
11
- Generating authentication tokens:
11
+ Generating authentication tokens programmatically :
12
12
13
13
``` js
14
14
import { signAuthToken } from " @chronicleprotocol/api-auth" ;
15
15
16
16
const { token , message } = signAuthToken ({
17
- // private key is 0x prefixed 32 byte hex string
18
- privateKey: " 0xabc..." ,
17
+ // private key is 0x prefixed 32 byte hex string
18
+ privateKey: " 0xabc..." ,
19
19
});
20
20
21
21
// `token` is hex string to be included as Authorization header (see below)
22
22
// `message` is object containing decoded data within `token`. Optional,
23
23
// but can be useful for programmatic token handling
24
+ ```
25
+
26
+ To generate a token via the command line, use:
24
27
28
+ ``` bash
29
+ # Please do not put your private key directly in the command and have it show up in your shell history :-(
30
+ npx @chronicleprotocol/api-auth --privateKey=$PRIVATE_KEY
25
31
```
26
32
27
- > Your public signing address must be allow-listed on our servers before your tokens will be valid.
33
+ > NOTE: Your public signing address must be allow-listed on our servers before your tokens will be valid.
28
34
29
- Using an auth token to fetch an API endpoint:
35
+ Using an auth token to fetch an API endpoint programmatically :
30
36
31
37
``` js
32
- // token is received from the server
33
- fetch (
34
- " https://chroniclelabs.org/api/pairs" ,
35
- {
36
- headers: {
37
- Authorization: ` Bearer ${ token} ` ,
38
- },
39
- },
40
- );
38
+ fetch (" https://chroniclelabs.org/api/authTest" , {
39
+ headers: {
40
+ Authorization: ` Bearer ${ token} ` ,
41
+ },
42
+ });
43
+ ```
44
+
45
+ or via command line:
46
+
47
+ ``` bash
48
+ curl --header " Authorization: Bearer $AUTH_TOKEN " https://chroniclelabs.org/api/authTest
41
49
```
0 commit comments