@nauth-toolkit/social-facebook 0.1.13 → 0.1.17
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/nestjs/facebook-social-auth.module.d.ts +37 -0
- package/dist/nestjs/facebook-social-auth.module.d.ts.map +1 -1
- package/dist/nestjs/facebook-social-auth.module.js +48 -4
- package/dist/nestjs/facebook-social-auth.module.js.map +1 -1
- package/dist/nestjs/index.d.ts +5 -0
- package/dist/nestjs/index.d.ts.map +1 -1
- package/dist/nestjs/index.js +6 -0
- package/dist/nestjs/index.js.map +1 -1
- package/dist/src/dto/social-login.dto.d.ts +219 -0
- package/dist/src/dto/social-login.dto.d.ts.map +1 -1
- package/dist/src/dto/social-login.dto.js +219 -0
- package/dist/src/dto/social-login.dto.js.map +1 -1
- package/dist/src/facebook-oauth.client.d.ts +59 -0
- package/dist/src/facebook-oauth.client.d.ts.map +1 -1
- package/dist/src/facebook-oauth.client.js +66 -2
- package/dist/src/facebook-oauth.client.js.map +1 -1
- package/dist/src/facebook-social-auth.service.d.ts +59 -1
- package/dist/src/facebook-social-auth.service.d.ts.map +1 -1
- package/dist/src/facebook-social-auth.service.js +82 -3
- package/dist/src/facebook-social-auth.service.js.map +1 -1
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/token-verifier.service.d.ts +40 -0
- package/dist/src/token-verifier.service.d.ts.map +1 -1
- package/dist/src/token-verifier.service.js +44 -0
- package/dist/src/token-verifier.service.js.map +1 -1
- package/dist/src/verified-token-profile.interface.d.ts +21 -0
- package/dist/src/verified-token-profile.interface.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,24 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FacebookSocialAuthService = void 0;
|
|
4
|
+
// Public API imports
|
|
4
5
|
const core_1 = require("@nauth-toolkit/core");
|
|
6
|
+
// Internal API imports (for provider implementations)
|
|
5
7
|
const internal_1 = require("@nauth-toolkit/core/internal");
|
|
6
8
|
const facebook_oauth_client_1 = require("./facebook-oauth.client");
|
|
7
9
|
const token_verifier_service_1 = require("./token-verifier.service");
|
|
10
|
+
/**
|
|
11
|
+
* Facebook Social Authentication Service (Platform-Agnostic)
|
|
12
|
+
*
|
|
13
|
+
* Handles Facebook OAuth flow including:
|
|
14
|
+
* - OAuth web flow (redirect-based)
|
|
15
|
+
* - Native mobile token verification
|
|
16
|
+
* - Account linking
|
|
17
|
+
*
|
|
18
|
+
* This is a plain TypeScript class with no framework dependencies.
|
|
19
|
+
* Use `@nauth-toolkit/social-facebook/nestjs` for NestJS integration.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Direct instantiation (platform-agnostic)
|
|
24
|
+
* const facebookAuth = new FacebookSocialAuthService(
|
|
25
|
+
* config,
|
|
26
|
+
* logger,
|
|
27
|
+
* authService,
|
|
28
|
+
* socialAuthService,
|
|
29
|
+
* jwtService,
|
|
30
|
+
* sessionService,
|
|
31
|
+
* challengeHelper,
|
|
32
|
+
* clientInfoService,
|
|
33
|
+
* auditService,
|
|
34
|
+
* stateStore,
|
|
35
|
+
* phoneVerificationService,
|
|
36
|
+
* tokenVerifier
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
8
40
|
class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService {
|
|
9
41
|
providerName = 'facebook';
|
|
10
42
|
oauthClient;
|
|
11
43
|
tokenVerifier;
|
|
12
|
-
constructor(config, logger, authService, socialAuthService, jwtService, sessionService, challengeHelper, clientInfoService,
|
|
44
|
+
constructor(config, logger, authService, socialAuthService, jwtService, sessionService, challengeHelper, clientInfoService,
|
|
45
|
+
// State store shared across all providers
|
|
46
|
+
stateStore, userRepository,
|
|
47
|
+
// Phone verification service (optional - only available when SMS provider is configured)
|
|
48
|
+
phoneVerificationService,
|
|
49
|
+
// Audit service (optional - only available when auditLogs.enabled is true)
|
|
50
|
+
auditService,
|
|
51
|
+
// Trusted device service (optional - only available when rememberDevices is enabled)
|
|
52
|
+
trustedDeviceService,
|
|
53
|
+
// Facebook-specific token verifier (optional, fallback to default)
|
|
54
|
+
tokenVerifier) {
|
|
13
55
|
super(config, logger, authService, socialAuthService, jwtService, sessionService, challengeHelper, clientInfoService, stateStore, userRepository, phoneVerificationService, auditService, trustedDeviceService);
|
|
56
|
+
// Initialize Facebook OAuth client
|
|
14
57
|
const providerConfig = this.getProviderConfig();
|
|
15
58
|
if (!providerConfig || !providerConfig.enabled) {
|
|
16
59
|
this.oauthClient = null;
|
|
17
60
|
this.tokenVerifier = null;
|
|
18
|
-
return;
|
|
61
|
+
return; // Exit constructor early if disabled
|
|
19
62
|
}
|
|
20
63
|
const webClientId = Array.isArray(providerConfig.clientId) ? providerConfig.clientId[0] : providerConfig.clientId;
|
|
21
64
|
if (!webClientId || !providerConfig.clientSecret) {
|
|
65
|
+
// Schema validation should catch this, but handle gracefully
|
|
22
66
|
this.oauthClient = null;
|
|
23
67
|
this.tokenVerifier = null;
|
|
24
68
|
return;
|
|
@@ -29,6 +73,7 @@ class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService
|
|
|
29
73
|
redirectUri: providerConfig.callbackUrl || '',
|
|
30
74
|
scopes: providerConfig.scopes || ['email', 'public_profile'],
|
|
31
75
|
});
|
|
76
|
+
// Use provided token verifier or create default one
|
|
32
77
|
this.tokenVerifier =
|
|
33
78
|
tokenVerifier ||
|
|
34
79
|
new token_verifier_service_1.TokenVerifierService(config) ||
|
|
@@ -36,6 +81,12 @@ class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService
|
|
|
36
81
|
null;
|
|
37
82
|
this.logger?.debug?.('FacebookSocialAuthService initialized');
|
|
38
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate OAuth authorization URL for Facebook
|
|
86
|
+
*
|
|
87
|
+
* @param state - Optional state parameter for CSRF protection
|
|
88
|
+
* @returns Authorization URL for redirecting user to Facebook
|
|
89
|
+
*/
|
|
39
90
|
async getAuthUrl(state) {
|
|
40
91
|
if (!this.oauthClient) {
|
|
41
92
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_CONFIG_MISSING, 'Facebook OAuth is not enabled');
|
|
@@ -43,6 +94,16 @@ class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService
|
|
|
43
94
|
const finalState = state || this.generateState();
|
|
44
95
|
return this.oauthClient.getAuthorizationUrl(finalState);
|
|
45
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Get OAuth user profile from callback
|
|
99
|
+
*
|
|
100
|
+
* Exchanges authorization code for access token and fetches user profile.
|
|
101
|
+
*
|
|
102
|
+
* @param code - Authorization code from Facebook OAuth callback
|
|
103
|
+
* @param _state - State parameter (validated by base class)
|
|
104
|
+
* @returns User profile from Facebook
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
46
107
|
async getOAuthProfile(code, _state) {
|
|
47
108
|
if (!this.oauthClient) {
|
|
48
109
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_CONFIG_MISSING, 'Facebook OAuth is not enabled');
|
|
@@ -51,9 +112,22 @@ class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService
|
|
|
51
112
|
if (!providerConfig || !providerConfig.callbackUrl) {
|
|
52
113
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_CONFIG_MISSING, 'Facebook OAuth callback URL is not configured');
|
|
53
114
|
}
|
|
115
|
+
// Exchange code for access token
|
|
54
116
|
const tokens = await this.oauthClient.exchangeCodeForToken(code, providerConfig.callbackUrl);
|
|
117
|
+
// Get user profile from Facebook
|
|
55
118
|
return await this.oauthClient.getUserProfile(tokens.accessToken);
|
|
56
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Verify Facebook access token from native mobile apps
|
|
122
|
+
*
|
|
123
|
+
* Facebook uses access tokens (not ID tokens) from native SDKs
|
|
124
|
+
*
|
|
125
|
+
* @param accessToken - Facebook access token from native SDK (passed as idToken parameter)
|
|
126
|
+
* @param _idToken - Not used for Facebook (Facebook uses access tokens)
|
|
127
|
+
* @param profileData - Optional profile data from native SDK
|
|
128
|
+
* @returns User profile from verified token
|
|
129
|
+
* @protected
|
|
130
|
+
*/
|
|
57
131
|
async verifyNativeToken(idToken, _accessToken, profileData) {
|
|
58
132
|
if (!this.tokenVerifier) {
|
|
59
133
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_CONFIG_MISSING, 'Facebook OAuth is not enabled');
|
|
@@ -67,12 +141,17 @@ class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService
|
|
|
67
141
|
if (!this.tokenVerifier.verifyFacebookToken) {
|
|
68
142
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_CONFIG_MISSING, 'Facebook token verifier is not available');
|
|
69
143
|
}
|
|
144
|
+
// For Facebook, the idToken parameter actually contains the access token
|
|
145
|
+
// Facebook native SDKs return access tokens, not ID tokens
|
|
70
146
|
const accessToken = idToken;
|
|
147
|
+
// Verify access token with Facebook's Graph API
|
|
71
148
|
const verified = (await this.tokenVerifier.verifyFacebookToken(accessToken, appId, appSecret));
|
|
72
149
|
this.logger?.debug?.(`Verified Facebook token for: ${verified.email || verified.id}`);
|
|
150
|
+
// CRITICAL: Require email from all social providers for signup
|
|
73
151
|
if (!verified.email) {
|
|
74
152
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_EMAIL_REQUIRED, 'Email is required from Facebook. Please grant email permissions.');
|
|
75
153
|
}
|
|
154
|
+
// Handle profile data from native SDK if available
|
|
76
155
|
const profileDataTyped = profileData;
|
|
77
156
|
return {
|
|
78
157
|
id: verified.id,
|
|
@@ -80,7 +159,7 @@ class FacebookSocialAuthService extends internal_1.BaseSocialAuthProviderService
|
|
|
80
159
|
firstName: verified.first_name || profileDataTyped?.firstName || null,
|
|
81
160
|
lastName: verified.last_name || profileDataTyped?.lastName || null,
|
|
82
161
|
picture: verified.picture?.data?.url || profileDataTyped?.picture || null,
|
|
83
|
-
verified: true,
|
|
162
|
+
verified: true, // Email is verified if provided by Facebook
|
|
84
163
|
raw: {
|
|
85
164
|
id: verified.id,
|
|
86
165
|
email: verified.email,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facebook-social-auth.service.js","sourceRoot":"","sources":["../../src/facebook-social-auth.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"facebook-social-auth.service.js","sourceRoot":"","sources":["../../src/facebook-social-auth.service.ts"],"names":[],"mappings":";;;AAAA,qBAAqB;AACrB,8CAa6B;AAC7B,sDAAsD;AACtD,2DAOsC;AAEtC,mEAA8D;AAC9D,qEAAgG;AAGhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,yBAA0B,SAAQ,wCAA6B;IACjE,YAAY,GAAG,UAAU,CAAC;IAClB,WAAW,CAA6B;IACxC,aAAa,CAA+B;IAE7D,YACE,MAAmB,EACnB,MAAmB,EACnB,WAAwB,EACxB,iBAAoC,EACpC,UAAsB,EACtB,cAA8B,EAC9B,eAA2C,EAC3C,iBAAoC;IACpC,0CAA0C;IAC1C,UAAgE,EAChE,cAAoC;IACpC,yFAAyF;IACzF,wBAAmD;IACnD,2EAA2E;IAC3E,YAA+B;IAC/B,qFAAqF;IACrF,oBAA2C;IAC3C,mEAAmE;IACnE,aAAqC;QAErC,KAAK,CACH,MAAM,EACN,MAAM,EACN,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,wBAAwB,EACxB,YAAY,EACZ,oBAAoB,CACrB,CAAC;QAEF,mCAAmC;QACnC,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAA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gB,EAAE,OAAO,IAAI,IAAI;YACzE,QAAQ,EAAE,IAAI,EAAE,4CAA4C;YAC5D,GAAG,EAAE;gBACH,EAAE,EAAE,QAAQ,CAAC,EAAE;gBACf,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,SAAS,EAAE,QAAQ,CAAC,SAAS;gBAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO;aACY;SACxC,CAAC;IACJ,CAAC;CACF;AAxLD,8DAwLC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nauth-toolkit/social-facebook
|
|
3
|
+
*
|
|
4
|
+
* Platform-agnostic Facebook OAuth provider for nauth-toolkit.
|
|
5
|
+
* For NestJS integration, use '@nauth-toolkit/social-facebook/nestjs'
|
|
6
|
+
*/
|
|
1
7
|
export { FacebookOAuthClient } from './facebook-oauth.client';
|
|
2
8
|
export { TokenVerifierService } from './token-verifier.service';
|
|
3
9
|
export { FacebookSocialAuthService } from './facebook-social-auth.service';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,cAAc,wBAAwB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @nauth-toolkit/social-facebook
|
|
4
|
+
*
|
|
5
|
+
* Platform-agnostic Facebook OAuth provider for nauth-toolkit.
|
|
6
|
+
* For NestJS integration, use '@nauth-toolkit/social-facebook/nestjs'
|
|
7
|
+
*/
|
|
2
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
9
|
if (k2 === undefined) k2 = k;
|
|
4
10
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;AAEH,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA;AAElC,yDAAuC"}
|
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
import { NAuthConfig, ITokenVerifierService } from '@nauth-toolkit/core';
|
|
2
2
|
import { VerifiedFacebookTokenProfile } from './verified-token-profile.interface';
|
|
3
|
+
/**
|
|
4
|
+
* Token Verifier Service for Facebook OAuth (Platform-Agnostic)
|
|
5
|
+
*
|
|
6
|
+
* Handles secure verification of Facebook access tokens via Graph API.
|
|
7
|
+
* Validates tokens by calling Facebook's debug_token endpoint.
|
|
8
|
+
*
|
|
9
|
+
* Security Features:
|
|
10
|
+
* - Facebook: Validates access tokens via Facebook Graph API
|
|
11
|
+
*
|
|
12
|
+
* This is a plain TypeScript class with no framework dependencies.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const verifier = new TokenVerifierService(config);
|
|
17
|
+
* const profile = await verifier.verifyFacebookToken(accessToken, appId, appSecret);
|
|
18
|
+
* console.log(profile.id); // Verified Facebook user ID
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
3
21
|
export declare class TokenVerifierService implements ITokenVerifierService {
|
|
4
22
|
private readonly logger;
|
|
5
23
|
constructor(config: NAuthConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Verify Facebook access token via Graph API
|
|
26
|
+
*
|
|
27
|
+
* Validates the access token by calling Facebook's debug_token endpoint,
|
|
28
|
+
* which checks the token's validity and returns user information.
|
|
29
|
+
*
|
|
30
|
+
* @param accessToken - Access token from Facebook OAuth
|
|
31
|
+
* @param appId - Facebook App ID
|
|
32
|
+
* @param appSecret - Facebook App Secret (server-side only)
|
|
33
|
+
* @returns Verified user profile data
|
|
34
|
+
* @throws {BadRequestException} When token is invalid or API call fails
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* try {
|
|
39
|
+
* const profile = await verifier.verifyFacebookToken(accessToken, appId, appSecret);
|
|
40
|
+
* console.log(`Verified Facebook user: ${profile.id}`);
|
|
41
|
+
* } catch (error) {
|
|
42
|
+
* console.error('Token verification failed:', error.message);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
6
46
|
verifyFacebookToken(accessToken: string, appId: string, appSecret: string): Promise<VerifiedFacebookTokenProfile>;
|
|
7
47
|
}
|
|
8
48
|
//# sourceMappingURL=token-verifier.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-verifier.service.d.ts","sourceRoot":"","sources":["../../src/token-verifier.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA8C,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACrH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"token-verifier.service.d.ts","sourceRoot":"","sources":["../../src/token-verifier.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA8C,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACrH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAElF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,oBAAqB,YAAW,qBAAqB;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,MAAM,EAAE,WAAW;IAI/B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,mBAAmB,CACvB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,4BAA4B,CAAC;CAoDzC"}
|
|
@@ -2,26 +2,70 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenVerifierService = void 0;
|
|
4
4
|
const core_1 = require("@nauth-toolkit/core");
|
|
5
|
+
/**
|
|
6
|
+
* Token Verifier Service for Facebook OAuth (Platform-Agnostic)
|
|
7
|
+
*
|
|
8
|
+
* Handles secure verification of Facebook access tokens via Graph API.
|
|
9
|
+
* Validates tokens by calling Facebook's debug_token endpoint.
|
|
10
|
+
*
|
|
11
|
+
* Security Features:
|
|
12
|
+
* - Facebook: Validates access tokens via Facebook Graph API
|
|
13
|
+
*
|
|
14
|
+
* This is a plain TypeScript class with no framework dependencies.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const verifier = new TokenVerifierService(config);
|
|
19
|
+
* const profile = await verifier.verifyFacebookToken(accessToken, appId, appSecret);
|
|
20
|
+
* console.log(profile.id); // Verified Facebook user ID
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
5
23
|
class TokenVerifierService {
|
|
6
24
|
logger;
|
|
7
25
|
constructor(config) {
|
|
8
26
|
this.logger = config.logger;
|
|
9
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Verify Facebook access token via Graph API
|
|
30
|
+
*
|
|
31
|
+
* Validates the access token by calling Facebook's debug_token endpoint,
|
|
32
|
+
* which checks the token's validity and returns user information.
|
|
33
|
+
*
|
|
34
|
+
* @param accessToken - Access token from Facebook OAuth
|
|
35
|
+
* @param appId - Facebook App ID
|
|
36
|
+
* @param appSecret - Facebook App Secret (server-side only)
|
|
37
|
+
* @returns Verified user profile data
|
|
38
|
+
* @throws {BadRequestException} When token is invalid or API call fails
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* try {
|
|
43
|
+
* const profile = await verifier.verifyFacebookToken(accessToken, appId, appSecret);
|
|
44
|
+
* console.log(`Verified Facebook user: ${profile.id}`);
|
|
45
|
+
* } catch (error) {
|
|
46
|
+
* console.error('Token verification failed:', error.message);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
10
50
|
async verifyFacebookToken(accessToken, appId, appSecret) {
|
|
11
51
|
try {
|
|
12
52
|
this.logger?.debug?.('[TokenVerifier] Verifying Facebook token with Graph API');
|
|
53
|
+
// Step 1: Verify token with debug_token endpoint
|
|
13
54
|
const debugUrl = `https://graph.facebook.com/debug_token?input_token=${accessToken}&access_token=${appId}|${appSecret}`;
|
|
14
55
|
const debugResponse = await fetch(debugUrl);
|
|
15
56
|
if (!debugResponse.ok) {
|
|
16
57
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_TOKEN_INVALID, 'Facebook token validation failed');
|
|
17
58
|
}
|
|
18
59
|
const debugData = (await debugResponse.json());
|
|
60
|
+
// Check if token is valid
|
|
19
61
|
if (!debugData.data || !debugData.data.is_valid) {
|
|
20
62
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_TOKEN_INVALID, 'Invalid Facebook access token');
|
|
21
63
|
}
|
|
64
|
+
// Check if token belongs to the correct app
|
|
22
65
|
if (debugData.data.app_id !== appId) {
|
|
23
66
|
throw new core_1.NAuthException(core_1.AuthErrorCode.SOCIAL_TOKEN_INVALID, 'Token does not belong to this app');
|
|
24
67
|
}
|
|
68
|
+
// Step 2: Get user profile
|
|
25
69
|
const profileUrl = `https://graph.facebook.com/me?fields=id,email,first_name,last_name,picture&access_token=${accessToken}`;
|
|
26
70
|
const profileResponse = await fetch(profileUrl);
|
|
27
71
|
if (!profileResponse.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-verifier.service.js","sourceRoot":"","sources":["../../src/token-verifier.service.ts"],"names":[],"mappings":";;;AAAA,8CAAqH;
|
|
1
|
+
{"version":3,"file":"token-verifier.service.js","sourceRoot":"","sources":["../../src/token-verifier.service.ts"],"names":[],"mappings":";;;AAAA,8CAAqH;AAGrH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,oBAAoB;IACd,MAAM,CAAc;IAErC,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAqB,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,mBAAmB,CACvB,WAAmB,EACnB,KAAa,EACb,SAAiB;QAEjB,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,yDAAyD,CAAC,CAAC;YAEhF,iDAAiD;YACjD,MAAM,QAAQ,GAAG,sDAAsD,WAAW,iBAAiB,KAAK,IAAI,SAAS,EAAE,CAAC;YACxH,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;YAE5C,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,qBAAc,CAAC,oBAAa,CAAC,oBAAoB,EAAE,kCAAkC,CAAC,CAAC;YACnG,CAAC;YAED,MAAM,SAAS,GAAG,CAAC,MAAM,aAAa,CAAC,IAAI,EAAE,CAAQ,CAAC;YAEtD,0BAA0B;YAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChD,MAAM,IAA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ACtD,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AArFD,oDAqFC"}
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verified Token Profile - Facebook OAuth
|
|
3
|
+
*
|
|
4
|
+
* Standardized return type for Facebook token verification.
|
|
5
|
+
* This is provider-specific and should not be in core.
|
|
6
|
+
*/
|
|
1
7
|
export interface VerifiedFacebookTokenProfile {
|
|
8
|
+
/**
|
|
9
|
+
* Facebook user ID
|
|
10
|
+
*/
|
|
2
11
|
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* User's email address
|
|
14
|
+
*/
|
|
3
15
|
email?: string;
|
|
16
|
+
/**
|
|
17
|
+
* User's first name
|
|
18
|
+
*/
|
|
4
19
|
first_name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* User's last name
|
|
22
|
+
*/
|
|
5
23
|
last_name?: string;
|
|
24
|
+
/**
|
|
25
|
+
* User's profile picture data
|
|
26
|
+
*/
|
|
6
27
|
picture?: {
|
|
7
28
|
data: {
|
|
8
29
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verified-token-profile.interface.d.ts","sourceRoot":"","sources":["../../src/verified-token-profile.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verified-token-profile.interface.d.ts","sourceRoot":"","sources":["../../src/verified-token-profile.interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,IAAI,EAAE;YACJ,GAAG,EAAE,MAAM,CAAC;SACb,CAAC;KACH,CAAC;CACH"}
|