From d1b6b5a1ee250fe21e5a2bf6d367ce7dceb174dd Mon Sep 17 00:00:00 2001 From: Will C Date: Mon, 2 Sep 2019 17:24:07 -0400 Subject: [PATCH 1/6] initial untappd implementation --- lib/fixtures/untappd.js | 14 ++++++++++++ lib/providers/untappd.js | 42 +++++++++++++++++++++++++++++++++++ lib/providers/untappd.test.js | 21 ++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 lib/fixtures/untappd.js create mode 100644 lib/providers/untappd.js create mode 100644 lib/providers/untappd.test.js diff --git a/lib/fixtures/untappd.js b/lib/fixtures/untappd.js new file mode 100644 index 0000000..2f4c449 --- /dev/null +++ b/lib/fixtures/untappd.js @@ -0,0 +1,14 @@ +/* eslint max-len: "off" */ + +const AUTHENTICATE_URL = `https://untappd.com/oauth/authenticate? + scope=& + redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback& + response_type=code& + client_id=APPID123 +`.replace(/\s+/g, ''); + +const DANCE_CALLBACK = `? + code=CODE123 +`.replace(/\s+/g, ''); + +export default [AUTHENTICATE_URL, DANCE_CALLBACK]; diff --git a/lib/providers/untappd.js b/lib/providers/untappd.js new file mode 100644 index 0000000..c2dd653 --- /dev/null +++ b/lib/providers/untappd.js @@ -0,0 +1,42 @@ +import { + curry, + has, + identity, + ifElse, + merge, + pipe, + pipeP, + prop, +} from 'ramda'; +import { + authorizationUrl, +} from '../utils/oauth2'; +import { + fromQueryString, +} from '../utils/uri'; + +const SCOPE = ''; +const AUTH = 'https://untappd.com/oauth/authenticate'; + +const checkError = ifElse( + has('error'), + pipe(prop('error'), curry((e) => { throw new Error(e); })), + identity, +); + +// eslint-disable-next-line import/prefer-default-export +export const authorize = ( + { dance }, + { appId, callback, scope = SCOPE }) => + pipeP( + dance, + fromQueryString, + checkError, + merge({ appId, callback }), + )(authorizationUrl(AUTH, appId, callback, scope, 'code')); + +export const identify = curry((request, { code }) => ({ + credentials: { + code, + }, +})); diff --git a/lib/providers/untappd.test.js b/lib/providers/untappd.test.js new file mode 100644 index 0000000..b5c5d7e --- /dev/null +++ b/lib/providers/untappd.test.js @@ -0,0 +1,21 @@ +import assert from 'assert'; +import * as untappd from './untappd'; +import DANCE from '../fixtures/untappd'; +import * as test from '../platforms/test'; +import login from '../login'; + +describe('Untappd', () => { + before(() => { + test.setup([], DANCE); + }); + + it('should authorize', () => { + const untappdTest = login(untappd, test); + return untappdTest({ + appId: 'APPID123', + }) + .then((response) => { + assert.equal(response.credentials.code, 'CODE123'); + }); + }); +}); From bdf8c9296c01420d469aff7ce60b1fc47ffa814b Mon Sep 17 00:00:00 2001 From: Will C Date: Mon, 2 Sep 2019 19:57:28 -0400 Subject: [PATCH 2/6] add untappd to index --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 8e7d4a4..7f4410f 100644 --- a/index.js +++ b/index.js @@ -10,10 +10,12 @@ import * as _google from './lib/providers/google'; import * as _facebook from './lib/providers/facebook'; import * as _twitter from './lib/providers/twitter'; import * as _tumblr from './lib/providers/tumblr'; +import * as _untappd from './lib/providers/untappd'; export const google = login(_google, platform); export const facebook = login(_facebook, platform); export const twitter = login(_twitter, platform); export const tumblr = login(_tumblr, platform); +export const untappd = login(_untappd, platform); export default login(__, platform); From b2227296a66a24ebab3cc8b7104b587279ce71d9 Mon Sep 17 00:00:00 2001 From: Will C Date: Sat, 9 Nov 2019 16:34:23 -0500 Subject: [PATCH 3/6] update providers in README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index acc64cc..0c9d44c 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,18 @@ Providers Setup - Add the deep link scheme for the callback (Your App Name, eg `testapp`) to your `AndroidManifest.xml` eg https://github.com/adamjmcgrath/ReactNativeSimpleAuthExample/blob/master/android/app/src/main/AndroidManifest.xml#L28-L33 - Add the deep link scheme for the callback to your iOS app, eg https://dev.twitter.com/cards/mobile/url-schemes (Due to A Facebook bug, this should always be the top one in the list) +### Untappd +- Create an app on +- Use a custom app prefix for the callback url +- Your configuration object should contain the app id and your callback url e.g. +```js +{ + appId: '123456789', + callback: 'testapp://authorize', +} +``` +- Register your deep link scheme with android and ios as described for other apps. + Usage ===== From 6bf10b5236d54e9f062901ba3cf359064fdd9d91 Mon Sep 17 00:00:00 2001 From: Will C Date: Sat, 9 Nov 2019 16:37:57 -0500 Subject: [PATCH 4/6] add untappd login url --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c9d44c..5569e95 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ Providers Setup - Add the deep link scheme for the callback to your iOS app, eg https://dev.twitter.com/cards/mobile/url-schemes (Due to A Facebook bug, this should always be the top one in the list) ### Untappd -- Create an app on -- Use a custom app prefix for the callback url +- Create an app on https://untappd.com/api/register +- Use a custom app prefix for the callback url. - Your configuration object should contain the app id and your callback url e.g. ```js { @@ -114,7 +114,7 @@ google({ appId: '123-123abc.apps.googleusercontent.com', callback: 'com.reactnativesimpleauthexample:/oauth2redirect', }).then((info) => { - // info.user - user details from the provider + // [info user](info.user) - user details from the provider // info.credentials - tokens from the provider }).catch((error) => { // error.code From 65b06e1ca54c4fe18495299b4bf5284d7f4c7a0d Mon Sep 17 00:00:00 2001 From: Will C Date: Sat, 9 Nov 2019 16:47:10 -0500 Subject: [PATCH 5/6] not sure what happened there --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5569e95..dc182b8 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ google({ appId: '123-123abc.apps.googleusercontent.com', callback: 'com.reactnativesimpleauthexample:/oauth2redirect', }).then((info) => { - // [info user](info.user) - user details from the provider + // info user - user details from the provider // info.credentials - tokens from the provider }).catch((error) => { // error.code From c1f52a5d5f2080061d52fcf60d11e0f6b9011699 Mon Sep 17 00:00:00 2001 From: Will C Date: Sat, 9 Nov 2019 16:47:44 -0500 Subject: [PATCH 6/6] remove unintentional typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc182b8..de77191 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ google({ appId: '123-123abc.apps.googleusercontent.com', callback: 'com.reactnativesimpleauthexample:/oauth2redirect', }).then((info) => { - // info user - user details from the provider + // info.user - user details from the provider // info.credentials - tokens from the provider }).catch((error) => { // error.code