diff --git a/index.js b/index.js index 951189a..96e8b11 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,6 @@ const fetch = require('node-fetch'); const encode = require('./lib/encode.js'); -/* appCredentials Object: -let appCredentials = { - client: { - id: 'CLIENT_ID', - secret: 'CLIENT_SECRET' - }, - uri: { - authorization: 'https://someauthorization.com/url', - token: 'https://api.sometoken.com/url', - redirect: 'https://myimportantapp.com/redirect' - }, - scope: 'some scope and shit', - responseType: 'code' -} - -*/ - -// oauth.authorizationCodeUri(appCredentials).then((url) => {}); exports.authorizationCodeUri = (appCredentials) => { return new Promise ((fulfill, reject) => { if (appCredentials.client.id === undefined) { @@ -44,7 +26,13 @@ exports.getAccessToken = (app) => { }, body: `client_id=${app.client.id}&grant_type=authorization_code&redirect_uri-&${encodeURI(app.uri.redirect)}&code=${app.code}` }).then((token) => { - fulfill(token.json()); + let accessToken = token.json(); + + if (accessToken.error !== undefined) { + reject(accessToken); + } else { + fulfill(accessToken); + } }).catch((error) => { reject(error); });