Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
add starter project for walkthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane Diaz committed Sep 13, 2016
1 parent 56db9b3 commit 8ce9b9e
Show file tree
Hide file tree
Showing 24 changed files with 966 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions starter-project/.eslintrc.js
@@ -0,0 +1,18 @@
module.exports = {
'env': {
'browser': true,
'node': true,
},
'extends': 'airbnb/legacy',
'rules':{
'prefer-template': 0,
'comma-dangle': 0,
'func-names': 0,
'prefer-arrow-callback': 0,
'new-cap': 0,
'no-param-reassign': 0,
'no-use-before-define': 0,
'no-console': 0,
'linebreak-style': 0
}
};
21 changes: 21 additions & 0 deletions starter-project/LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions starter-project/NOTICES.md
@@ -0,0 +1,56 @@
# Third Party Notices for O365-Nodejs-Unified-API-Connect

This project incorporates material from the project(s) listed below (collectively, “Third Party Code”). Microsoft is not the original author of the Third Party Code. The original copyright notice and license, under which Microsoft Open Tech received such Third Party Code, are set out below together with the full text of such license. These notices and licenses are provided for informational purposes only. This Third Party Code is licensed to you under the terms set forth in the licenses set forth below. Microsoft Open Tech reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.

<hr />

## [github/gitignore](https://github.com/github/gitignore)

Copyright (c) 2014 GitHub, Inc.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

<hr />

## [strongloop/express](https://github.com/strongloop/express)

(The MIT License)

Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2013-2014 Roman Shtylman <shtylman+expressjs@gmail.com>
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 5 additions & 0 deletions starter-project/README.md
@@ -0,0 +1,5 @@
# Office 365 Node.js Connect starter project
This is the starter project used by the Node.js walkthrough in the [Microsoft Graph documentation](http://graph.microsoft.io).

## Copyright
Copyright (c) 2016 Microsoft. All rights reserved.
69 changes: 69 additions & 0 deletions starter-project/app.js
@@ -0,0 +1,69 @@
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
* See LICENSE in the project root for license information.
*/
// application dependencies
var express = require('express');
var session = require('express-session');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

app.use(favicon(path.join(__dirname, 'public', 'img', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// session middleware configuration
// see https://github.com/expressjs/session
app.use(session({
secret: '12345QWERTY-SECRET',
name: 'nodecookie',
resave: false,
saveUninitialized: false
}));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function (err, req, res) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});

module.exports = app;
57 changes: 57 additions & 0 deletions starter-project/authHelper.js
@@ -0,0 +1,57 @@
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
* See LICENSE in the project root for license information.
*/
var OAuth = require('oauth');
var uuid = require('node-uuid');

// The application registration (must match Azure AD config)
var credentials = {
authority: 'https://login.microsoftonline.com/common',
authorize_endpoint: '/oauth2/v2.0/authorize',
token_endpoint: '/oauth2/v2.0/token',
client_id: 'ENTER_YOUR_CLIENT_ID',
client_secret: 'ENTER_YOUR_SECRET',
redirect_uri: 'http://localhost:3000/login',
scope: 'User.Read Mail.Send offline_access'
};

/**
* Generate a fully formed uri to use for authentication based on the supplied resource argument
* @return {string} a fully formed uri with which authentication can be completed
*/
function getAuthUrl() {
return credentials.authority + credentials.authorize_endpoint +
'?client_id=' + credentials.client_id +
'&response_type=code' +
'&redirect_uri=' + credentials.redirect_uri +
'&scope=' + credentials.scope +
'&response_mode=query' +
'&nonce=' + uuid.v4() +
'&state=abcd';
}

/**
* Gets a token for a given resource.
* @param {string} code An authorization code returned from a client.
* @param {AcquireTokenCallback} callback The callback function.
*/
function getTokenFromCode(code, callback) {
}


/**
* Gets a new access token via a previously issued refresh token.
* @param {string} refreshToken A refresh token returned in a token response
* from a previous result of an authentication flow.
* @param {AcquireTokenCallback} callback The callback function.
*/
function getTokenFromRefreshToken(refreshToken, callback) {
}

exports.credentials = credentials;
exports.getAuthUrl = getAuthUrl;
exports.getTokenFromCode = getTokenFromCode;
exports.getTokenFromRefreshToken = getTokenFromRefreshToken;
exports.ACCESS_TOKEN_CACHE_KEY = 'ACCESS_TOKEN_CACHE_KEY';
exports.REFRESH_TOKEN_CACHE_KEY = 'REFRESH_TOKEN_CACHE_KEY';
90 changes: 90 additions & 0 deletions starter-project/bin/www
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('o365-nodejs-unified-api-connect:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
35 changes: 35 additions & 0 deletions starter-project/emailer.js
@@ -0,0 +1,35 @@
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
* See LICENSE in the project root for license information.
*/
// The contents of the outbound email message that will be sent to the user
var emailContent = '<html><head> <meta http-equiv=\'Content-Type\' content=\'text/html; charset=us-ascii\'> <title></title> </head><body style=\'font-family:calibri\'> <p>Congratulations {{name}},</p> <p>This is a message from the Office 365 Connect sample. You are well on your way to incorporating Office 365 services in your apps. </p> <h3>What&#8217;s next?</h3> <ul><li>Check out <a href=\'http://dev.office.com\' target=\'_blank\'>dev.office.com</a> to start building Office 365 apps today with all the latest tools, templates, and guidance to get started quickly.</li><li>Head over to the <a href=\'http://graph.microsoft.io/docs/api-reference\' target=\'blank\'>Microsoft Graph reference</a> to explore the rest of the APIs.</li><li>Browse other <a href=\'https://github.com/OfficeDev/\' target=\'_blank\'>samples on GitHub</a> to see more of the APIs in action.</li></ul> <h3>Give us feedback</h3> <ul><li>If you have any trouble running this sample, please <a href=\'\' target=\'_blank\'>log an issue</a>.</li><li>For general questions about the Office 365 APIs, post to <a href=\'http://stackoverflow.com/\' target=\'blank\'>Stack Overflow</a>. Make sure that your questions or comments are tagged with [office365].</li></ul><p>Thanks and happy coding!<br>Your Office 365 Development team </p> <div style=\'text-align:center; font-family:calibri\'> <table style=\'width:100%; font-family:calibri\'> <tbody> <tr> <td><a href=\'https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect\'>See on GitHub</a> </td> <td><a href=\'https://officespdev.uservoice.com/forums/224641-general/category/72301-documentation-guidance\'>Suggest on UserVoice</a> </td> <td><a href=\'http://twitter.com/share?text=I%20just%20started%20developing%20apps%20for%20%23Node.js%20using%20the%20%23Office365%20Connect%20app%20%40OfficeDev&amp;url=https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect\'>Share on Twitter</a> </td> </tr> </tbody> </table> </div> </body> </html>';

/**
* Returns the outbound email message content with the supplied name populated in the text
* @param {string} name The proper noun to use when addressing the email
* @return {string} the formatted email body
*/
function getEmailContent(name) {
return emailContent.replace('{{name}}', name);
}

/**
* Wraps the email's message content in the expected [soon-to-deserialized JSON] format
* @param {string} content the message body of the email message
* @param {string} recipient the email address to whom this message will be sent
* @return the message object to send over the wire
*/
function wrapEmail(content, recipient) {
}

/**
* Delegating method to wrap the formatted email message into a POST-able object
* @param {string} name the name used to address the recipient
* @param {string} recipient the email address to which the connect email will be sent
*/
function generateMailBody(name, recipient) {
return wrapEmail(getEmailContent(name), recipient);
}

exports.generateMailBody = generateMailBody;

0 comments on commit 8ce9b9e

Please sign in to comment.