diff --git a/README.md b/README.md index acc64cc..de77191 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 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 +{ + appId: '123456789', + callback: 'testapp://authorize', +} +``` +- Register your deep link scheme with android and ios as described for other apps. + Usage ===== 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); 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'); + }); + }); +});