@twin.org/api-auth-entity-storage-service 0.0.1-next.28 → 0.0.1-next.29
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/cjs/index.cjs +3 -15
- package/dist/esm/index.mjs +4 -16
- package/dist/types/utils/tokenHelper.d.ts +1 -1
- package/docs/changelog.md +1 -1
- package/locales/en.json +0 -1
- package/package.json +4 -4
package/dist/cjs/index.cjs
CHANGED
@@ -76,11 +76,7 @@ class TokenHelper {
|
|
76
76
|
const jwt = await web.Jwt.encodeWithSigner({ alg: "EdDSA" }, {
|
77
77
|
sub: subject,
|
78
78
|
exp: nowSeconds + ttlSeconds
|
79
|
-
}, async (header, payload) =>
|
80
|
-
const signingBytes = web.Jwt.toSigningBytes(header, payload);
|
81
|
-
const signatureBytes = await vaultConnector.sign(signingKeyName, signingBytes);
|
82
|
-
return web.Jwt.tokenFromBytes(signingBytes, signatureBytes);
|
83
|
-
});
|
79
|
+
}, async (header, payload) => vaultModels.VaultConnectorHelper.jwtSigner(vaultConnector, signingKeyName, header, payload));
|
84
80
|
return {
|
85
81
|
token: jwt,
|
86
82
|
expiry: (nowSeconds + ttlSeconds) * 1000
|
@@ -98,16 +94,8 @@ class TokenHelper {
|
|
98
94
|
if (!core.Is.stringValue(token)) {
|
99
95
|
throw new core.UnauthorizedError(this._CLASS_NAME, "missing");
|
100
96
|
}
|
101
|
-
const decoded = await web.Jwt.verifyWithVerifier(token, async (t) =>
|
102
|
-
|
103
|
-
const verified = await vaultConnector.verify(signingKeyName, signingBytes, signature);
|
104
|
-
if (!verified) {
|
105
|
-
throw new core.UnauthorizedError(this._CLASS_NAME, "invalidSignature");
|
106
|
-
}
|
107
|
-
return web.Jwt.fromSigningBytes(signingBytes);
|
108
|
-
});
|
109
|
-
// If the signature validation failed or some of the header/payload data
|
110
|
-
// is not properly populated then it is unauthorized.
|
97
|
+
const decoded = await web.Jwt.verifyWithVerifier(token, async (t) => vaultModels.VaultConnectorHelper.jwtVerifier(vaultConnector, signingKeyName, t));
|
98
|
+
// If some of the header/payload data is not properly populated then it is unauthorized.
|
111
99
|
if (!core.Is.stringValue(decoded.payload.sub)) {
|
112
100
|
throw new core.UnauthorizedError(this._CLASS_NAME, "payloadMissingSubject");
|
113
101
|
}
|
package/dist/esm/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { property, entity, EntitySchemaFactory, EntitySchemaHelper } from '@twin.org/entity';
|
2
2
|
import { HttpErrorHelper } from '@twin.org/api-models';
|
3
3
|
import { Is, UnauthorizedError, Guards, BaseError, ComponentFactory, Converter, GeneralError } from '@twin.org/core';
|
4
|
-
import { VaultConnectorFactory } from '@twin.org/vault-models';
|
4
|
+
import { VaultConnectorHelper, VaultConnectorFactory } from '@twin.org/vault-models';
|
5
5
|
import { Jwt, HeaderTypes, HttpStatusCode } from '@twin.org/web';
|
6
6
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
7
7
|
import { Blake2b } from '@twin.org/crypto';
|
@@ -74,11 +74,7 @@ class TokenHelper {
|
|
74
74
|
const jwt = await Jwt.encodeWithSigner({ alg: "EdDSA" }, {
|
75
75
|
sub: subject,
|
76
76
|
exp: nowSeconds + ttlSeconds
|
77
|
-
}, async (header, payload) =>
|
78
|
-
const signingBytes = Jwt.toSigningBytes(header, payload);
|
79
|
-
const signatureBytes = await vaultConnector.sign(signingKeyName, signingBytes);
|
80
|
-
return Jwt.tokenFromBytes(signingBytes, signatureBytes);
|
81
|
-
});
|
77
|
+
}, async (header, payload) => VaultConnectorHelper.jwtSigner(vaultConnector, signingKeyName, header, payload));
|
82
78
|
return {
|
83
79
|
token: jwt,
|
84
80
|
expiry: (nowSeconds + ttlSeconds) * 1000
|
@@ -96,16 +92,8 @@ class TokenHelper {
|
|
96
92
|
if (!Is.stringValue(token)) {
|
97
93
|
throw new UnauthorizedError(this._CLASS_NAME, "missing");
|
98
94
|
}
|
99
|
-
const decoded = await Jwt.verifyWithVerifier(token, async (t) =>
|
100
|
-
|
101
|
-
const verified = await vaultConnector.verify(signingKeyName, signingBytes, signature);
|
102
|
-
if (!verified) {
|
103
|
-
throw new UnauthorizedError(this._CLASS_NAME, "invalidSignature");
|
104
|
-
}
|
105
|
-
return Jwt.fromSigningBytes(signingBytes);
|
106
|
-
});
|
107
|
-
// If the signature validation failed or some of the header/payload data
|
108
|
-
// is not properly populated then it is unauthorized.
|
95
|
+
const decoded = await Jwt.verifyWithVerifier(token, async (t) => VaultConnectorHelper.jwtVerifier(vaultConnector, signingKeyName, t));
|
96
|
+
// If some of the header/payload data is not properly populated then it is unauthorized.
|
109
97
|
if (!Is.stringValue(decoded.payload.sub)) {
|
110
98
|
throw new UnauthorizedError(this._CLASS_NAME, "payloadMissingSubject");
|
111
99
|
}
|
package/docs/changelog.md
CHANGED
package/locales/en.json
CHANGED
@@ -11,7 +11,6 @@
|
|
11
11
|
},
|
12
12
|
"tokenHelper": {
|
13
13
|
"missing": "The JSON Web token could not be found in the authorization header",
|
14
|
-
"invalidSignature": "The JSON Web token signature could not be validated",
|
15
14
|
"payloadMissingSubject": "The JSON Web token payload does not contain a subject",
|
16
15
|
"expired": "The JSON Web token has expired"
|
17
16
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@twin.org/api-auth-entity-storage-service",
|
3
|
-
"version": "0.0.1-next.
|
3
|
+
"version": "0.0.1-next.29",
|
4
4
|
"description": "Auth Entity Storage contract implementation and REST endpoint definitions",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -14,9 +14,9 @@
|
|
14
14
|
"node": ">=20.0.0"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@twin.org/api-auth-entity-storage-models": "0.0.1-next.
|
18
|
-
"@twin.org/api-core": "0.0.1-next.
|
19
|
-
"@twin.org/api-models": "0.0.1-next.
|
17
|
+
"@twin.org/api-auth-entity-storage-models": "0.0.1-next.29",
|
18
|
+
"@twin.org/api-core": "0.0.1-next.29",
|
19
|
+
"@twin.org/api-models": "0.0.1-next.29",
|
20
20
|
"@twin.org/core": "next",
|
21
21
|
"@twin.org/crypto": "next",
|
22
22
|
"@twin.org/entity": "next",
|