- Part 1 - Introduction to creating a multi-tenant Office 365 add-in using VS2015
- Part 2 - Creating the initial project and add-in registrations in Azure AD
- Part 3 - What did the wizard leave behind?
- Part 4 - Connecting Office 365 services to the project
- Part 5 - Adding code to send e-mails
- Part 6 - Switching to the Office 365 unified API (preview)
- Part 7 - Publishing the App to Azure
- Part 8 - Troubleshooting and tips
Adding Office 365 resources to your projectRight click on the web project and add a Connected Service.
I want to change the Azure AD settings and add e-mail capabilities, and thus pick Office 365 APIs, and click Configure.
Pick the domain of the Azure AD which will host the application, typically the Azure instance mentioned in the Prerequisites in Part 1.
On the next screen pick Use settings from an existing Azure AD application to access Office 365 API services. The client id should match the id you have in your web.config file.
Click Next until you get to the Mail settings, where you select Send mail as you. This allows the application to later send e-mails on the user’s behalf using the Office 365 API’s.
Move on further to Users and Groups.
Remember that I originally checked the Read directory data permission when creating the ASP.NET application in order to get the AdalTokenCache code inserted into the project. Now I can remove it as I’m not going to read multiple items from Azure AD.
When clicking Finish VS2015 will start adding the service and pull in needed nuget packages as well as reconfigure your App registration with the chosen delegate permissions.
Taking a look at web.config I see that two new lines have been added; the tentantid and domain where you are hosting the application. This is all good, but not needed as we are doing a multi-tenant application, so you can safely remove them again.
Check the web.config file.
Back in the Azure management portal, the app registration page reflects the changes you made in the wizard. One AAD permission for logging in and reading the users profile, and one Exchange permissions for sending e-mails.
What nuget packages has been added?Open up the nuget package manager and a reference to OutlookServices has been added. This library contains the OutlookServicesClient which is used to perform e-mail actions.
Now is also a perfect opportunity to upgrade some of the default packages which have been added to the project.
I upgraded Microsoft.Azure.ActiveDirectory.GraphClient from v2.0.2 to 2.1.0 which allows you to replace
IUser user = activeDirectoryClient.Users .Where(u => u.ObjectId.Equals(userObjectID)) .ExecuteAsync().Result.CurrentPage.ToList().First()
IUser user = activeDirectoryClient.Me.ExecuteAsync().Result
to get the current users object from AAD.
NOTE: The above code replacement is a necessity as I removed the application permission to Read directory data. The original code does a query on all items, while the latter loads your profile only. If you don’t replace it, you will get a permission error when loading the user.
Any other package upgrade should also be ok to make sure you are current.