Back
Updates

Office 365 API tool for Visual Studio 2013–update 3

Chakkaradeep Chandran is a program manager with Visual Studio.

Today, we are releasing an update to the Office 365 API Tool for Visual Studio 2013, which includes Office 365 API client libraries for .NET applications and JavaScript for multi-device hybrid applications. This update addresses some of the key feedback and bug fixes since the previous release.

Tooling updates

Updated flow

When you open the tool for the first time to add Office 365 APIs to your project, the Register your app link makes it explicit that you are registering a new application in Microsoft Azure Active Directory (AAD).

API tool for Visual Studio updates

 

When you click Register your app, you are required to sign in with your Office 365 credentials. Once successfully signed in, the tool displays the available Office 365 services that you can add to your project.

Support for managing redirect URIs in ASP.NET web application projects

Previously, if you published your web application project to a web server for staging/testing, you would get an error that the URL is not recognized, and the app would fail to authenticate with AAD. With the latest tooling update, you can specify Redirect URIs directly in the tooling for your web application project, making it easy to add the URL of your testing site (though you should still create a separate AAD entry for pushing the app to production).

API tool for Visual Studio 2

You can learn more about Redirect URIs by clicking the authentication response link in the tool or by reading the documentation here.

Status messages in Visual Studio output window

The tool now logs messages in the Visual Studio output window so you can see what changes are made once you add Office 365 services to your project.

API tool for Visual Studio

Support for Windows Phone 8.1 projects in Visual Studio

With today’s update, you can now associate your Windows Phone 8.1 project with an Azure Active Directory application using the Office 365 API tool.

This will perform the following changes to your Windows Phone 8.1 project:

  1. Register an Azure Active Directory application for your Windows Phone project in Windows Azure.
  2. Add the following NuGet package to your project:
    Microsoft Azure Active Directory Authentication Library (ADAL)

We are working on supporting the Office 365 API client libraries for Windows Phone 8.1 projects, but in the meantime, you can use the tool to register the Azure Active Directory application and configure the Office 365 services and permissions required for your Windows Phone project.

The Office 365 API client libraries section explains how to authenticate and call Office 365 APIs from your Windows Phone 8.1 projects.

Office 365 API client libraries

This update brings several changes and some new features to the Office 365 API client libraries.

Changes to Office 365 API authentication library

The previous release of Office 365 client libraries included the initial release of the Office 365 API authentication library, which was built on top of the Active Directory Authentication Library (ADAL). Based on your feedback we have improved the interoperability of the Office 365 API authentication library with ADAL to work well with other Azure-based services.

Note: Today’s update brings a breaking change to the code required to authenticate with Office 365 APIs. The Office 365 APIs and Tooling are still in preview, and we do try to avoid breaking changes. In this instance, because of the amount of feedback we got from developers, we thought the change was worth it before we formally release them.

For non-Xamarin-based applications, the new authentication flow is as follows (for Xamarin, continue to use the previously documented flow):

  1. Create the Office 365 Discovery Context.

DiscoveryContext discoveryContext = await DiscoveryContext.CreateAsync();

  1. Authenticate using Resource ID or Discovery Service.

Using Resource ID:

ResourceDiscoveryResult dcr =

    await discoveryContext.DiscoverResourceAsync(ServiceResourceId);

 Using Discovery Service:

CapabilityDiscoveryResult dcr =

    await discoveryContext.DiscoverCapabilityAsync(“Contacts”);

  1. Create the respective client object and pass in a delegate to retrieve the access token.

Func<Task<String>> getAccessToken = async () =>

{

    UserIdentifier userId = newUserIdentifier(dcr.UserId, UserIdentifierType.UniqueId);

    string clientId = discoveryContext.AppIdentity.ClientId;

    AuthenticationResult authResult = await discoveryContext.AuthenticationContext.AcquireTokenSilentAsync(ServiceResourceId, clientId, userId);

    return authResult.AccessToken;

};

ExchangeClient exchangeClient = newExchangeClient(ServiceEndpointUri, getAccessToken);

Updates to multi-device hybrid Cordova applications

  1. The files installed by the Office 365 API tools are now organized in a much more intuitive folder structure.
    API tool for Visual Studio
  1. Support has also been added for SharePoint Files. In concert with SharePoint Files, support for the Office 365 Discovery service is provided, which helps to find the SharePoint service endpoints for the logged-in user. For example, the following code sample authenticates a user, discovers the user’s SharePoint service endpoint, and then retrieves the user’s files and folders from the SharePoint File service:

    getCapability(capabilities: O365Discovery.ServiceCapability[],

                  capability: String): O365Discovery.ServiceCapability {

        var result;

        capabilities.forEach((serviceCapability, index, array) => {

            if (serviceCapability.capability === capability) {

                result = serviceCapability;

            }

        });

        return result;

    }

    getFiles() {

        var authContext = new O365Auth.Context();

        var discoveryContext = new O365Discovery.Context();

        discoveryContext.services(authContext.getAccessTokenFn(‘Microsoft.SharePoint’)).

Then (value => {

                var capability = this.getCapability(value, ‘MyFiles’),

                    sharePoint = new MS.SharePointClient(capability.endpointUri,

                                    authContext.getAccessTokenFn(capability.resourceId));

                sharePoint.files.getFileSystemItems().fetch().then(

                    value => {

                        value.currentPage.forEach((fileOrFolder, index, array) => {

                            // process file or folder…

                        });

                    }, error => {

                        // process error…

                    });

            }, error => {

                // process error…

            });

    }

Windows store, Windows forms, web, and Xamarin apps

Based on your feedback, several bug fixes were made in client libraries. For Windows store, Windows forms, and Web apps, the authentication flow has been refactored to allow the developer to have better control over discovery and authentication results.

Windows Phone 8.1 apps

While our client libraries are not yet supported by Windows Phone 8.1 (we are working on it!), you can interact with the Office 365 service endpoints by using the Active Directory Authentication Library (ADAL). When you configure a Windows Phone 8.1 application to use Office 365 APIs, a reference to the ADAL will be added to your project. There is sample code that can be found on GitHub.com at Azure AD Windows Phone 8.1 sample (as an aside, we also offer many good Azure AD samples). In order to interact with the services at the http level, you must authenticate with Azure AD (using the sample for guidance), and when you have obtained an authorization token from ADAL, add it to the http headers using the following:

String accessToken = “The access token that ADAL provides.”;

HttpClient client = newHttpClient();

HttpRequestMessage request =

newHttpRequestMessage(HttpMethod.Get, new Uri(“https://outlook.office365.com/ews/odata/Me/Inbox“));

request.Headers.Authorization = newAuthenticationHeaderValue(“Bearer”, accessToken);

var response = await client.SendAsync(request);

Installing the latest update

To install the latest update:

Once you’ve updated the tool, invoke the Office 365 API tool by right-clicking your project in the Solution Explorer, select Add ->Connected Service.

API tool for Visual Studio 5

For new projects, you will get the latest Office 365 API client libraries automatically by installing the latest tools. For existing projects using older versions of the libraries, you can manually update them as follows:

  1. In Visual Studio, right-click your project and then select Manage NuGet Packages.
  2. In the left pane, select Updates.
  3. In the Updates list, select Include Prerelease.
    You should now see updates available for the Office 365 API Client Libraries.
  4. For each Office 365 API Client Library, click Update to update the libraries to the latest version.

API tool for Visual Studio

 

Have feature requests? Let us know on UserVoice.

Have questions? Connect with us on StackOverflow. Tag your questions with [Office365] & [API].

Be sure to also connect with the team on the Office 365 Developer Network on Yammer.

Don’t miss the Channel 9 video, Office 365 API Tools for Visual Studio – Building Office 365 Android Apps with Xamarin, with Microsoft’s Beth Massi (@BethMassi).

Your feedback about the tools and APIs is important to us.

—Chakkaradeep Chandran

 

Join the conversation

1 comments
  1. When will JavaScript Windows Store Apps be supported? It’s strange it’s not already supported since you have support for Multi-device Hybrid Apps in JavaScript.

Comments are closed.