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'); + }); + }); +});