@owlmeans/auth-token 0.1.18-rc.31 → 0.1.18-rc.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/auth-token/SKILL.md +1 -1
- package/build/format/types.d.ts +27 -0
- package/build/format/types.d.ts.map +1 -0
- package/build/format/types.js +2 -0
- package/build/format/types.js.map +1 -0
- package/build/format.d.ts +3 -21
- package/build/format.d.ts.map +1 -1
- package/build/format.js +22 -33
- package/build/format.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/types.d.ts +2 -1
- package/build/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/format/types.ts +27 -0
- package/src/format.ts +28 -36
- package/src/index.ts +1 -0
- package/src/types.ts +1 -1
- package/tests/format.spec.ts +17 -17
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
6
6
|
your project's skill store (`.agents/skills/`):
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
9
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.49
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/auth-token",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-10-
|
|
4
|
+
"version": "0.1.18-rc.32",
|
|
5
|
+
"generatedAt": "2026-10-05T21:03:06.401Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/auth-token
|
|
9
9
|
|
|
10
10
|
**Layer:** Auth shared
|
|
11
|
-
**Install:** `"@owlmeans/auth-token": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/auth-token": "^0.1.18-rc.32"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
The contract half of long-lived access tokens: the record shape, the route declarations, the
|
|
14
14
|
format helpers, and one client-side guard that presents a token it was handed. The server half —
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** An `Authorization` header taken apart: the scheme lower-cased, the value trimmed. */
|
|
2
|
+
export interface AuthorizationHeader {
|
|
3
|
+
scheme: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
/** How an access token is recognised on the wire and shown back to a person. */
|
|
7
|
+
export interface TokenFormatHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Split an `Authorization` header into its scheme and its value.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately NOT `extractAuthToken` from `@owlmeans/auth-common`: that compares the prefix
|
|
12
|
+
* against `type.toUpperCase()`, so it matches `AUTH-TOKEN` and can never match `Bearer` — the
|
|
13
|
+
* exact spelling every third-party client sends. The scheme comes back lower-cased so a caller
|
|
14
|
+
* compares once.
|
|
15
|
+
*/
|
|
16
|
+
parseAuthorizationHeader: (header: string | string[] | undefined) => AuthorizationHeader | null;
|
|
17
|
+
/** Whether a value looks like an access token this deployment issued. */
|
|
18
|
+
isAccessToken: (value: string | null | undefined, prefix: string) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The half of a token that may be shown again.
|
|
21
|
+
*
|
|
22
|
+
* Prefix plus the first characters of the secret. Enough to tell two tokens apart in a list, and
|
|
23
|
+
* far short of anything that could be replayed.
|
|
24
|
+
*/
|
|
25
|
+
displayOf: (token: string, prefix: string) => string;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/format/types.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd;AAED,gFAAgF;AAChF,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,wBAAwB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,KAAK,mBAAmB,GAAG,IAAI,CAAA;IAC/F,yEAAyE;IACzE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAA;IAC5E;;;;;OAKG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;CACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/format/types.ts"],"names":[],"mappings":""}
|
package/build/format.d.ts
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Deliberately NOT `extractAuthToken` from `@owlmeans/auth-common`: that compares the prefix
|
|
5
|
-
* against `type.toUpperCase()`, so it matches `AUTH-TOKEN` and can never match `Bearer` — the
|
|
6
|
-
* exact spelling every third-party client sends. The scheme comes back lower-cased so a caller
|
|
7
|
-
* compares once.
|
|
8
|
-
*/
|
|
9
|
-
export declare const parseAuthorizationHeader: (header: string | string[] | undefined) => {
|
|
10
|
-
scheme: string;
|
|
11
|
-
value: string;
|
|
12
|
-
} | null;
|
|
13
|
-
/** Whether a value looks like an access token this deployment issued. */
|
|
14
|
-
export declare const isAccessToken: (value: string | null | undefined, prefix: string) => boolean;
|
|
15
|
-
/**
|
|
16
|
-
* The half of a token that may be shown again.
|
|
17
|
-
*
|
|
18
|
-
* Prefix plus the first characters of the secret. Enough to tell two tokens apart in a list, and
|
|
19
|
-
* far short of anything that could be replayed.
|
|
20
|
-
*/
|
|
21
|
-
export declare const displayOf: (token: string, prefix: string) => string;
|
|
1
|
+
import type { TokenFormatHelper } from './format/types.js';
|
|
2
|
+
export declare const createTokenFormatHelper: () => TokenFormatHelper;
|
|
3
|
+
export declare const tokenFormatHelper: TokenFormatHelper;
|
|
22
4
|
//# sourceMappingURL=format.d.ts.map
|
package/build/format.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE/E,eAAO,MAAM,uBAAuB,QAAO,iBA4B1C,CAAA;AAED,eAAO,MAAM,iBAAiB,mBAA4B,CAAA"}
|
package/build/format.js
CHANGED
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
import { AUTH_TOKEN_DISPLAY_LENGTH } from './consts.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
};
|
|
24
|
-
/** Whether a value looks like an access token this deployment issued. */
|
|
25
|
-
export const isAccessToken = (value, prefix) => value != null && value.length > prefix.length && value.startsWith(prefix);
|
|
26
|
-
/**
|
|
27
|
-
* The half of a token that may be shown again.
|
|
28
|
-
*
|
|
29
|
-
* Prefix plus the first characters of the secret. Enough to tell two tokens apart in a list, and
|
|
30
|
-
* far short of anything that could be replayed.
|
|
31
|
-
*/
|
|
32
|
-
export const displayOf = (token, prefix) => {
|
|
33
|
-
const secret = token.startsWith(prefix) ? token.slice(prefix.length) : token;
|
|
34
|
-
return `${prefix}${secret.slice(0, AUTH_TOKEN_DISPLAY_LENGTH)}`;
|
|
2
|
+
export const createTokenFormatHelper = () => {
|
|
3
|
+
const parseAuthorizationHeader = (header) => {
|
|
4
|
+
const raw = Array.isArray(header) ? header[0] : header;
|
|
5
|
+
if (raw == null)
|
|
6
|
+
return null;
|
|
7
|
+
const trimmed = raw.trim();
|
|
8
|
+
const space = trimmed.indexOf(' ');
|
|
9
|
+
if (space < 1)
|
|
10
|
+
return null;
|
|
11
|
+
const scheme = trimmed.slice(0, space).toLowerCase();
|
|
12
|
+
const value = trimmed.slice(space + 1).trim();
|
|
13
|
+
if (value.length < 1)
|
|
14
|
+
return null;
|
|
15
|
+
return { scheme, value };
|
|
16
|
+
};
|
|
17
|
+
const isAccessToken = (value, prefix) => value != null && value.length > prefix.length && value.startsWith(prefix);
|
|
18
|
+
const displayOf = (token, prefix) => {
|
|
19
|
+
const secret = token.startsWith(prefix) ? token.slice(prefix.length) : token;
|
|
20
|
+
return `${prefix}${secret.slice(0, AUTH_TOKEN_DISPLAY_LENGTH)}`;
|
|
21
|
+
};
|
|
22
|
+
return { parseAuthorizationHeader, isAccessToken, displayOf };
|
|
35
23
|
};
|
|
24
|
+
export const tokenFormatHelper = createTokenFormatHelper();
|
|
36
25
|
//# sourceMappingURL=format.js.map
|
package/build/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAGvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAsB,EAAE;IAC7D,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;IACjE,CAAC,CAAA;IAED,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,SAAS,EAAE,CAAA;AAC/D,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,EAAE,CAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,mBAAmB,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,mBAAmB,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -45,7 +45,8 @@ export interface AccessTokenRecord extends ResourceRecord {
|
|
|
45
45
|
audience?: string[];
|
|
46
46
|
}
|
|
47
47
|
/** What a caller may see. The hash never leaves the server. */
|
|
48
|
-
export
|
|
48
|
+
export interface AccessTokenView extends Omit<AccessTokenRecord, 'hash'> {
|
|
49
|
+
}
|
|
49
50
|
export interface CreateAccessToken {
|
|
50
51
|
name: string;
|
|
51
52
|
/** A subset of the caller's own scopes. Defaults to all of them. */
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,c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C,CAAA;IAChD,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAA;IAChC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxC;AAED,MAAM,WAAW,0BAA0B;IACzC,gHAAgH;IAChH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,iEAAiE;AACjE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,kBAAkB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;IAChD,IAAI,EAAE,kBAAkB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAA;IACtD,MAAM,EAAE,kBAAkB,CAAC;QAAE,IAAI,EAAE,iBAAiB,CAAA;KAAE,EAAE,iBAAiB,CAAC,CAAA;IAC1E,MAAM,EAAE,kBAAkB,CAAC;QAAE,MAAM,EAAE,iBAAiB,CAAA;KAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC1E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/auth-token",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.32",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Long-lived access tokens (API keys) on the OwlMeans auth rails — the record shape, the token format, the management entrypoints and the client-side carrier guard.",
|
|
6
6
|
"type": "module",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
27
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
28
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
29
|
-
"@owlmeans/resource": "^0.1.18-rc.
|
|
30
|
-
"@owlmeans/route": "^0.1.18-rc.
|
|
26
|
+
"@owlmeans/auth": "^0.1.18-rc.40",
|
|
27
|
+
"@owlmeans/context": "^0.1.18-rc.34",
|
|
28
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.41",
|
|
29
|
+
"@owlmeans/resource": "^0.1.18-rc.40",
|
|
30
|
+
"@owlmeans/route": "^0.1.18-rc.35"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@owlmeans/dep-config": "workspace:*",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** An `Authorization` header taken apart: the scheme lower-cased, the value trimmed. */
|
|
2
|
+
export interface AuthorizationHeader {
|
|
3
|
+
scheme: string
|
|
4
|
+
value: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** How an access token is recognised on the wire and shown back to a person. */
|
|
8
|
+
export interface TokenFormatHelper {
|
|
9
|
+
/**
|
|
10
|
+
* Split an `Authorization` header into its scheme and its value.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately NOT `extractAuthToken` from `@owlmeans/auth-common`: that compares the prefix
|
|
13
|
+
* against `type.toUpperCase()`, so it matches `AUTH-TOKEN` and can never match `Bearer` — the
|
|
14
|
+
* exact spelling every third-party client sends. The scheme comes back lower-cased so a caller
|
|
15
|
+
* compares once.
|
|
16
|
+
*/
|
|
17
|
+
parseAuthorizationHeader: (header: string | string[] | undefined) => AuthorizationHeader | null
|
|
18
|
+
/** Whether a value looks like an access token this deployment issued. */
|
|
19
|
+
isAccessToken: (value: string | null | undefined, prefix: string) => boolean
|
|
20
|
+
/**
|
|
21
|
+
* The half of a token that may be shown again.
|
|
22
|
+
*
|
|
23
|
+
* Prefix plus the first characters of the secret. Enough to tell two tokens apart in a list, and
|
|
24
|
+
* far short of anything that could be replayed.
|
|
25
|
+
*/
|
|
26
|
+
displayOf: (token: string, prefix: string) => string
|
|
27
|
+
}
|
package/src/format.ts
CHANGED
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
import { AUTH_TOKEN_DISPLAY_LENGTH } from './consts.js'
|
|
2
|
+
import type { AuthorizationHeader, TokenFormatHelper } from './format/types.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const trimmed = raw.trim()
|
|
18
|
-
const space = trimmed.indexOf(' ')
|
|
19
|
-
if (space < 1) return null
|
|
20
|
-
|
|
21
|
-
const scheme = trimmed.slice(0, space).toLowerCase()
|
|
22
|
-
const value = trimmed.slice(space + 1).trim()
|
|
23
|
-
if (value.length < 1) return null
|
|
24
|
-
|
|
25
|
-
return { scheme, value }
|
|
26
|
-
}
|
|
4
|
+
export const createTokenFormatHelper = (): TokenFormatHelper => {
|
|
5
|
+
const parseAuthorizationHeader = (
|
|
6
|
+
header: string | string[] | undefined
|
|
7
|
+
): AuthorizationHeader | null => {
|
|
8
|
+
const raw = Array.isArray(header) ? header[0] : header
|
|
9
|
+
if (raw == null) return null
|
|
10
|
+
|
|
11
|
+
const trimmed = raw.trim()
|
|
12
|
+
const space = trimmed.indexOf(' ')
|
|
13
|
+
if (space < 1) return null
|
|
14
|
+
|
|
15
|
+
const scheme = trimmed.slice(0, space).toLowerCase()
|
|
16
|
+
const value = trimmed.slice(space + 1).trim()
|
|
17
|
+
if (value.length < 1) return null
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value != null && value.length > prefix.length && value.startsWith(prefix)
|
|
19
|
+
return { scheme, value }
|
|
20
|
+
}
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
* Prefix plus the first characters of the secret. Enough to tell two tokens apart in a list, and
|
|
36
|
-
* far short of anything that could be replayed.
|
|
37
|
-
*/
|
|
38
|
-
export const displayOf = (token: string, prefix: string): string => {
|
|
39
|
-
const secret = token.startsWith(prefix) ? token.slice(prefix.length) : token
|
|
22
|
+
const isAccessToken = (value: string | null | undefined, prefix: string): boolean =>
|
|
23
|
+
value != null && value.length > prefix.length && value.startsWith(prefix)
|
|
40
24
|
|
|
41
|
-
|
|
25
|
+
const displayOf = (token: string, prefix: string): string => {
|
|
26
|
+
const secret = token.startsWith(prefix) ? token.slice(prefix.length) : token
|
|
27
|
+
|
|
28
|
+
return `${prefix}${secret.slice(0, AUTH_TOKEN_DISPLAY_LENGTH)}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { parseAuthorizationHeader, isAccessToken, displayOf }
|
|
42
32
|
}
|
|
33
|
+
|
|
34
|
+
export const tokenFormatHelper = createTokenFormatHelper()
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -47,7 +47,7 @@ export interface AccessTokenRecord extends ResourceRecord {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** What a caller may see. The hash never leaves the server. */
|
|
50
|
-
export
|
|
50
|
+
export interface AccessTokenView extends Omit<AccessTokenRecord, 'hash'> {}
|
|
51
51
|
|
|
52
52
|
export interface CreateAccessToken {
|
|
53
53
|
name: string
|
package/tests/format.spec.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import {
|
|
2
|
+
import { tokenFormatHelper } from '../src/format.js'
|
|
3
3
|
import { AUTH_TOKEN_DEFAULT_PREFIX } from '../src/consts.js'
|
|
4
4
|
|
|
5
5
|
describe('@owlmeans/auth-token — Authorization parsing', () => {
|
|
6
6
|
test('lower-cases the scheme so Bearer and BEARER are one answer', () => {
|
|
7
|
-
expect(parseAuthorizationHeader('Bearer owl_abc')).toEqual({ scheme: 'bearer', value: 'owl_abc' })
|
|
8
|
-
expect(parseAuthorizationHeader('BEARER owl_abc')?.scheme).toBe('bearer')
|
|
9
|
-
expect(parseAuthorizationHeader('AUTH-TOKEN owl_abc')?.scheme).toBe('auth-token')
|
|
7
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('Bearer owl_abc')).toEqual({ scheme: 'bearer', value: 'owl_abc' })
|
|
8
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('BEARER owl_abc')?.scheme).toBe('bearer')
|
|
9
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('AUTH-TOKEN owl_abc')?.scheme).toBe('auth-token')
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
test('takes the first header when a proxy folded several', () => {
|
|
13
|
-
expect(parseAuthorizationHeader(['Bearer one', 'Bearer two'])?.value).toBe('one')
|
|
13
|
+
expect(tokenFormatHelper.parseAuthorizationHeader(['Bearer one', 'Bearer two'])?.value).toBe('one')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
test('answers null for anything that is not a scheme and a value', () => {
|
|
17
|
-
expect(parseAuthorizationHeader(undefined)).toBeNull()
|
|
18
|
-
expect(parseAuthorizationHeader('')).toBeNull()
|
|
19
|
-
expect(parseAuthorizationHeader('Bearer')).toBeNull()
|
|
20
|
-
expect(parseAuthorizationHeader('Bearer ')).toBeNull()
|
|
21
|
-
expect(parseAuthorizationHeader(' leadingspace')).toBeNull()
|
|
17
|
+
expect(tokenFormatHelper.parseAuthorizationHeader(undefined)).toBeNull()
|
|
18
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('')).toBeNull()
|
|
19
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('Bearer')).toBeNull()
|
|
20
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('Bearer ')).toBeNull()
|
|
21
|
+
expect(tokenFormatHelper.parseAuthorizationHeader(' leadingspace')).toBeNull()
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
test('keeps a value that itself contains spaces', () => {
|
|
25
|
-
expect(parseAuthorizationHeader('Bearer a b c')?.value).toBe('a b c')
|
|
25
|
+
expect(tokenFormatHelper.parseAuthorizationHeader('Bearer a b c')?.value).toBe('a b c')
|
|
26
26
|
})
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
describe('@owlmeans/auth-token — token shape', () => {
|
|
30
30
|
test('claims only a value carrying the prefix', () => {
|
|
31
|
-
expect(isAccessToken('owl_abcdef', AUTH_TOKEN_DEFAULT_PREFIX)).toBe(true)
|
|
32
|
-
expect(isAccessToken('vib_abcdef', AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
33
|
-
expect(isAccessToken('abcdef', AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
31
|
+
expect(tokenFormatHelper.isAccessToken('owl_abcdef', AUTH_TOKEN_DEFAULT_PREFIX)).toBe(true)
|
|
32
|
+
expect(tokenFormatHelper.isAccessToken('vib_abcdef', AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
33
|
+
expect(tokenFormatHelper.isAccessToken('abcdef', AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
34
34
|
// The prefix alone is not a token — there is no secret behind it.
|
|
35
|
-
expect(isAccessToken(AUTH_TOKEN_DEFAULT_PREFIX, AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
36
|
-
expect(isAccessToken(null, AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
35
|
+
expect(tokenFormatHelper.isAccessToken(AUTH_TOKEN_DEFAULT_PREFIX, AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
36
|
+
expect(tokenFormatHelper.isAccessToken(null, AUTH_TOKEN_DEFAULT_PREFIX)).toBe(false)
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
test('the display form keeps the prefix and eight characters of the secret', () => {
|
|
40
|
-
const display = displayOf('owl_ABCDEFGHIJKLMNOP', 'owl_')
|
|
40
|
+
const display = tokenFormatHelper.displayOf('owl_ABCDEFGHIJKLMNOP', 'owl_')
|
|
41
41
|
expect(display).toBe('owl_ABCDEFGH')
|
|
42
42
|
// Short enough to be useless, long enough to tell two of a person's tokens apart.
|
|
43
43
|
expect(display.length).toBeLessThan('owl_ABCDEFGHIJKLMNOP'.length)
|