diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d84d23c..dd23e6227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [16.6.7] - 2023-12-18 + +- Adds facebook user data by checking the scopes provided in the config + ## [16.6.6] - 2023-12-17 - Adds `userContext` input to the `validate` function in form fields. You can use this to fetch the request object from the `userContext`, read the request body, and then read the other form fields from there. If doing so, keep in mind that for the email and password validators, the request object may not always be available in the `validate` function, and even if it's available, it may not have the request body of the sign up API since the `validate` functions are also called from other operations (like in password reset API). For custom form fields that you have added to the sign up API, the request object will always be there in the `userContext`. diff --git a/lib/build/recipe/thirdparty/providers/facebook.js b/lib/build/recipe/thirdparty/providers/facebook.js index 2c049e086..0353cc704 100644 --- a/lib/build/recipe/thirdparty/providers/facebook.js +++ b/lib/build/recipe/thirdparty/providers/facebook.js @@ -38,8 +38,46 @@ function Facebook(input) { }; const oGetUserInfo = originalImplementation.getUserInfo; originalImplementation.getUserInfo = async function (input) { + var _a; + const fieldsPermissionMap = { + public_profile: [ + "first_name", + "last_name", + "middle_name", + "name", + "name_format", + "picture", + "short_name", + ], + email: ["id", "email"], + user_birthday: ["birthday"], + user_videos: ["videos"], + user_posts: ["posts"], + user_photos: ["photos"], + user_location: ["location"], + user_link: ["link"], + user_likes: ["likes"], + user_hometown: ["hometown"], + user_gender: ["gender"], + user_friends: ["friends"], + user_age_range: ["age_range"], + }; + const scopeValues = originalImplementation.config.scope; + const fields = + (_a = + scopeValues === null || scopeValues === void 0 + ? void 0 + : scopeValues + .map((scopeValue) => { + var _a; + return (_a = fieldsPermissionMap[scopeValue]) !== null && _a !== void 0 ? _a : []; + }) + .flat() + .join(",")) !== null && _a !== void 0 + ? _a + : "id,email"; originalImplementation.config.userInfoEndpointQueryParams = Object.assign( - { access_token: input.oAuthTokens.access_token, fields: "id,email", format: "json" }, + { access_token: input.oAuthTokens.access_token, fields, format: "json" }, originalImplementation.config.userInfoEndpointQueryParams ); originalImplementation.config.userInfoEndpointHeaders = Object.assign( diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index 82c87b50a..bccb69e80 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1,4 +1,4 @@ // @ts-nocheck -export declare const version = "16.6.6"; +export declare const version = "16.6.7"; export declare const cdiSupported: string[]; export declare const dashboardVersion = "0.9"; diff --git a/lib/build/version.js b/lib/build/version.js index 51058724a..0b2be2c33 100644 --- a/lib/build/version.js +++ b/lib/build/version.js @@ -15,7 +15,7 @@ exports.dashboardVersion = exports.cdiSupported = exports.version = void 0; * License for the specific language governing permissions and limitations * under the License. */ -exports.version = "16.6.6"; +exports.version = "16.6.7"; exports.cdiSupported = ["4.0"]; // Note: The actual script import for dashboard uses v{DASHBOARD_VERSION} exports.dashboardVersion = "0.9"; diff --git a/lib/ts/recipe/thirdparty/providers/facebook.ts b/lib/ts/recipe/thirdparty/providers/facebook.ts index 0211e268d..41cf0c042 100644 --- a/lib/ts/recipe/thirdparty/providers/facebook.ts +++ b/lib/ts/recipe/thirdparty/providers/facebook.ts @@ -56,9 +56,40 @@ export default function Facebook(input: ProviderInput): TypeProvider { const oGetUserInfo = originalImplementation.getUserInfo; originalImplementation.getUserInfo = async function (input) { + const fieldsPermissionMap: Record = { + public_profile: [ + "first_name", + "last_name", + "middle_name", + "name", + "name_format", + "picture", + "short_name", + ], + email: ["id", "email"], + user_birthday: ["birthday"], + user_videos: ["videos"], + user_posts: ["posts"], + user_photos: ["photos"], + user_location: ["location"], + user_link: ["link"], + user_likes: ["likes"], + user_hometown: ["hometown"], + user_gender: ["gender"], + user_friends: ["friends"], + user_age_range: ["age_range"], + }; + const scopeValues = originalImplementation.config.scope; + + const fields = + scopeValues + ?.map((scopeValue) => fieldsPermissionMap[scopeValue] ?? []) + .flat() + .join(",") ?? "id,email"; + originalImplementation.config.userInfoEndpointQueryParams = { access_token: input.oAuthTokens.access_token, - fields: "id,email", + fields, format: "json", ...originalImplementation.config.userInfoEndpointQueryParams, }; diff --git a/lib/ts/version.ts b/lib/ts/version.ts index 1c3c9fd1f..7ba55b996 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const version = "16.6.6"; +export const version = "16.6.7"; export const cdiSupported = ["4.0"]; diff --git a/package-lock.json b/package-lock.json index 64dda0db4..734ae6bc8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-node", - "version": "16.6.6", + "version": "16.6.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "supertokens-node", - "version": "16.6.6", + "version": "16.6.7", "license": "Apache-2.0", "dependencies": { "content-type": "^1.0.5", diff --git a/package.json b/package.json index b9a5f44b0..c53b445f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-node", - "version": "16.6.6", + "version": "16.6.7", "description": "NodeJS driver for SuperTokens core", "main": "index.js", "scripts": {