Spartan
Spartan

Reputation: 301

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!

Upvotes: 1

Views: 2248

Answers (2)

Jason Johnston
Jason Johnston

Reputation: 17692

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.

Upvotes: 1

Kyle Hale
Kyle Hale

Reputation: 8120

Per this Github repository from the Office Dev team:

  1. Download and install the Office 365 API tools from the Visual Studio Gallery
  2. On the project node, right click and choose Add --> Connected Service
  3. At the top of the Services Manager dialog box, choose the Office 365 link, and then choose Register your app. Sign in with a tenant administrator account for your Office 365 developer.
  4. Set permissions for your app to use the O365 Mail service.
  5. This adds the JS libraries including O365auth to your project.

Upvotes: 1

Related Questions