GithubHelp home page GithubHelp logo

isabella232 / contacts-api-nodejs-appmodelv2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from officedev/contacts-api-nodejs-appmodelv2

0.0 0.0 0.0 1.47 MB

License: MIT License

JavaScript 83.46% CSS 1.20% HTML 15.34%

contacts-api-nodejs-appmodelv2's Introduction

page_type products languages extensions
sample
office-365
office-outlook
javascript
contentType createdDate
samples
9/3/2015 2:30:58 PM

Contacts API for Outlook using Node.js and the v2 App Model

This repository contains a Node.js that connects to the unified Contacts API for Outlook using the v2 App Model (which handles both consumer and business accounts). A full write-up of the solution is available at http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2015/09/04/building-office-365-applications-with-node-js-and-the-azure-ad-v2-app-model.aspx

Getting Started

To get started, clone the repo and then register an application at https://apps.dev.microsoft.com. The application should be registered for a web platform where you will be asked to provide an OAuth reply URL. Copy this reply URL along with the app's Client ID and Secret into appDetails section of authHelper.js:

var appDetails = {
 authority: 'https://login.microsoftonline.com/common',
 client_id: '1d9e332b-6c7d-4554-8b51-d398fef5f8a7',
 client_secret: 'Y0tgHpYAy3wQ0eF9NPkMPOf',
 redirect_url: 'http://localhost:5858/login',
 scopes: 'openid+https://outlook.office.com/contacts.read+offline_access'
};

authHelper.js

The solution uses an authHelper.js file, containing application registration details (client id, client secret, reply URL, permission scopes, etc) and utility functions for interacting with Azure AD. The three primary utility functions are detailed below:

  • getAuthUrl returns the authorization end-point in Azure AD with app details concatenated as URL parameters. The application can redirect to this end-point to initiate the first step of OAuth.
  • getTokenFromCode returns an access token using the app registration details and a provided authorization code (that is returned to the application after user signs in and authorizes the app)
  • getTokenFromRefreshToken returns an access token using the app registration details and a provided refresh token (that might come from cache)

Application Routes

The Node.js solution was built to using express and handlebars. Two routes handle the entire flow:

Index Route

  • If the user has a cached refresh token, use it to get a new token
    • If the new token is valid, get and display data
    • If the new token is invalid, send the user to login
  • If the user doesn’t have a cached refresh token, send the user to login

Login Route

  • If the URL contains an authorization code, use it to get tokens
    • If the token is valid, cache the refresh token and send the user back to index
    • If the token is invalid, and error must have occurred
  • If the URL doesn’t contain and authorization code, get the redirect URL for authorization and send user there

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

contacts-api-nodejs-appmodelv2's People

Contributors

davidchesnut avatar dependabot[bot] avatar lindalu-msft avatar o365devx avatar richdizz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.