Created
April 10, 2016 16:42
-
-
Save vdeturckheim/f84a17b29743148700d9a5cd364b5aa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Bell = require('bell'); | |
const AuthBearer = require('hapi-auth-bearer-token'); | |
const AuthService = require('./lib/services/auth.service'); | |
const Routes = require('./lib').routes; | |
exports.register = function (server, options, next) { | |
if (!options.github){ | |
return next(new Error('no options provided for github')); | |
} | |
const ghOptions = options.github; | |
ghOptions.scope = ['user:email', 'gist']; | |
ghOptions.provider = 'github'; | |
server.register([Bell, AuthBearer]) | |
.then(() => { | |
server.auth.strategy('github', 'bell', ghOptions); | |
server.auth.strategy('bearer', 'bearer-access-token', { | |
allowQueryToken: false, | |
validateFunc: AuthService.validateToken | |
}); | |
server.auth.default('bearer'); | |
}) | |
.then(() => { | |
server.route(Routes); | |
}) | |
.then(() => next()) | |
.catch((err) => next(err)); | |
}; | |
exports.register.attributes = { | |
pkg: require('./package.json') | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment