Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

OfficeDev/O365-Win-Connect

Repository files navigation

[ARCHIVED] Connecting to Office 365 in Windows Store, Phone, and universal apps

Note: This repo is archived and no longer actively maintained. Security vulnerabilities may exist in the project, or its dependencies. If you plan to reuse or run any code from this repo, be sure to perform appropriate security checks on the code or dependencies first. Do not use this project as the starting point of a production Office Add-in. Always start your production code by using the Office/SharePoint development workload in Visual Studio, or the Yeoman generator for Office Add-ins, and follow security best practices as you develop the add-in.

日本 (日本語) (Japanese)

Authentication is the first step for any app that uses an Office 365 service. These three code samples show how to connect a user to an Office 365 tenant inside a Windows Store app, a Windows Phone 8.1 app, and a universal Windows app. Each solution contains a class called AuthenticationHelper that calls the Active Directory Authentication Library (ADAL) to authenticate a user.

The universal Windows app contains shared code files that you can use on both the Windows Store and Windows Phone 8.1 platforms to interact with an Office 365 tenant. The code files that implement the user interfaces for both the Phone and the Windows apps are separate, but the rest of the logic in the universal Windows app is mostly shared.

The interface is essentially the same on both platforms. The images below show what you'll see after you've authenticated in the apps.

Windows Phone 8.1 Windows Store
Application main page on a mobile device Application main page on a desktop device

Prerequisites and configuration

This sample requires the following:

###Register and configure the apps

The configuration steps are the same for all three samples (with one small extra step for the universal Windows app).

Note: If you see any errors while installing packages during step 7 (for example, Unable to find "Microsoft.IdentityModel.Clients.ActiveDirectory") make sure the local path where you placed the solution is not too long/deep. Moving the solution closer to the root of your drive resolves this issue.

You can register each app with the Office 365 API Tools for Visual Studio. Be sure to download and install the Office 365 API tools from the Visual Studio Gallery.

  1. Open the .sln file for the sample that you want to run (O365-Universal-Connect.sln, O365-Windows-Connect.sln, or O365-WinPhone-Connect.sln) using Visual Studio 2013.
  2. In the Solution Explorer window, right-click each project name and select Add -> Connected Service.
  3. A Services Manager dialog box will appear. Choose Office 365 and then Register your app.
  4. On the sign-in dialog box, enter the user name and password for your Office 365 tenant. This user name will often follow the pattern @.onmicrosoft.com. If you don't already have a an Office 365 tenant, you can get a free Developer Site as part of your MSDN Benefits or sign up for a free trial.
  5. After you're signed in, you will see a list of all the services. No permissions will be selected, since the app is not registered to use any services yet.
  6. To register for the services used in this sample, choose the (Mail) - Send mail as you permission. The dialog will look like this: O365 app registration page
  7. After you click OK in the Services Manager dialog box, assemblies for connecting to Office 365 APIs will be added to your project.

###Universal Windows app registration

The universal Windows app solution contains two projects: O365-Universal-Connect.Windows and O365-Universal-Connect.WindowsPhone. You can perform the registration steps for one project, and the Office 365 assemblies will be added to both projects. However, you'll still need to right-click the other project name and select Add -> Connected Service. When you do this, you'll see this prompt in the Services Manager dialog box:

Dialog confirming to register the project

Click the Yes button. This extra step will make sure that your app gets a redirect URI value in its Azure Active Directory settings. You don't need to know the value of this URI, but it's required for authenticating users in your app.

Build and debug

After you've loaded the solution in Visual Studio, press F5 to build and debug. If you're running a Windows Phone app, the Windows Phone emulator will launch. After the app launches, sign in with your organizational account to Office 365.

Questions and comments

We'd love to get your feedback on the O365 Windows Connect project. You can send your questions and suggestions to us in the Issues section of this repository.

Questions about Office 365 development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [Office365] and [API].

Next steps

Additional resources

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.