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

Commit

Permalink
Merge pull request #114 from beerxchange/untappd
Browse files Browse the repository at this point in the history
Add Untappd as a supported provider
  • Loading branch information
adamjmcgrath authored Nov 10, 2019
2 parents ead0fc9 + c1f52a5 commit d187d74
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
14 changes: 14 additions & 0 deletions lib/fixtures/untappd.js
Original file line number Diff line number Diff line change
@@ -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];
42 changes: 42 additions & 0 deletions lib/providers/untappd.js
Original file line number Diff line number Diff line change
@@ -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,
},
}));
21 changes: 21 additions & 0 deletions lib/providers/untappd.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});

0 comments on commit d187d74

Please sign in to comment.