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

Commit d37d4f5

Browse files
authored
Merge pull request #72 from pcofilada/feature/facebook-scope
Add additional scope for facebook
2 parents 6051b68 + 573681f commit d37d4f5

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Providers Setup
4848
{
4949
appId: '1234567890',
5050
callback: 'fb1234567890://authorize',
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
5153
}
5254
```
5355
- 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-
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: 29 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,17 +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';
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+
];
2030

21-
export const authorize = ({ dance, request }, { appId, callback }) => pipeP(
31+
export const authorize = (
32+
{ dance, request },
33+
{ appId, callback, scope = SCOPE, fields = FIELDS },
34+
) => pipeP(
2235
dance,
2336
replace('#', '?'),
2437
fromQueryString,
25-
)(authorizationUrl(AUTH, appId, callback, SCOPE));
38+
set(lensProp('credentials'), __, {}),
39+
merge({ fields }),
40+
)(authorizationUrl(AUTH, appId, callback, scope));
2641

27-
export const identify = curry((request, credentials) => pipeP(
28-
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+
),
2952
invoker(0, 'json'),
3053
set(lensProp('user'), __, {}),
3154
set(lensProp('credentials'), credentials),

0 commit comments

Comments
 (0)