Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit 573681f

Browse files
committed
Add way to override default fields
1 parent 12178c0 commit 573681f

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ Providers Setup
4848
{
4949
appId: '1234567890',
5050
callback: 'fb1234567890://authorize',
51-
scope: 'user_friends' // you can add some additional scope here
51+
scope: 'user_friends', // you can override the default scope here
52+
fields: ['email', 'first_name', 'last_name'], // you can override the default fields here
5253
}
5354
```
5455
- Add the deep link scheme for the callback (Your Bundle ID, eg `fb1234567890`) to your `AndroidManifest.xml` eg https://github.com/adamjmcgrath/ReactNativeSimpleAuthExample/blob/master/android/app/src/main/AndroidManifest.xml#L28-L33

lib/fixtures/facebook.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const DANCE_CALLBACK = `fb0123456789://authorize#
1111
`.replace(/\s+/g, '');
1212

1313
const USER_INFO_URL = `https://graph.facebook.com/v2.8/me?
14-
fields=id,name,first_name,last_name,verified,email,location,link,
15-
gender,cover,picture,friends,website&access_token=ACCESSTOKEN123
14+
&access_token=ACCESSTOKEN123
15+
&fields=id,name,first_name,last_name,verified,email,location,link
1616
`.replace(/\s+/g, '');
1717

1818
const USER_INFO_RESPONSE = {

lib/providers/facebook.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
pipeP,
88
replace,
99
set,
10+
merge,
1011
} from 'ramda';
1112
import {
1213
authorizationUrl,
@@ -15,21 +16,39 @@ import { fromQueryString } from '../utils/uri';
1516

1617
const SCOPE = 'email public_profile';
1718
const AUTH = 'https://www.facebook.com/dialog/oauth';
18-
const ME = 'https://graph.facebook.com/v2.8/me?fields=' +
19-
'id,name,first_name,last_name,verified,email,location,link,' +
20-
'gender,cover,picture,friends,website';
19+
const ME = 'https://graph.facebook.com/v2.8/me?';
20+
const FIELDS = [
21+
'id',
22+
'name',
23+
'first_name',
24+
'last_name',
25+
'verified',
26+
'email',
27+
'location',
28+
'link',
29+
];
2130

2231
export const authorize = (
2332
{ dance, request },
24-
{ appId, callback, scope = SCOPE },
33+
{ appId, callback, scope = SCOPE, fields = FIELDS },
2534
) => pipeP(
2635
dance,
2736
replace('#', '?'),
2837
fromQueryString,
38+
set(lensProp('credentials'), __, {}),
39+
merge({ fields }),
2940
)(authorizationUrl(AUTH, appId, callback, scope));
3041

31-
export const identify = curry((request, credentials) => pipeP(
32-
partial(request, [`${ME}&access_token=${credentials.access_token}`, {}]),
42+
export const identify = curry((request, { credentials, fields }) => pipeP(
43+
partial(
44+
request,
45+
[
46+
`${ME}` +
47+
`&access_token=${credentials.access_token}` +
48+
`&fields=${fields.join(',')}`,
49+
{},
50+
],
51+
),
3352
invoker(0, 'json'),
3453
set(lensProp('user'), __, {}),
3554
set(lensProp('credentials'), credentials),

0 commit comments

Comments
 (0)