forked from hapijs/bell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle.js
executable file
·60 lines (45 loc) · 1.82 KB
/
google.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
'use strict';
// Load modules
const Bell = require('../');
const Hapi = require('hapi');
// Declare internals
const internals = {};
internals.start = async function () {
const server = Hapi.server({ host: 'localhost', port: 8000 });
await server.register(Bell);
// You'll need to go to https://console.developers.google.com and set up an application to get started
// Once you create your app, fill out "APIs & auth >> Consent screen" and make sure to set the email field
// Next, go to "APIs & auth >> Credentials and Create new Client ID
// Select "web application" and set "AUTHORIZED JAVASCRIPT ORIGINS" and "AUTHORIZED REDIRECT URIS"
// This will net you the clientId and the clientSecret needed.
// Also be sure to pass the location as well. It must be in the list of "AUTHORIZED REDIRECT URIS"
// You must also enable the Google+ API in your profile.
// Go to APIs & Auth, then APIs and under Social APIs click Google+ API and enable it.
server.auth.strategy('google', 'bell', {
provider: 'google',
password: 'cookie_encryption_password_secure',
isSecure: false,
clientId: '',
clientSecret: '',
location: server.info.uri
});
server.route({
method: '*',
path: '/bell/door',
options: {
auth: {
strategy: 'google',
mode: 'try'
},
handler: function (request, h) {
if (!request.auth.isAuthenticated) {
return 'Authentication failed due to: ' + request.auth.error.message;
}
return '<pre>' + JSON.stringify(request.auth.credentials, null, 4) + '</pre>';
}
}
});
await server.start();
console.log('Server started at:', server.info.uri);
};
internals.start();