-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoogle-auth.js
74 lines (63 loc) · 1.85 KB
/
google-auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var error = require('eraro')({
package: 'google-auth'
})
var CommonAuth = require('./lib/common-google-auth')
var ExpressAuth = require('./lib/express-google-auth')
var HapiAuth = require('./lib/hapi-google-auth')
/**
*
* Google Authentification Seneca Plugin
*
* @param {Object} options - Plugin options
*
* @param {string} options.clientID - google Auth Client Id
* @param {string} options.clientSecret - google Auth Client Id
* @param {string} options.urlhost - url of the client
*
* @returns {{name: string}} the plugin name, google-auth
*/
module.exports = function (options) {
var seneca = this
var internals = {}
internals.accepted_framworks = [
'express',
'hapi'
]
internals.options = options
if (!options.framework) {
options.framework = 'express'
}
internals.choose_framework = function () {
if (internals.options.framework === 'express') {
internals.load_express_implementation()
}
else {
internals.load_hapi_implementation()
}
}
internals.check_options = function () {
if (seneca.options().plugin.web && seneca.options().plugin.web.framework) {
internals.options.framework = seneca.options().plugin.web.framework
}
if (internals.accepted_framworks.indexOf(internals.options.framework) === -1) {
throw error('Framework type <' + internals.options.framework + '> not supported.')
}
}
internals.load_express_implementation = function () {
seneca.use(ExpressAuth, internals.options)
seneca.use(CommonAuth, internals.options)
}
internals.load_hapi_implementation = function () {
seneca.use(HapiAuth, internals.options)
seneca.use(CommonAuth, internals.options)
}
function init (args, done) {
internals.check_options()
internals.choose_framework()
done()
}
seneca.add('init: google-auth', init)
return {
name: 'google-auth'
}
}