Skip to content

Instantly share code, notes, and snippets.

@jboxman
Last active October 1, 2018 04:52
Show Gist options
  • Save jboxman/58d5dda70854eb6cece943469cc7c8f7 to your computer and use it in GitHub Desktop.
Save jboxman/58d5dda70854eb6cece943469cc7c8f7 to your computer and use it in GitHub Desktop.
github-sso-auth-code-flow #3
const Router = require('koa-router');
const passport = require('koa-passport');
const isAuthenticated = (ctx, next) => {
return ctx.isAuthenticated() ? next() : ctx.status = 403;
};
const router = new Router();
router.get('/auth/github',
passport.authenticate('github')
);
// Custom handler that returns the authenticated user object
router.get('/auth/github/callback', function(ctx) {
return passport.authenticate('github', async function(err, user, info) {
await ctx.logIn(user);
await ctx.render('success', {user: JSON.stringify(ctx.state.user)});
})(ctx);
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment