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

Commit

Permalink
See #67
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath committed Mar 27, 2017
1 parent b887f44 commit 3bb8417
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
20 changes: 0 additions & 20 deletions lib/fixtures/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@ const DANCE_CALLBACK = `fb0123456789://authorize#
expires_in=12345
`.replace(/\s+/g, '');

const VERIFY_URL = `https://graph.facebook.com/debug_token?
input_token=ACCESSTOKEN123&
access_token=ACCESSTOKEN123
`.replace(/\s+/g, '');

const VERIFY_RESPONSE = {
data: {
app_id: 'APPID123',
application: 'Test App',
expires_at: 123456789,
is_valid: true,
scopes: [
'email',
'public_profile',
],
user_id: 'USER123',
},
};

const USER_INFO_URL = `https://graph.facebook.com/v2.8/me?
fields=id,name,first_name,last_name,verified,email,location,link&
access_token=ACCESSTOKEN123
Expand All @@ -43,6 +24,5 @@ const USER_INFO_RESPONSE = {
export const DANCE = [AUTH_URL, DANCE_CALLBACK];

export const REQUESTS = [
[VERIFY_URL, {}, VERIFY_RESPONSE, 'verify token'],
[USER_INFO_URL, {}, USER_INFO_RESPONSE, 'get user info'],
];
18 changes: 1 addition & 17 deletions lib/providers/facebook.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {
__,
curry,
equals,
identity,
ifElse,
invoker,
lensProp,
merge,
partial,
pathSatisfies,
pipeP,
replace,
set,
Expand All @@ -20,27 +15,16 @@ import { fromQueryString } from '../utils/uri';

const SCOPE = 'email public_profile';
const AUTH = 'https://www.facebook.com/dialog/oauth';
const DEBUG_TOKEN = 'https://graph.facebook.com/debug_token';
const ME = 'https://graph.facebook.com/v2.8/me?fields=' +
'id,name,first_name,last_name,verified,email,location,link';

const checkAppId = curry((appId, obj) => ifElse(
pathSatisfies(equals(appId), ['data', 'app_id']),
identity,
() => { throw new Error('AppIds don\'t match.'); },
)(obj));

export const authorize = ({ dance, request }, { appId, callback }) => pipeP(
dance,
replace('#', '?'),
fromQueryString,
merge({ appId }),
)(authorizationUrl(AUTH, appId, callback, SCOPE));

export const identify = curry((request, { appId, ...credentials }) => pipeP(
partial(request, [`${DEBUG_TOKEN}?input_token=${credentials.access_token}&access_token=${credentials.access_token}`, {}]), // eslint-disable-line max-len
invoker(0, 'json'),
checkAppId(appId),
export const identify = curry((request, credentials) => pipeP(
partial(request, [`${ME}&access_token=${credentials.access_token}`, {}]),
invoker(0, 'json'),
set(lensProp('user'), __, {}),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-simple-auth",
"version": "2.0.0",
"version": "2.0.1",
"description": "Native social authentication for React Native",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3bb8417

Please sign in to comment.