Search code examples
office365office365-apps

Office 365 - Outlook Client object in Javascript using Outlook Mail REST API


I am trying to create a webapp in JavaScript using Office 365 APIs. I went through the link https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations and found the following code snippet:

var authContext;
var authToken; // for use with creating an outlookClient later.
authContext = new O365Auth.Context();
authContext.getIdToken("https://outlook.office365.com/")
   .then((function (token) {
       authToken = token;
       // The auth token also carries additional information. For example:
       userName = token.givenName + " " + token.familyName;
   }).bind(this), function (reason) {
       console.log('Failed to login. Error = ' + reason.message);
   });
// Once the authToken has been acquired, create an outlookClient. One place to do this is inside of the
//    ".then" function callback of authContext.getIdToken(...) above.
var outlookClient = new Microsoft.OutlookServices.Client('https://outlook.office365.com/api/v1.0', authToken.getAccessTokenFn('https://outlook.office365.com'));

When I use the above code it throws me an 'O365Auth' not defined. How do I create the Outlook Client object? Am I missing any JavaScript library that needs to be included as part of the project? Do I need to get the library from the nuget manager?

I created the project in napa and later on imported it into VS2013.

Please let me know if any more details are required.

Thanks!


Solution

  • That would be the Active Directory Authentication Library (ADAL) for JavaScript. There's a tutorial on creating a simple mail app on the OfficeDev GitHub here: https://github.com/OfficeDev/O365-JavaScript-GetStarted.