Skip to content

Commit 0a51170

Browse files
committed
feat(types): rename field to params
1 parent f2f15b4 commit 0a51170

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# authorization-parser
1+
# auth-parser
22

33
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/authorization_parser)
44
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/authorization_parser/mod.ts)
@@ -9,7 +9,8 @@
99
[![test](https://github.com/httpland/authorization-parser/actions/workflows/test.yaml/badge.svg)](https://github.com/httpland/authorization-parser/actions/workflows/test.yaml)
1010
[![NPM](https://nodei.co/npm/@httpland/authorization-parser.png?mini=true)](https://nodei.co/npm/@httpland/authorization-parser/)
1111

12-
HTTP `Authorization` field parser and serializer.
12+
HTTP Authentication and Authorization `Authorization` field parser and
13+
serializer.
1314

1415
Compliant with
1516
[RFC 9110, 11.6.2. Authorization](https://www.rfc-editor.org/rfc/rfc9110.html#section-11.6.2).
@@ -26,13 +27,13 @@ const result = parseAuthorization("Basic token68");
2627

2728
assertEquals(parseAuthorization("Basic token68"), {
2829
authScheme: "Basic",
29-
token: "token68",
30+
params: "token68",
3031
});
3132
assertEquals(
3233
parseAuthorization(`Bearer realm="example", error="invalid_token"`),
3334
{
3435
authScheme: "Bearer",
35-
token: {
36+
params: {
3637
realm: `"example"`,
3738
error: `"invalid_token"`,
3839
},
@@ -81,10 +82,10 @@ assertThrows(() =>
8182

8283
`Authorization` is following structure:
8384

84-
| Name | Type | Description |
85-
| ---------- | ------------------------------------------ | ---------------------- |
86-
| authScheme | `string` | Authentication scheme. |
87-
| token | `Token68` | `AuthParam` | `null` | token68 or auth-param. |
85+
| Name | Type | Description |
86+
| ---------- | ------------------------------------------- | ---------------------- |
87+
| authScheme | `string` | Authentication scheme. |
88+
| params | `Token68` | `AuthParams` | `null` | token68 or auth-param. |
8889

8990
### Token68
9091

@@ -95,12 +96,12 @@ so that it can hold a base64, base64url (URL and filename safe alphabet),
9596
base32, or base16 (hex) encoding, with or without padding, but excluding
9697
whitespace.
9798

98-
### AuthParam
99+
### AuthParams
99100

100101
It is name/value pairs.
101102

102103
```ts
103-
interface AuthParam {
104+
interface AuthParams {
104105
readonly [k: string]: string;
105106
}
106107
```

authorization.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"header": "Basic YWxhZGRpbjpvcGVuc2VzYW1l",
66
"expected": {
77
"authScheme": "Basic",
8-
"authParams": "YWxhZGRpbjpvcGVuc2VzYW1l"
8+
"params": "YWxhZGRpbjpvcGVuc2VzYW1l"
99
}
1010
},
1111
{
@@ -14,7 +14,7 @@
1414
"header": "Bearer realm=\"example\", error=\"invalid_token\", error_description=\"The access token expired\"",
1515
"expected": {
1616
"authScheme": "Bearer",
17-
"authParams": {
17+
"params": {
1818
"realm": "\"example\"",
1919
"error": "\"invalid_token\"",
2020
"error_description": "\"The access token expired\""
@@ -27,7 +27,7 @@
2727
"header": "Digest username=\"Mufasa\", realm=\"[email protected]\", uri=\"/dir/index.html\", algorithm=SHA-256, nonce=\"7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v\", nc=00000001, cnonce=\"f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ\", qop=auth, response=\"753927fa0e85d155564e2e272a28d1802ca10daf4496794697cf8db5856cb6c1\", opaque=\"FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS\"",
2828
"expected": {
2929
"authScheme": "Digest",
30-
"authParams": {
30+
"params": {
3131
"username": "\"Mufasa\"",
3232
"realm": "\"[email protected]\"",
3333
"uri": "\"/dir/index.html\"",
@@ -47,7 +47,7 @@
4747
"ref": "https://datatracker.ietf.org/doc/html/rfc7616#section-3.9.2",
4848
"expected": {
4949
"authScheme": "Digest",
50-
"authParams": {
50+
"params": {
5151
"username": "\"488869477bf257147b804c45308cd62ac4e25eb717b12b298c79e62dcea254ec\"",
5252
"realm": "\"[email protected]\"",
5353
"uri": "\"/doe.json\"",
@@ -68,7 +68,7 @@
6868
"ref": "https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html",
6969
"expected": {
7070
"authScheme": "AWS4-HMAC-SHA256",
71-
"authParams": {
71+
"params": {
7272
"Credential": "\"AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request\"",
7373
"SignedHeaders": "\"host;range;x-amz-date\"",
7474
"Signature": "fe5f80f77d5fa3beca038a248ff027d0445342fe2855ddc963176630326f1024"

parse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ const reAuthorization =
2020
*
2121
* assertEquals(parseAuthorization("Basic token68"), {
2222
* authScheme: "Basic",
23-
* token: "token68",
23+
* params: "token68",
2424
* });
2525
* assertEquals(
2626
* parseAuthorization(`Bearer realm="example", error="invalid_token"`),
2727
* {
2828
* authScheme: "Bearer",
29-
* token: {
29+
* params: {
3030
* realm: `"example"`,
3131
* error: `"invalid_token"`,
3232
* },
@@ -44,11 +44,11 @@ export function parseAuthorization(input: string): Authorization {
4444

4545
const groups = result.groups as ParsedGroups;
4646
const { authScheme } = groups;
47-
const authParams = isString(groups.authParam)
47+
const params = isString(groups.authParam)
4848
? parseAuthParams(groups.authParam)
4949
: groups.token68;
5050

51-
return { authScheme, authParams: authParams ?? null };
51+
return { authScheme, params: params ?? null };
5252
}
5353

5454
type ParsedGroups = {

types.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
22
// This module is browser compatible.
33

4-
/** Credentials API. */
4+
/** Credentials API.
5+
* @see [RFC 9110, 11.4. Credentials](https://www.rfc-editor.org/rfc/rfc9110.html#section-11.4)
6+
*/
57
export interface Credentials {
68
/** Authentication scheme. */
79
readonly authScheme: string;
810

911
/** Authentication parameters. */
10-
readonly authParams: Token68 | AuthParams | null;
12+
readonly params: Token68 | AuthParams | null;
1113
}
1214

1315
/** Representation of [token68](https://www.rfc-editor.org/rfc/rfc9110.html#auth.params). */
@@ -20,4 +22,7 @@ export interface AuthParams {
2022
readonly [k: string]: string;
2123
}
2224

25+
/** Authorization API.
26+
* @see [RFC 9110, 11.6.2. Authorization](https://www.rfc-editor.org/rfc/rfc9110.html#section-11.6.2)
27+
*/
2328
export type Authorization = Credentials;

0 commit comments

Comments
 (0)