diff options
| author | Semisol <45574030+Semisol@users.noreply.github.com> | 2023-11-19 01:45:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-19 01:45:41 +0100 |
| commit | da19c078ab892b578a5c35968443205c9e8ac27f (patch) | |
| tree | 17a9f4f3105acdae234d3bc67e42571aed261fa2 /98.md | |
| parent | 4d709d1804de45bab3739ce814d4b0c0b211c273 (diff) | |
| parent | 5dcfe85306434f21ecb1e7a47edd92b2e3e64f9a (diff) | |
Merge branch 'master' into clarify-json-serialization
Diffstat (limited to '98.md')
| -rw-r--r-- | 98.md | 44 |
1 files changed, 19 insertions, 25 deletions
| @@ -2,13 +2,13 @@ NIP-98 | |||
| 2 | ====== | 2 | ====== |
| 3 | 3 | ||
| 4 | HTTP Auth | 4 | HTTP Auth |
| 5 | ------------------------- | 5 | --------- |
| 6 | 6 | ||
| 7 | `draft` `optional` `author:kieran` `author:melvincarvalho` | 7 | `draft` `optional` |
| 8 | 8 | ||
| 9 | This NIP defines an ephemerial event used to authorize requests to HTTP servers using nostr events. | 9 | This NIP defines an ephemeral event used to authorize requests to HTTP servers using nostr events. |
| 10 | 10 | ||
| 11 | This is useful for HTTP services which are build for Nostr and deal with Nostr user accounts. | 11 | This is useful for HTTP services which are built for Nostr and deal with Nostr user accounts. |
| 12 | 12 | ||
| 13 | ## Nostr event | 13 | ## Nostr event |
| 14 | 14 | ||
| @@ -16,7 +16,7 @@ A `kind 27235` (In reference to [RFC 7235](https://www.rfc-editor.org/rfc/rfc723 | |||
| 16 | 16 | ||
| 17 | The `content` SHOULD be empty. | 17 | The `content` SHOULD be empty. |
| 18 | 18 | ||
| 19 | The following tags are defined as REQUIRED. | 19 | The following tags MUST be included. |
| 20 | 20 | ||
| 21 | * `u` - absolute URL | 21 | * `u` - absolute URL |
| 22 | * `method` - HTTP Request Method | 22 | * `method` - HTTP Request Method |
| @@ -24,28 +24,22 @@ The following tags are defined as REQUIRED. | |||
| 24 | Example event: | 24 | Example event: |
| 25 | ```json | 25 | ```json |
| 26 | { | 26 | { |
| 27 | "id": "fe964e758903360f28d8424d092da8494ed207cba823110be3a57dfe4b578734", | 27 | "id": "fe964e758903360f28d8424d092da8494ed207cba823110be3a57dfe4b578734", |
| 28 | "pubkey": "63fe6318dc58583cfe16810f86dd09e18bfd76aabc24a0081ce2856f330504ed", | 28 | "pubkey": "63fe6318dc58583cfe16810f86dd09e18bfd76aabc24a0081ce2856f330504ed", |
| 29 | "content": "", | 29 | "content": "", |
| 30 | "kind": 27235, | 30 | "kind": 27235, |
| 31 | "created_at": 1682327852, | 31 | "created_at": 1682327852, |
| 32 | "tags": [ | 32 | "tags": [ |
| 33 | [ | 33 | ["u", "https://api.snort.social/api/v1/n5sp/list"], |
| 34 | "u", | 34 | ["method", "GET"] |
| 35 | "https://api.snort.social/api/v1/n5sp/list" | 35 | ], |
| 36 | ], | 36 | "sig": "5ed9d8ec958bc854f997bdc24ac337d005af372324747efe4a00e24f4c30437ff4dd8308684bed467d9d6be3e5a517bb43b1732cc7d33949a3aaf86705c22184" |
| 37 | [ | ||
| 38 | "method", | ||
| 39 | "GET" | ||
| 40 | ] | ||
| 41 | ], | ||
| 42 | "sig": "5ed9d8ec958bc854f997bdc24ac337d005af372324747efe4a00e24f4c30437ff4dd8308684bed467d9d6be3e5a517bb43b1732cc7d33949a3aaf86705c22184" | ||
| 43 | } | 37 | } |
| 44 | ``` | 38 | ``` |
| 45 | 39 | ||
| 46 | Servers MUST perform the following checks in order to validate the event: | 40 | Servers MUST perform the following checks in order to validate the event: |
| 47 | 1. The `kind` MUST be `27235`. | 41 | 1. The `kind` MUST be `27235`. |
| 48 | 2. The `created_at` MUST be within a reasonable time window (suggestion 60 seconds). | 42 | 2. The `created_at` timestamp MUST be within a reasonable time window (suggestion 60 seconds). |
| 49 | 3. The `u` tag MUST be exactly the same as the absolute request URL (including query parameters). | 43 | 3. The `u` tag MUST be exactly the same as the absolute request URL (including query parameters). |
| 50 | 4. The `method` tag MUST be the same HTTP method used for the requested resource. | 44 | 4. The `method` tag MUST be the same HTTP method used for the requested resource. |
| 51 | 45 | ||
| @@ -53,11 +47,11 @@ When the request contains a body (as in POST/PUT/PATCH methods) clients SHOULD i | |||
| 53 | 47 | ||
| 54 | If one of the checks was to fail the server SHOULD respond with a 401 Unauthorized response code. | 48 | If one of the checks was to fail the server SHOULD respond with a 401 Unauthorized response code. |
| 55 | 49 | ||
| 56 | All other checks which server MAY do are OPTIONAL, and implementation specific. | 50 | Servers MAY perform additional implementation-specific validation checks. |
| 57 | 51 | ||
| 58 | ## Request Flow | 52 | ## Request Flow |
| 59 | 53 | ||
| 60 | Using the `Authorization` header, the `kind 27235` event MUST be `base64` encoded and use the Authorization scheme `Nostr` | 54 | Using the `Authorization` HTTP header, the `kind 27235` event MUST be `base64` encoded and use the Authorization scheme `Nostr` |
| 61 | 55 | ||
| 62 | Example HTTP Authorization header: | 56 | Example HTTP Authorization header: |
| 63 | ``` | 57 | ``` |
| @@ -65,4 +59,4 @@ Authorization: Nostr eyJpZCI6ImZlOTY0ZTc1ODkwMzM2MGYyOGQ4NDI0ZDA5MmRhODQ5NGVkMjA | |||
| 65 | ``` | 59 | ``` |
| 66 | 60 | ||
| 67 | ## Reference Implementations | 61 | ## Reference Implementations |
| 68 | - C# ASP.NET `AuthenticationHandler` [NostrAuth.cs](https://gist.github.com/v0l/74346ae530896115bfe2504c8cd018d3) \ No newline at end of file | 62 | - C# ASP.NET `AuthenticationHandler` [NostrAuth.cs](https://gist.github.com/v0l/74346ae530896115bfe2504c8cd018d3) |