Skip to content

Commit 1a7b3bc

Browse files
author
Jim Crowley
committed
updating starter project
1 parent 9dcd656 commit 1a7b3bc

18 files changed

+385
-356
lines changed

starter-project/.eslintrc.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ module.exports = {
33
'browser': true,
44
'node': true,
55
},
6-
'extends': 'airbnb/legacy',
7-
'rules':{
6+
'extends': 'airbnb/legacy',
7+
"parserOptions": {
8+
"ecmaVersion": 6
9+
},
10+
'rules': {
811
'prefer-template': 0,
912
'comma-dangle': 0,
1013
'func-names': 0,
@@ -13,7 +16,6 @@ module.exports = {
1316
'no-param-reassign': 0,
1417
'no-use-before-define': 0,
1518
'no-console': 0,
16-
'linebreak-style': 0,
17-
'no-unused-vars':0 //for empty functions in the starter project
19+
'linebreak-style': 0
1820
}
1921
};

starter-project/app.js

+54-16
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,53 @@
33
* See LICENSE in the project root for license information.
44
*/
55
// application dependencies
6-
var express = require('express');
7-
var session = require('express-session');
8-
var path = require('path');
9-
var favicon = require('serve-favicon');
10-
var logger = require('morgan');
11-
var cookieParser = require('cookie-parser');
12-
var bodyParser = require('body-parser');
13-
var routes = require('./routes/index');
6+
const express = require('express');
7+
const session = require('express-session');
8+
const path = require('path');
9+
const favicon = require('serve-favicon');
10+
const logger = require('morgan');
11+
const cookieParser = require('cookie-parser');
12+
const bodyParser = require('body-parser');
13+
const routes = require('./routes/index');
14+
const passport = require('passport');
15+
const OIDCStrategy = require('passport-azure-ad').OIDCStrategy;
16+
const uuid = require('uuid');
17+
const config = require('./utils/config.js');
1418

15-
var app = express();
19+
const app = express();
20+
21+
// **IMPORTANT
22+
// Note that production apps will need to create a self-signed cert and use a secure server,
23+
// and change dev settings marked 'For development only' in app.js and config.js.
24+
// Below is an example after you have the key cert pair:
25+
// const https = require('https');
26+
// const certConfig = {
27+
// key: fs.readFileSync('./utils/cert/server.key', 'utf8'),
28+
// cert: fs.readFileSync('./utils/cert/server.crt', 'utf8')
29+
// };
30+
// const server = https.createServer(certConfig, app);
31+
32+
// authentication setup
33+
const callback = (iss, sub, profile, accessToken, refreshToken, done) => {
34+
done(null, {
35+
profile,
36+
accessToken,
37+
refreshToken
38+
});
39+
};
40+
41+
passport.use(new OIDCStrategy(config.creds, callback));
42+
43+
const users = {};
44+
passport.serializeUser((user, done) => {
45+
const id = uuid.v4();
46+
users[id] = user;
47+
done(null, id);
48+
});
49+
passport.deserializeUser((id, done) => {
50+
const user = users[id];
51+
done(null, user);
52+
});
1653

1754
// view engine setup
1855
app.set('views', path.join(__dirname, 'views'));
@@ -27,23 +64,24 @@ app.use(cookieParser());
2764
// see https://github.com/expressjs/session
2865
app.use(session({
2966
secret: '12345QWERTY-SECRET',
30-
name: 'nodecookie',
67+
name: 'graphNodeCookie',
3168
resave: false,
32-
saveUninitialized: false
69+
saveUninitialized: false,
70+
//cookie: {secure: true} // For development only
3371
}));
3472
app.use(express.static(path.join(__dirname, 'public')));
35-
73+
app.use(passport.initialize());
74+
app.use(passport.session());
3675
app.use('/', routes);
3776

77+
// error handlers
3878
// catch 404 and forward to error handler
3979
app.use(function (req, res, next) {
40-
var err = new Error('Not Found');
80+
const err = new Error('Not Found');
4181
err.status = 404;
4282
next(err);
4383
});
4484

45-
// error handlers
46-
4785
// development error handler
4886
// will print stacktrace
4987
if (app.get('env') === 'development') {
@@ -66,4 +104,4 @@ app.use(function (err, req, res) {
66104
});
67105
});
68106

69-
module.exports = app;
107+
module.exports = app;

starter-project/authHelper.js

-65
This file was deleted.

starter-project/bin/www

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
* Module dependencies.
55
*/
66

7-
var app = require('../app');
8-
var debug = require('debug')('o365-nodejs-unified-api-connect:server');
9-
var http = require('http');
7+
const app = require('../app');
8+
const debug = require('debug')('nodejs-microsoft-graph-connect:server');
9+
const http = require('http');
1010

1111
/**
1212
* Get port from environment and store in Express.
1313
*/
1414

15-
var port = normalizePort(process.env.PORT || '3000');
15+
const port = normalizePort(process.env.PORT || '3000');
1616
app.set('port', port);
1717

1818
/**
1919
* Create HTTP server.
2020
*/
2121

22-
var server = http.createServer(app);
22+
const server = http.createServer(app);
2323

2424
/**
2525
* Listen on provided port, on all network interfaces.
@@ -34,7 +34,7 @@ server.on('listening', onListening);
3434
*/
3535

3636
function normalizePort(val) {
37-
var port = parseInt(val, 10);
37+
const port = parseInt(val, 10);
3838

3939
if (isNaN(port)) {
4040
// named pipe
@@ -58,7 +58,7 @@ function onError(error) {
5858
throw error;
5959
}
6060

61-
var bind = typeof port === 'string'
61+
const bind = typeof port === 'string'
6262
? 'Pipe ' + port
6363
: 'Port ' + port;
6464

@@ -82,9 +82,10 @@ function onError(error) {
8282
*/
8383

8484
function onListening() {
85-
var addr = server.address();
86-
var bind = typeof addr === 'string'
85+
const addr = server.address();
86+
const bind = typeof addr === 'string'
8787
? 'pipe ' + addr
8888
: 'port ' + addr.port;
89-
debug('Listening on ' + bind);
90-
}
89+
debug('Listening on ' + bind);
90+
console.log('\r\nListening on ' + bind);
91+
}

starter-project/emailer.js

-35
This file was deleted.

starter-project/package.json

+27-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "o365-nodejs-microsoft-graph-connect",
3-
"version": "1.0.0",
4-
"description": "Connecting to Office 365 is the first step every Node.js app must take to start working with Office 365 services and data. This sample shows how to connect and then call one endpoint through the Microsoft Graph API.",
2+
"name": "nodejs-microsoft-graph-connect",
3+
"version": "2.0.0",
4+
"description": "Connecting to Microsoft Graph is the first step every Node.js app must take to start working with the Microsoft Graph API. This sample shows how to connect and call Microsoft Graph",
55
"private": true,
66
"scripts": {
77
"start": "mocha ./tests/confTest.js && node ./bin/www",
@@ -10,34 +10,36 @@
1010
"automatedTest": "mocha ./tests/automatedTest.js --timeout 20000"
1111
},
1212
"keywords": [
13-
"o365",
13+
"graph",
1414
"microsoft",
1515
"nodejs",
1616
"unified"
1717
],
18-
"author": "PatSol",
18+
"author": "DevEd",
1919
"license": "MIT",
2020
"dependencies": {
21-
"body-parser": "~1.13.2",
22-
"cookie-parser": "~1.3.5",
23-
"cookie-session": "^1.2.0",
24-
"debug": "~2.2.0",
25-
"express": "~4.13.1",
26-
"express-session": "^1.11.3",
27-
"hbs": "~3.1.0",
28-
"morgan": "~1.6.1",
29-
"node-uuid": "^1.4.7",
30-
"oauth": "^0.9.14",
31-
"serve-favicon": "~2.3.0"
21+
"body-parser": "~1.17.1",
22+
"cookie-parser": "~1.4.3",
23+
"debug": "~2.6.3",
24+
"eslint-plugin-import": "^2.2.0",
25+
"eslint-plugin-react": "^6.10.3",
26+
"express": "~4.15.2",
27+
"express-session": "^1.15.2",
28+
"hbs": "~4.0.1",
29+
"morgan": "~1.8.1",
30+
"passport": "^0.3.2",
31+
"passport-azure-ad": "^3.0.5",
32+
"serve-favicon": "~2.4.2",
33+
"superagent": "^3.5.2",
34+
"uuid": "^3.0.1"
3235
},
3336
"devDependencies": {
34-
"eslint": "^2.3.0",
35-
"eslint-config-airbnb": "^6.1.0",
36-
"eslint-plugin-import": "^1.10.2",
37-
"eslint-plugin-react": "^4.2.1",
38-
"gulp": "^3.9.0",
39-
"gulp-nodemon": "^2.0.4",
40-
"mocha": "^2.4.5",
41-
"selenium-webdriver": "^2.53.3"
37+
"eslint": "^3.19.0",
38+
"eslint-config-airbnb": "^14.1.0",
39+
"eslint-plugin-jsx-a11y": "^4.0.0",
40+
"gulp": "^3.9.1",
41+
"gulp-nodemon": "^2.2.1",
42+
"mocha": "^3.2.0",
43+
"selenium-webdriver": "^3.3.0"
4244
}
43-
}
45+
}

starter-project/public/img/test.jpg

1.9 KB
Loading

starter-project/requestUtil.js

-25
This file was deleted.

0 commit comments

Comments
 (0)