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 |
---|---|
This sample requires the following:
- Visual Studio 2013 with Update 4.
- Office 365 API Tools version 1.4.50428.2.
- An Office 365 account. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building Office 365 apps.
###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.
- 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.
- In the Solution Explorer window, right-click each project name and select Add -> Connected Service.
- A Services Manager dialog box will appear. Choose Office 365 and then Register your app.
- 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.
- 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.
- To register for the services used in this sample, choose the (Mail) - Send mail as you permission. The dialog will look like this:
- 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:
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.
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.
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].
- If you're interested in a sample that does a lot more with the Office 365 services in a Windows app, look at the Office 365 Starter Project for Windows Store App.
- For more details on what else you can do with the Office 365 services in your Windows app, start with the Getting started page on dev.office.com.
- Office 365 APIs platform overview
- Office 365 API code samples and videos
- Office developer code samples
- Office dev center
- Office 365 Code Snippets for Windows
- Office 365 Starter Project for Windows Store App
- Office 365 Profile sample for Windows
- Office 365 REST API Explorer for Sites
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.