Skip to content

Commit

Permalink
adding in auth0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
snollygolly committed Oct 3, 2018
1 parent fb83bd3 commit 04d582e
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ I'm also including goodies from:
* [Github Corners](https://github.com/tholman/github-corners)
* [Google Universal Analytics](https://www.google.com/analytics/)
* [ESLint](http://eslint.org/)
* [Auth0](https://auth0.com/)

## Prerequisites
* [Node.js](https://nodejs.org/en/) (Version 8 and up recommended, async/await support required)
* [Github Client ID and Secret](https://github.com/settings/developers) (for OAuth)
* [Auth0 Account](https://auth0.com/) (for OAuth)

### Installation

Expand Down
5 changes: 5 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"secret": "koa-starter-kit-is-awesome",
"oauth": {
"host": "http://127.0.0.1",
"auth0": {
"domain": "YOUR AUTH0 DOMAIN",
"clientID": "YOUR AUTH0 CLIENT ID",
"clientSecret": "YOUR AUTH0 CLIENT SECRET"
},
"github": {
"clientID": "OAUTH CLIENT ID FOR GITHUB",
"clientSecret": "OAUTH CLIENT SECRET FOR GITHUB"
Expand Down
22 changes: 17 additions & 5 deletions models/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
const passport = require("../index.js").passport;
const config = require("../config.json");

// if we have a port other than 80, add it to our callback url
let port = "";
if (config.site.port !== 80) {
port = `:${config.site.port}`;
}

passport.serializeUser((user, done) => {
done(null, user);
});
Expand All @@ -12,11 +18,6 @@ passport.deserializeUser((user, done) => {
});

const GithubStrategy = require("passport-github").Strategy;
// if we have a port other than 80, add it to our callback url
let port = "";
if (config.site.port !== 80) {
port = `:${config.site.port}`;
}
passport.use(new GithubStrategy({
clientID: config.site.oauth.github.clientID,
clientSecret: config.site.oauth.github.clientSecret,
Expand All @@ -25,3 +26,14 @@ passport.use(new GithubStrategy({
// retrieve user ...
done(null, profile);
}));

const Auth0Strategy = require("passport-auth0");
passport.use(new Auth0Strategy({
domain: config.site.oauth.auth0.domain,
clientID: config.site.oauth.auth0.clientID,
clientSecret: config.site.oauth.auth0.clientSecret,
callbackURL: `${config.site.oauth.host}${port}/auth/auth0/callback`
}, (accessToken, refreshToken, extraParams, profile, done) => {
// retrieve user ...
done(null, profile);
}));
Loading

0 comments on commit 04d582e

Please sign in to comment.