forked from salrashid123/gcpsamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (39 loc) · 1.24 KB
/
app.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
'use strict';
var http = require('http');
var express = require('express')
var log4js = require("log4js");
var GoogleAuth = require('google-auth-library');
var google = require('googleapis');
var logger = log4js.getLogger();
var app = express();
app.get('/', function (req, res) {
google.auth.getApplicationDefault(function(err, authClient) {
if (err) {
logger.error(err);
res.send(err);
return;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped(['https://www.googleapis.com/auth/userinfo.email']);
}
var service = google.oauth2({ version: 'v2',
auth: authClient
});
var service = google.oauth2({ version: 'v2', auth: authClient });
service.userinfo.get(function(err, info) {
if (err) {
res.send(err);
return;
}
res.status(200).send(info.email);
});
});
});
app.get('/_ah/health', function (req, res) {
res.status(200).send('ok');
});
var server = app.listen(8080, function () {
var host = server.address().address;
var port = server.address().port;
logger.info("Web Server Start " + host + ":" + port);
});