- Prerequisites
- Register the application
- Build and run the sample
- Questions and comments
- Contributing
- Additional resources
This sample shows how to connect an ASP.NET 4.6 MVC web app to a Microsoft work or school (Azure Active Directory) or personal (Microsoft) account using the Microsoft Graph API to retrieve a user's profile information and upload that information to an Excel workbook. It uses the Microsoft Graph .NET Client Library to work with data returned by Microsoft Graph.
In addition, the sample uses the Microsoft Authentication Library (MSAL) for authentication. The MSAL SDK provides features for working with the Azure AD v2.0 endpoint, which enables developers to write a single code flow that handles authentication for both work or school (Azure Active Directory) and personal (Microsoft) accounts.
This library is suitable for use in a production environment. We provide the same production level support for this library as we do our current production libraries. During the preview we may make changes to the API, internal cache format, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. For instance, a change to the cache format may impact your users, such as requiring them to sign in again. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.
This sample requires the following:
- Visual Studio
- Either a Microsoft account or Office 365 for business account. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building Office 365 apps.
- Upload the demo.xlsx file in the root of this repository to the root folder of your OneDrive account. This file contains an empty table with two columns.
-
Sign into the App Registration Portal using either your personal or work or school account.
-
Choose Add an app.
-
Enter a name for the app, and choose Create application.
The registration page displays, listing the properties of your app.
-
Copy the Application Id. This is the unique identifier for your app.
-
Under Application Secrets, choose Generate New Password. Copy the password from the New password generated dialog.
You'll use the application ID and password to configure the sample app in the next section.
-
Under Platforms, choose Add platform.
-
Choose Web.
-
Make sure the Allow Implicit Flow check box is selected, and enter http://localhost:55065/ as the Redirect URI.
The Allow Implicit Flow option enables the hybrid flow. During authentication, this enables the app to receive both sign-in info (the id_token) and artifacts (in this case, an authorization code) that the app can use to obtain an access token.
-
Choose Save.
-
Download or clone the Microsoft Graph Connect Sample for ASP.NET 4.6.
-
Open the sample solution in Visual Studio.
-
In the Web.config file in the root directory, replace the ida:AppId and ida:AppSecret placeholder values with the application ID and password that you copied during app registration.
-
Press F5 to build and run the sample. This will restore NuGet package dependencies and open the app.
If you see any errors while installing packages, 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.
-
Sign in with your personal or work or school account and grant the requested permissions.
-
Choose the Get email address button. When the operation completes, the name and email address of the signed-in user are displayed on the page.
-
Choose the Upload to Excel button. The application creates a new row in the demo.xlsx workbook and adds the user name and email address to taht row. A Success message is displayed below the button.
We'd love to get your feedback about this sample. You can send us your questions and suggestions in the Issues section of this repository.
Your feedback is important to us. Connect with us on Stack Overflow. Tag your questions with [MicrosoftGraph].
If you'd like to contribute to this sample, see CONTRIBUTING.md.
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.
- Other Microsoft Graph Connect samples
- Microsoft Graph overview
- Office developer code samples
- Office dev center
Copyright (c) 2017 Microsoft. All rights reserved.