Skip to content

Commit

Permalink
add 'provider' constant
Browse files Browse the repository at this point in the history
  • Loading branch information
dimapaloskin committed Apr 14, 2017
1 parent 96bbe67 commit 25222b9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const uuid = require('uuid');
const rp = require('request-promise');
const redirect = require('micro-redirect');

const provider = 'github';

const microAuthGithub = ({ clientId, clientSecret, callbackUrl, path = '/auth/github', scope = 'user' }) => {

const getRedirectUrl = (state) => {
Expand All @@ -23,7 +25,7 @@ const microAuthGithub = ({ clientId, clientSecret, callbackUrl, path = '/auth/gi
states.push(state);
return redirect(res, 302, redirectUrl);
} catch (err) {
args.push({ err, provider: 'github' });
args.push({ err, provider });
return fn(req, res, ...args);
}
}
Expand All @@ -35,7 +37,7 @@ const microAuthGithub = ({ clientId, clientSecret, callbackUrl, path = '/auth/gi

if (!states.includes(state)) {
const err = new Error('Invalid state');
return fn(req, res, { err, provider: 'github' });
return fn(req, res, { err, provider });
}

states.splice(states.indexOf(state), 1);
Expand All @@ -54,7 +56,7 @@ const microAuthGithub = ({ clientId, clientSecret, callbackUrl, path = '/auth/gi
});

if (response.error) {
args.push({ err: response.error, provider: 'github' });
args.push({ err: response.error, provider });
return fn(req, res, ...args);
}

Expand All @@ -70,15 +72,15 @@ const microAuthGithub = ({ clientId, clientSecret, callbackUrl, path = '/auth/gi
});

const result = {
provider: 'github',
provider,
accessToken,
info: user
};

args.push({ result });
return fn(req, res, ...args);
} catch (err) {
args.push({ err, provider: 'github' });
args.push({ err, provider });
return fn(req, res, ...args);
}
}
Expand Down

0 comments on commit 25222b9

Please sign in to comment.