@smartsoft001/fb 2.198.0 → 2.199.0
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 +5 -0
- package/package.json +1 -1
- package/src/lib/fb.service.d.ts +5 -0
- package/src/lib/fb.service.js +20 -4
- package/src/lib/fb.service.js.map +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,11 @@ and a non-empty `data.user_id`. `getData` additionally requires the `/me` id to
|
|
|
39
39
|
`user_id`. An empty `appIds`, a missing app id or secret, or an empty token or one longer than 8192
|
|
40
40
|
characters fails closed before any request is made.
|
|
41
41
|
|
|
42
|
+
`getData` signs its `/me` request with `appsecret_proof`, the hex HMAC-SHA256 of the user access
|
|
43
|
+
token keyed with the app secret, when the token was issued to the app in `credentials`. A token of
|
|
44
|
+
another app in `appIds` has no configured secret, so its `/me` request goes without a proof, as
|
|
45
|
+
before. Neither the secret nor the proof is logged.
|
|
46
|
+
|
|
42
47
|
Every failure is an `UnauthorizedException`. The token and the app access token are URL-encoded, and
|
|
43
48
|
HTTP errors are replaced with `Invalid Facebook token`, so request URLs that carry the token and the
|
|
44
49
|
app secret never reach logs.
|
package/package.json
CHANGED
package/src/lib/fb.service.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export declare class FbService {
|
|
|
16
16
|
id: string;
|
|
17
17
|
email: string;
|
|
18
18
|
}>;
|
|
19
|
+
/**
|
|
20
|
+
* `&appsecret_proof=<HMAC-SHA256(token, appSecret)>` signed with the secret of the app the
|
|
21
|
+
* token was issued to, or an empty string when that app's secret is not configured.
|
|
22
|
+
*/
|
|
23
|
+
private appSecretProof;
|
|
19
24
|
/** Asks `debug_token` whether the token is valid and which app it was issued to. */
|
|
20
25
|
private verify;
|
|
21
26
|
private request;
|
package/src/lib/fb.service.js
CHANGED
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const axios_1 = require("@nestjs/axios");
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
7
|
const rxjs_1 = require("rxjs");
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
9
|
const GRAPH = 'https://graph.facebook.com';
|
|
9
10
|
const INVALID_TOKEN = 'Invalid Facebook token';
|
|
10
11
|
let FbService = class FbService {
|
|
@@ -17,16 +18,31 @@ let FbService = class FbService {
|
|
|
17
18
|
* `appIds` and `credentials` come from server configuration, never from a request.
|
|
18
19
|
*/
|
|
19
20
|
async getUserId(token, appIds, credentials) {
|
|
20
|
-
|
|
21
|
+
const { userId } = await this.verify(token, appIds, credentials);
|
|
22
|
+
return userId;
|
|
21
23
|
}
|
|
22
24
|
async getData(token, appIds, credentials) {
|
|
23
|
-
const userId = await this.verify(token, appIds, credentials);
|
|
24
|
-
const data = await this.request(`${GRAPH}/me?fields=email,id&access_token=${encodeURIComponent(token)}`
|
|
25
|
+
const { userId, appId } = await this.verify(token, appIds, credentials);
|
|
26
|
+
const data = await this.request(`${GRAPH}/me?fields=email,id&access_token=${encodeURIComponent(token)}` +
|
|
27
|
+
this.appSecretProof(token, appId, credentials));
|
|
25
28
|
if (!data || data.id !== userId) {
|
|
26
29
|
throw new common_1.UnauthorizedException(INVALID_TOKEN);
|
|
27
30
|
}
|
|
28
31
|
return data;
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* `&appsecret_proof=<HMAC-SHA256(token, appSecret)>` signed with the secret of the app the
|
|
35
|
+
* token was issued to, or an empty string when that app's secret is not configured.
|
|
36
|
+
*/
|
|
37
|
+
appSecretProof(token, appId, credentials) {
|
|
38
|
+
if (credentials.appId !== appId || !credentials.appSecret) {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
const proof = (0, node_crypto_1.createHmac)('sha256', credentials.appSecret)
|
|
42
|
+
.update(token)
|
|
43
|
+
.digest('hex');
|
|
44
|
+
return `&appsecret_proof=${proof}`;
|
|
45
|
+
}
|
|
30
46
|
/** Asks `debug_token` whether the token is valid and which app it was issued to. */
|
|
31
47
|
async verify(token, appIds, credentials) {
|
|
32
48
|
if (!token ||
|
|
@@ -48,7 +64,7 @@ let FbService = class FbService {
|
|
|
48
64
|
!data.user_id) {
|
|
49
65
|
throw new common_1.UnauthorizedException(INVALID_TOKEN);
|
|
50
66
|
}
|
|
51
|
-
return data.user_id;
|
|
67
|
+
return { userId: data.user_id, appId: data.app_id };
|
|
52
68
|
}
|
|
53
69
|
async request(url) {
|
|
54
70
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fb.service.js","sourceRoot":"","sources":["../../../../../../packages/shared/fb/src/lib/fb.service.ts"],"names":[],"mappings":";;;;AAAA,yCAA4C;AAC5C,2CAAmE;AACnE,+BAAsC;
|
|
1
|
+
{"version":3,"file":"fb.service.js","sourceRoot":"","sources":["../../../../../../packages/shared/fb/src/lib/fb.service.ts"],"names":[],"mappings":";;;;AAAA,yCAA4C;AAC5C,2CAAmE;AACnE,+BAAsC;AAEtC,6CAAyC;AAQzC,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAC3C,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAGxC,IAAM,SAAS,GAAf,MAAM,SAAS;IACA;IAApB,YAAoB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;IAAG,CAAC;IAEzC;;;OAGG;IACH,KAAK,CAAC,SAAS,CACb,KAAa,EACb,MAAyB,EACzB,WAA8B;QAE9B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACjE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAa,EACb,MAAyB,EACzB,WAA8B;QAE9B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACxE,MAAM,IAAI,GAAG,MAAM,IAAI,CA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