This sample project provides a repository of code snippets that use the Microsoft Graph to perform common tasks, such as sending email, managing groups, and other activities from within an ASP.NET MVC app.
- Prerequisites
- Register the application
- Build and run the sample
- Examples
- Questions and comments
- Contributing
- Additional resources
This sample requires the following:
- Visual Studio 2015
- Either a Microsoft account or an Office 365 for business account. An Office 365 administrator account is required to run admin-level operations. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building apps.
- Clone this repo
- Install Node.js (if you haven't)
npm install
to install project dependencies after moving into the project directorynpm run build
to start TypeScript compiler and watch for changes (leave this open in another console)
- Register your application at https://apps.dev.microsoft.com/
- Add
http://localhost:3000
as a redirect URL under Platforms -> web - Add Application permissions (Directory.ReadWrite.All, Calendars.Read, User.ReadWrite.All, Mail.Send)
- Update
secrets.ts
with your application id - Update
secrets.ts
with an app secret (click 'generate new password') - Update
secrets.ts
with your tenant domain likeMOD507192.onmicrosoft.com
- Visit
https://login.microsoftonline.com/common/adminconsent?client_id=YOUR_APP_ID&state=12345&redirect_uri=http://localhost:3000
and grant the app access. ReplaceYOUR_APP_ID
. After granting access you will be redirected tolocalhost:3000
and nothing is running there, which is expected.
- Create an Azure function app at https://portal.azure.com and create a new 'Function App'
- You may need to setup credentials under
Platform Features / Code Deployment / Deployment Credentials
- Configure your app to allow Git deployments
- Under
Platform features
selectDeployment Options
and chooseLocal Git Repository
as the source.
- Under
- Add your Function as a git remote
- Under
General Settings
->Properties
, select yourGit Url
git remote add azure YOUR_GIT_URL
- Under
- Push a deployment
- (Make sure TypeScript recompiled after you updated your secrets file with npm run build. You should be seeing messages like 'Compilation complete' when you save the .ts files.)
git add .
,git commit -m 'Initial commit'
,git push azure master
- Since this starter project uses an HTTP trigger function, you can get a URL to execute your code. Click
Get function URL
, and open in a new tab. You can find this link by expanding the Functions panel in the left sidebar and clicking on our function.
- Check the logs and your function should be running!
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 Snippets samples
- Microsoft Graph overview
- Office developer code samples
- Office dev center
Copyright (c) 2016 Microsoft. All rights reserved.