Connecting to Office 365 is the first step every app must take to start working with Office 365 services and data. This sample shows how to connect and use Microsoft Graph (previously called Office 365 unified API) to send an email. It uses Active Directory Authentication Library to make OAuth2 call.
![Office 365 ASP.NET MVC sample screenshot](./README assets/O365AspNetMVCSendMailPageScreenshot.png)
To use the Office 365 ASP.NET MVC Connect sample, you need the following:
-
Visual Studio 2015 installed and working on your development computer.
Note: This sample is written using Visual Studio 2015. If you're using Visual Studio 2013, make sure to change the compiler language version to 5 in the Web.config file: compilerOptions="/langversion:5
-
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.
Note: If you already have a subscription, the previous link sends you to a page with the message Sorry, you can’t add that to your current account. In that case use an account from your current Office 365 subscription.
- Sign in to the Azure portal.
- On the top bar, click on your account and under the Directory list, choose the Active Directory tenant where you wish to register your application.
- Click on More Services in the left hand nav, and choose Azure Active Directory.
- Click on App registrations and choose Add.
- Enter a friendly name for the application, for example 'MSGraphConnectAspNet' and select 'Web app/API' as the Application Type. For the Sign-on URL, enter http://localhost:55065. Click on Create to create the application.
- While still in the Azure portal, choose your application, click on Settings and choose Properties.
- Find the Application ID value and copy it to the clipboard.
- Configure Permissions for your application:
- In the Settings menu, choose the Required permissions section, click on Add, then Select an API, and select Microsoft Graph.
- Then, click on Select Permissions and select Sign in and read user profile and Send mail as a user. Click Select and then Done.
- In the Settings menu, choose the Keys section. Enter a description and select a duration for the key. Click Save.
- Important: Copy the key value. You won't be able to access this value again once you leave this pane. You will use this value as your app secret.
-
Open UnifiedApiConnect.sln file.
-
In Solution Explorer, open the Web.config file.
-
Replace ENTER_YOUR_CLIENT_ID with the app ID of your registered Azure application.
-
Replace ENTER_YOUR_SECRET with the key of your registered Azure application.
-
Press F5 to build and debug. Run the solution and sign in to Office 365 with your organizational account.
Note: Copy and paste the start page URL address http://localhost:55065/home/index, to a different browser if you get the following error during sign in:AADSTS70001: Application with identifier ad533dcf-ccad-469a-abed-acd1c8cc0d7d was not found in the directory.
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 [email protected] with any additional questions or comments.
We'd love to get your feedback about the Office 365 ASP.NET MVC Connect sample. 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 [MicrosoftGraph].
Copyright (c) 2015 Microsoft. All rights reserved.