@ttoss/http-server-auth 0.3.3 → 0.3.5
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/dist/index.cjs +15 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +15 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -76,8 +76,22 @@ var trySystem = (token, opts) => {
|
|
|
76
76
|
};
|
|
77
77
|
/** Sentinel: token verified but missing a required scope → 403, not 401. */
|
|
78
78
|
var FORBIDDEN = Symbol("forbidden");
|
|
79
|
+
/**
|
|
80
|
+
* Derives a space-separated scope string from the payload.
|
|
81
|
+
* Accepts either `scope: string` (standard JWT claim) or `scopes: string[]`
|
|
82
|
+
* (a common alternative shape). Returns `null` when neither is present.
|
|
83
|
+
*/
|
|
84
|
+
var resolveScopeString = payload => {
|
|
85
|
+
if (typeof payload.scope === "string") return payload.scope;
|
|
86
|
+
if (Array.isArray(payload.scopes) && payload.scopes.every(s => {
|
|
87
|
+
return typeof s === "string";
|
|
88
|
+
})) return payload.scopes.join(" ");
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
79
91
|
var hasRequiredScopes = (requiredScopes, payload) => {
|
|
80
|
-
const
|
|
92
|
+
const scopeString = resolveScopeString(payload);
|
|
93
|
+
if (scopeString === null) return false;
|
|
94
|
+
const tokenScopes = scopeString ? scopeString.split(" ") : [];
|
|
81
95
|
return requiredScopes.every(s => {
|
|
82
96
|
return tokenScopes.includes(s);
|
|
83
97
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -52,8 +52,9 @@ type OAuthOptions = {
|
|
|
52
52
|
*/
|
|
53
53
|
mapPayload?: (payload: Record<string, unknown>, ctx: Context) => AuthenticatedUser | null;
|
|
54
54
|
/**
|
|
55
|
-
* Scopes that must all be present on the token
|
|
56
|
-
*
|
|
55
|
+
* Scopes that must all be present on the token, else `403`.
|
|
56
|
+
* `verify` may return either `scope: string` (space-separated JWT claim) or
|
|
57
|
+
* `scopes: string[]`; both are normalised internally.
|
|
57
58
|
*/
|
|
58
59
|
requiredScopes?: string[];
|
|
59
60
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -52,8 +52,9 @@ type OAuthOptions = {
|
|
|
52
52
|
*/
|
|
53
53
|
mapPayload?: (payload: Record<string, unknown>, ctx: Context) => AuthenticatedUser | null;
|
|
54
54
|
/**
|
|
55
|
-
* Scopes that must all be present on the token
|
|
56
|
-
*
|
|
55
|
+
* Scopes that must all be present on the token, else `403`.
|
|
56
|
+
* `verify` may return either `scope: string` (space-separated JWT claim) or
|
|
57
|
+
* `scopes: string[]`; both are normalised internally.
|
|
57
58
|
*/
|
|
58
59
|
requiredScopes?: string[];
|
|
59
60
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -45,8 +45,22 @@ var trySystem = (token, opts) => {
|
|
|
45
45
|
};
|
|
46
46
|
/** Sentinel: token verified but missing a required scope → 403, not 401. */
|
|
47
47
|
var FORBIDDEN = Symbol("forbidden");
|
|
48
|
+
/**
|
|
49
|
+
* Derives a space-separated scope string from the payload.
|
|
50
|
+
* Accepts either `scope: string` (standard JWT claim) or `scopes: string[]`
|
|
51
|
+
* (a common alternative shape). Returns `null` when neither is present.
|
|
52
|
+
*/
|
|
53
|
+
var resolveScopeString = payload => {
|
|
54
|
+
if (typeof payload.scope === "string") return payload.scope;
|
|
55
|
+
if (Array.isArray(payload.scopes) && payload.scopes.every(s => {
|
|
56
|
+
return typeof s === "string";
|
|
57
|
+
})) return payload.scopes.join(" ");
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
48
60
|
var hasRequiredScopes = (requiredScopes, payload) => {
|
|
49
|
-
const
|
|
61
|
+
const scopeString = resolveScopeString(payload);
|
|
62
|
+
if (scopeString === null) return false;
|
|
63
|
+
const tokenScopes = scopeString ? scopeString.split(" ") : [];
|
|
50
64
|
return requiredScopes.every(s => {
|
|
51
65
|
return tokenScopes.includes(s);
|
|
52
66
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/http-server-auth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Authentication middleware for @ttoss/http-server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@ttoss/auth-core": "^0.
|
|
35
|
+
"@ttoss/auth-core": "^0.8.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/koa": "^3.0.3",
|
|
39
39
|
"jest": "^30.4.2",
|
|
40
40
|
"supertest": "^7.2.2",
|
|
41
41
|
"tsdown": "^0.22.2",
|
|
42
|
-
"@ttoss/
|
|
43
|
-
"@ttoss/
|
|
42
|
+
"@ttoss/config": "^1.37.17",
|
|
43
|
+
"@ttoss/http-server": "^0.7.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@ttoss/http-server": "^0.7.1"
|