Skip to content

Commit

Permalink
feat(facebook): added missing user scope data (#763)
Browse files Browse the repository at this point in the history
* feat(facebook): added missing user scope data

* feat(changelog): added missing changelog

* feat(rerun pretty): updated

---------

Co-authored-by: krzysztofwitkowski <[email protected]>
Co-authored-by: Rishabh Poddar <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent 8d247df commit 58136d3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
40 changes: 39 additions & 1 deletion lib/build/recipe/thirdparty/providers/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion lib/ts/recipe/thirdparty/providers/facebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,40 @@ export default function Facebook(input: ProviderInput): TypeProvider {

const oGetUserInfo = originalImplementation.getUserInfo;
originalImplementation.getUserInfo = async function (input) {
const fieldsPermissionMap: Record<string, string[]> = {
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,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 58136d3

Please sign in to comment.