18 | }
19 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Extensions/AzureAdOptions.cs:
--------------------------------------------------------------------------------
1 | namespace MicrosoftGraphAspNetCoreConnectSample.Extensions
2 | {
3 | public class AzureAdOptions
4 | {
5 | public string ClientId { get; set; }
6 |
7 | public string ClientSecret { get; set; }
8 |
9 | public string Instance { get; set; }
10 |
11 | public string Domain { get; set; }
12 |
13 | public string TenantId { get; set; }
14 |
15 | public string CallbackPath { get; set; }
16 |
17 | public string BaseUrl { get; set; }
18 |
19 | public string Scopes { get; set; }
20 |
21 | public string GraphResourceId { get; set; }
22 |
23 | public string GraphScopes { get; set; }
24 |
25 | public string NotificationUrl { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Extensions/AzureAdOptions.cs:
--------------------------------------------------------------------------------
1 | namespace MicrosoftGraphAspNetCoreConnectSample.Extensions
2 | {
3 | public class AzureAdOptions
4 | {
5 | public string ClientId { get; set; }
6 |
7 | public string ClientSecret { get; set; }
8 |
9 | public string Instance { get; set; }
10 |
11 | public string Domain { get; set; }
12 |
13 | public string TenantId { get; set; }
14 |
15 | public string CallbackPath { get; set; }
16 |
17 | public string BaseUrl { get; set; }
18 |
19 | public string Scopes { get; set; }
20 |
21 | public string GraphResourceId { get; set; }
22 |
23 | public string GraphScopes { get; set; }
24 |
25 | public string NotificationUrl { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/images/blank-profile-picture.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/images/blank-profile-picture.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Models/MessageViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 | using MicrosoftGraphAspNetCoreConnectSample.Models.GraphWebhooks.Models;
6 |
7 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
8 | {
9 | // The data that displays in the Notification view.
10 | public class MessageViewModel
11 | {
12 | public Message Message { get; set; }
13 |
14 | // The ID of the user associated with the subscription.
15 | // Used to filter messages to display in the client.
16 | public string SubscribedUser { get; set; }
17 |
18 | public MessageViewModel(Message message, string subscribedUserId)
19 | {
20 | Message = message;
21 | SubscribedUser = subscribedUserId;
22 | }
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Models/MessageViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 | using MicrosoftGraphAspNetCoreConnectSample.Models.GraphWebhooks.Models;
6 |
7 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
8 | {
9 | // The data that displays in the Notification view.
10 | public class MessageViewModel
11 | {
12 | public Message Message { get; set; }
13 |
14 | // The ID of the user associated with the subscription.
15 | // Used to filter messages to display in the client.
16 | public string SubscribedUser { get; set; }
17 |
18 | public MessageViewModel(Message message, string subscribedUserId)
19 | {
20 | Message = message;
21 | SubscribedUser = subscribedUserId;
22 | }
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "AzureAd": {
3 | "Instance": "https://login.microsoftonline.com/",
4 | "CallbackPath": "/signin-oidc",
5 |
6 | "BaseUrl": "ENTER_YOUR_APP_URL", // e.g. https://YOURWEBAPP.azurewebsites.net
7 | "ClientId": "ENTER_YOUR_APP_ID ",
8 | "ClientSecret": "ENTER_YOUR_SECRET", // This sample uses a password (secret) to authenticate. Production apps should use a certificate.
9 | "NotificationUrl": "ENTER_YOUR_NOTIFYURL/notification/listen", // e.g. https://YOURWEBAPP.azurewebsites.net/notification/listen
10 | "Scopes": "openid email profile offline_access",
11 | "GraphResourceId": "https://graph.microsoft.com/",
12 | "GraphScopes": "User.Read User.ReadBasic.All Mail.Send"
13 | },
14 | "Logging": {
15 | "IncludeScopes": false,
16 | "LogLevel": {
17 | "Default": "Warning"
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "AzureAd": {
3 | "Instance": "https://login.microsoftonline.com/",
4 | "CallbackPath": "/signin-oidc",
5 |
6 | "BaseUrl": "ENTER_YOUR_APP_URL", // e.g. https://YOURWEBAPP.azurewebsites.net
7 | "ClientId": "ENTER_YOUR_APP_ID ",
8 | "ClientSecret": "ENTER_YOUR_SECRET", // This sample uses a password (secret) to authenticate. Production apps should use a certificate.
9 | "NotificationUrl": "ENTER_YOUR_NOTIFYURL/notification/listen", // e.g. https://YOURWEBAPP.azurewebsites.net/notification/listen
10 | "Scopes": "openid email profile offline_access",
11 | "GraphResourceId": "https://graph.microsoft.com/",
12 | "GraphScopes": "User.Read User.ReadBasic.All Mail.Send"
13 | },
14 | "Logging": {
15 | "IncludeScopes": false,
16 | "LogLevel": {
17 | "Default": "Warning"
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | padding-bottom: 20px;
4 | }
5 |
6 | /* Wrapping element */
7 | /* Set some basic padding to keep content from hitting the edges */
8 | .body-content {
9 | padding-left: 15px;
10 | padding-right: 15px;
11 | }
12 |
13 | /* Set widths on the form inputs since otherwise they're 100% wide */
14 | input,
15 | select,
16 | textarea {
17 | max-width: 280px;
18 | }
19 |
20 | /* Carousel */
21 | .carousel-caption p {
22 | font-size: 20px;
23 | line-height: 1.4;
24 | }
25 |
26 | /* Make .svg files in the carousel display properly in older browsers */
27 | .carousel-inner .item img[src$=".svg"] {
28 | width: 100%;
29 | }
30 |
31 | /* Hide/rearrange for smaller screens */
32 | @media screen and (max-width: 767px) {
33 | /* Hide captions */
34 | .carousel-caption {
35 | display: none;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | padding-bottom: 20px;
4 | }
5 |
6 | /* Wrapping element */
7 | /* Set some basic padding to keep content from hitting the edges */
8 | .body-content {
9 | padding-left: 15px;
10 | padding-right: 15px;
11 | }
12 |
13 | /* Set widths on the form inputs since otherwise they're 100% wide */
14 | input,
15 | select,
16 | textarea {
17 | max-width: 280px;
18 | }
19 |
20 | /* Carousel */
21 | .carousel-caption p {
22 | font-size: 20px;
23 | line-height: 1.4;
24 | }
25 |
26 | /* Make .svg files in the carousel display properly in older browsers */
27 | .carousel-inner .item img[src$=".svg"] {
28 | width: 100%;
29 | }
30 |
31 | /* Hide/rearrange for smaller screens */
32 | @media screen and (max-width: 767px) {
33 | /* Hide captions */
34 | .carousel-caption {
35 | display: none;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Models/ResourceData.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
4 | {
5 | public class ResourceData
6 | {
7 |
8 | // The ID of the resource.
9 | [JsonProperty(PropertyName = "id")]
10 | public string Id { get; set; }
11 |
12 | // The OData etag property.
13 | [JsonProperty(PropertyName = "@odata.etag")]
14 | public string ODataEtag { get; set; }
15 |
16 | // The OData ID of the resource. This is the same value as the resource property.
17 | [JsonProperty(PropertyName = "@odata.id")]
18 | public string ODataId { get; set; }
19 |
20 | // The OData type of the resource: "#Microsoft.Graph.Message", "#Microsoft.Graph.Event", or "#Microsoft.Graph.Contact".
21 | [JsonProperty(PropertyName = "@odata.type")]
22 | public string ODataType { get; set; }
23 | }
24 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Models/ResourceData.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
4 | {
5 | public class ResourceData
6 | {
7 |
8 | // The ID of the resource.
9 | [JsonProperty(PropertyName = "id")]
10 | public string Id { get; set; }
11 |
12 | // The OData etag property.
13 | [JsonProperty(PropertyName = "@odata.etag")]
14 | public string ODataEtag { get; set; }
15 |
16 | // The OData ID of the resource. This is the same value as the resource property.
17 | [JsonProperty(PropertyName = "@odata.id")]
18 | public string ODataId { get; set; }
19 |
20 | // The OData type of the resource: "#Microsoft.Graph.Message", "#Microsoft.Graph.Event", or "#Microsoft.Graph.Contact".
21 | [JsonProperty(PropertyName = "@odata.type")]
22 | public string ODataType { get; set; }
23 | }
24 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/add-custom-data/add-custom-data.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | device_code_flow_console
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | PreserveNewest
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/add-custom-data/add-custom-data.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | device_code_flow_console
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | PreserveNewest
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Project Name
2 |
3 | (short, 1-3 sentenced, description of the project)
4 |
5 | ## Features
6 |
7 | This project framework provides the following features:
8 |
9 | * Feature 1
10 | * Feature 2
11 | * ...
12 |
13 | ## Getting Started
14 |
15 | ### Prerequisites
16 |
17 | (ideally very short, if any)
18 |
19 | - OS
20 | - Library version
21 | - ...
22 |
23 | ### Installation
24 |
25 | (ideally very short)
26 |
27 | - npm install [package name]
28 | - mvn install
29 | - ...
30 |
31 | ### Quickstart
32 | (Add steps to get up and running quickly)
33 |
34 | 1. git clone [repository clone url]
35 | 2. cd [respository name]
36 | 3. ...
37 |
38 |
39 | ## Demo
40 |
41 | A demo app is included to show how to use the project.
42 |
43 | To run the demo, follow these steps:
44 |
45 | (Add steps to start up the demo)
46 |
47 | 1.
48 | 2.
49 | 3.
50 |
51 | ## Resources
52 |
53 | (Any additional resources or related projects)
54 |
55 | - Link to supporting information
56 | - Link to similar sample
57 | - ...
58 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 |
3 |
4 | @{
5 | ViewData["Title"] = "Error";
6 | }
7 |
8 |
9 |
Error.
10 |
An error occurred while processing your request.
11 |
@ViewBag.Message
12 |
13 |
Development Mode
14 |
15 | Swapping to Development environment will display more detailed information about the error that occurred.
16 |
17 |
18 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
19 |
15 | Swapping to Development environment will display more detailed information about the error that occurred.
16 |
17 |
18 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
19 |
20 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery-validation/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-validation",
3 | "homepage": "http://jqueryvalidation.org/",
4 | "repository": {
5 | "type": "git",
6 | "url": "git://github.com/jzaefferer/jquery-validation.git"
7 | },
8 | "authors": [
9 | "Jörn Zaefferer "
10 | ],
11 | "description": "Form validation made easy",
12 | "main": "dist/jquery.validate.js",
13 | "keywords": [
14 | "forms",
15 | "validation",
16 | "validate"
17 | ],
18 | "license": "MIT",
19 | "ignore": [
20 | "**/.*",
21 | "node_modules",
22 | "bower_components",
23 | "test",
24 | "demo",
25 | "lib"
26 | ],
27 | "dependencies": {
28 | "jquery": ">= 1.7.2"
29 | },
30 | "version": "1.14.0",
31 | "_release": "1.14.0",
32 | "_resolution": {
33 | "type": "version",
34 | "tag": "1.14.0",
35 | "commit": "c1343fb9823392aa9acbe1c3ffd337b8c92fed48"
36 | },
37 | "_source": "git://github.com/jzaefferer/jquery-validation.git",
38 | "_target": ">=1.8",
39 | "_originalSource": "jquery-validation"
40 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery-validation/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-validation",
3 | "homepage": "http://jqueryvalidation.org/",
4 | "repository": {
5 | "type": "git",
6 | "url": "git://github.com/jzaefferer/jquery-validation.git"
7 | },
8 | "authors": [
9 | "Jörn Zaefferer "
10 | ],
11 | "description": "Form validation made easy",
12 | "main": "dist/jquery.validate.js",
13 | "keywords": [
14 | "forms",
15 | "validation",
16 | "validate"
17 | ],
18 | "license": "MIT",
19 | "ignore": [
20 | "**/.*",
21 | "node_modules",
22 | "bower_components",
23 | "test",
24 | "demo",
25 | "lib"
26 | ],
27 | "dependencies": {
28 | "jquery": ">= 1.7.2"
29 | },
30 | "version": "1.14.0",
31 | "_release": "1.14.0",
32 | "_resolution": {
33 | "type": "version",
34 | "tag": "1.14.0",
35 | "commit": "c1343fb9823392aa9acbe1c3ffd337b8c92fed48"
36 | },
37 | "_source": "git://github.com/jzaefferer/jquery-validation.git",
38 | "_target": ">=1.8",
39 | "_originalSource": "jquery-validation"
40 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Microsoft Corporation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Microsoft Corporation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/bootstrap/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bootstrap",
3 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
4 | "keywords": [
5 | "css",
6 | "js",
7 | "less",
8 | "mobile-first",
9 | "responsive",
10 | "front-end",
11 | "framework",
12 | "web"
13 | ],
14 | "homepage": "http://getbootstrap.com",
15 | "license": "MIT",
16 | "moduleType": "globals",
17 | "main": [
18 | "less/bootstrap.less",
19 | "dist/js/bootstrap.js"
20 | ],
21 | "ignore": [
22 | "/.*",
23 | "_config.yml",
24 | "CNAME",
25 | "composer.json",
26 | "CONTRIBUTING.md",
27 | "docs",
28 | "js/tests",
29 | "test-infra"
30 | ],
31 | "dependencies": {
32 | "jquery": "1.9.1 - 3"
33 | },
34 | "version": "3.3.7",
35 | "_release": "3.3.7",
36 | "_resolution": {
37 | "type": "version",
38 | "tag": "v3.3.7",
39 | "commit": "0b9c4a4007c44201dce9a6cc1a38407005c26c86"
40 | },
41 | "_source": "https://github.com/twbs/bootstrap.git",
42 | "_target": "v3.3.7",
43 | "_originalSource": "bootstrap",
44 | "_direct": true
45 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/bootstrap/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bootstrap",
3 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
4 | "keywords": [
5 | "css",
6 | "js",
7 | "less",
8 | "mobile-first",
9 | "responsive",
10 | "front-end",
11 | "framework",
12 | "web"
13 | ],
14 | "homepage": "http://getbootstrap.com",
15 | "license": "MIT",
16 | "moduleType": "globals",
17 | "main": [
18 | "less/bootstrap.less",
19 | "dist/js/bootstrap.js"
20 | ],
21 | "ignore": [
22 | "/.*",
23 | "_config.yml",
24 | "CNAME",
25 | "composer.json",
26 | "CONTRIBUTING.md",
27 | "docs",
28 | "js/tests",
29 | "test-infra"
30 | ],
31 | "dependencies": {
32 | "jquery": "1.9.1 - 3"
33 | },
34 | "version": "3.3.7",
35 | "_release": "3.3.7",
36 | "_resolution": {
37 | "type": "version",
38 | "tag": "v3.3.7",
39 | "commit": "0b9c4a4007c44201dce9a6cc1a38407005c26c86"
40 | },
41 | "_source": "https://github.com/twbs/bootstrap.git",
42 | "_target": "v3.3.7",
43 | "_originalSource": "bootstrap",
44 | "_direct": true
45 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/MicrosoftGraphAspNetCoreConnectSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 | aspnet-MicrosoftGraphAspNetCoreConnectSample-ec1d62b9-d84d-45c8-8b3e-dc4e8b2ed850
6 | 0
7 | 2.0.0
8 | Mark Szabo
9 | Microsoft
10 | Microsoft Graph
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/MicrosoftGraphAspNetCoreConnectSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 | aspnet-MicrosoftGraphAspNetCoreConnectSample-ec1d62b9-d84d-45c8-8b3e-dc4e8b2ed850
6 | 0
7 | 2.0.0
8 | Mark Szabo
9 | Microsoft
10 | Microsoft Graph
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2016 Twitter, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch/HttpResponseMessageExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Http;
3 |
4 | namespace Batch
5 | {
6 | public static class HttpResponseMessageExtension
7 | {
8 | public static void WriteCodeAndReasonToConsole(this HttpResponseMessage response)
9 | {
10 | var defaultBGColor = Console.BackgroundColor;
11 | var defaultFGColor = Console.ForegroundColor;
12 |
13 | if (response.IsSuccessStatusCode)
14 | {
15 | Console.ForegroundColor = ConsoleColor.Black;
16 | Console.BackgroundColor = ConsoleColor.Green;
17 | Console.Write(response.StatusCode);
18 | }
19 |
20 | if (!response.IsSuccessStatusCode)
21 | {
22 | Console.ForegroundColor = ConsoleColor.White;
23 | Console.BackgroundColor = ConsoleColor.Red;
24 | Console.Write(response.StatusCode);
25 | Console.WriteLine(" - " + response.ReasonPhrase);
26 | }
27 | Console.BackgroundColor = defaultBGColor;
28 | Console.ForegroundColor = defaultFGColor;
29 | Console.WriteLine();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch-final/HttpResponseMessageExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Http;
3 |
4 | namespace Batch
5 | {
6 | public static class HttpResponseMessageExtension
7 | {
8 | public static void WriteCodeAndReasonToConsole(this HttpResponseMessage response)
9 | {
10 | var defaultBGColor = Console.BackgroundColor;
11 | var defaultFGColor = Console.ForegroundColor;
12 |
13 | if (response.IsSuccessStatusCode)
14 | {
15 | Console.ForegroundColor = ConsoleColor.Black;
16 | Console.BackgroundColor = ConsoleColor.Green;
17 | Console.Write(response.StatusCode);
18 | }
19 |
20 | if (!response.IsSuccessStatusCode)
21 | {
22 | Console.ForegroundColor = ConsoleColor.White;
23 | Console.BackgroundColor = ConsoleColor.Red;
24 | Console.Write(response.StatusCode);
25 | Console.WriteLine(" - " + response.ReasonPhrase);
26 | }
27 | Console.BackgroundColor = defaultBGColor;
28 | Console.ForegroundColor = defaultFGColor;
29 | Console.WriteLine();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/01-user-changes/UsersDeltaQuery.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2010
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsersDeltaQuery", "UsersDeltaQuery\UsersDeltaQuery.csproj", "{358B7833-D475-402C-A80C-BF5C42FA4B6E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {D2CB962B-EEFF-4818-9884-8EC096D00801}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2016 Twitter, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/add-custom-data.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2010
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "add-custom-data", "add-custom-data\add-custom-data.csproj", "{2EA73CD2-D137-4C7F-94FA-314D4998E9B1}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {3EF5DD5E-765A-475C-A5AB-7B841BD66C54}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/01-user-changes-final/UsersDeltaQuery.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2010
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsersDeltaQuery", "UsersDeltaQuery\UsersDeltaQuery.csproj", "{358B7833-D475-402C-A80C-BF5C42FA4B6E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {358B7833-D475-402C-A80C-BF5C42FA4B6E}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {D2CB962B-EEFF-4818-9884-8EC096D00801}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/add-custom-data.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2010
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "add-custom-data", "add-custom-data\add-custom-data.csproj", "{2EA73CD2-D137-4C7F-94FA-314D4998E9B1}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {2EA73CD2-D137-4C7F-94FA-314D4998E9B1}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {3EF5DD5E-765A-475C-A5AB-7B841BD66C54}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/add-custom-data/HttpResponseMessageExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Http;
3 |
4 | namespace add_custom_data
5 | {
6 | public static class HttpResponseMessageExtension
7 | {
8 | public static void WriteCodeAndReasonToConsole(this HttpResponseMessage response)
9 | {
10 |
11 |
12 | var defaultBGColor = Console.BackgroundColor;
13 | var defaultFGColor = Console.ForegroundColor;
14 |
15 | if (response.IsSuccessStatusCode)
16 | {
17 | Console.ForegroundColor = ConsoleColor.Black;
18 | Console.BackgroundColor = ConsoleColor.Green;
19 | Console.Write(response.StatusCode);
20 | }
21 |
22 | if (!response.IsSuccessStatusCode)
23 | {
24 | Console.ForegroundColor = ConsoleColor.White;
25 | Console.BackgroundColor = ConsoleColor.Red;
26 | Console.Write(response.StatusCode);
27 | Console.WriteLine(" - " + response.ReasonPhrase);
28 | }
29 | Console.BackgroundColor = defaultBGColor;
30 | Console.ForegroundColor = defaultFGColor;
31 | Console.WriteLine();
32 | }
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/add-custom-data/HttpResponseMessageExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Http;
3 |
4 | namespace add_custom_data
5 | {
6 | public static class HttpResponseMessageExtension
7 | {
8 | public static void WriteCodeAndReasonToConsole(this HttpResponseMessage response)
9 | {
10 |
11 |
12 | var defaultBGColor = Console.BackgroundColor;
13 | var defaultFGColor = Console.ForegroundColor;
14 |
15 | if (response.IsSuccessStatusCode)
16 | {
17 | Console.ForegroundColor = ConsoleColor.Black;
18 | Console.BackgroundColor = ConsoleColor.Green;
19 | Console.Write(response.StatusCode);
20 | }
21 |
22 | if (!response.IsSuccessStatusCode)
23 | {
24 | Console.ForegroundColor = ConsoleColor.White;
25 | Console.BackgroundColor = ConsoleColor.Red;
26 | Console.Write(response.StatusCode);
27 | Console.WriteLine(" - " + response.ReasonPhrase);
28 | }
29 | Console.BackgroundColor = defaultBGColor;
30 | Console.ForegroundColor = defaultFGColor;
31 | Console.WriteLine();
32 | }
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Models/NotificationsStore.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Web;
4 | using Microsoft.Extensions.Caching.Memory;
5 |
6 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
7 | {
8 | public class NotificationsStore
9 | {
10 | private static MemoryCache cache = new MemoryCache(new MemoryCacheOptions());
11 |
12 | // This sample temporarily stores the current subscription ID, client state, user object ID, and tenant ID.
13 | // This info is required so the NotificationController can retrieve an access token from the cache and validate the subscription.
14 | // Production apps typically use some method of persistent storage.
15 | public static void SaveNotifications(ConcurrentBag notifications)
16 | {
17 | cache.Set(
18 | "notificationArray",
19 | notifications,
20 | new TimeSpan(24, 0, 0));
21 | }
22 |
23 | public static ConcurrentBag GetNotifications()
24 | {
25 | ConcurrentBag notifications = (ConcurrentBag) cache.Get("notificationArray");
26 | return notifications;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Models/NotificationsStore.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Web;
4 | using Microsoft.Extensions.Caching.Memory;
5 |
6 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
7 | {
8 | public class NotificationsStore
9 | {
10 | private static MemoryCache cache = new MemoryCache(new MemoryCacheOptions());
11 |
12 | // This sample temporarily stores the current subscription ID, client state, user object ID, and tenant ID.
13 | // This info is required so the NotificationController can retrieve an access token from the cache and validate the subscription.
14 | // Production apps typically use some method of persistent storage.
15 | public static void SaveNotifications(ConcurrentBag notifications)
16 | {
17 | cache.Set(
18 | "notificationArray",
19 | notifications,
20 | new TimeSpan(24, 0, 0));
21 | }
22 |
23 | public static ConcurrentBag GetNotifications()
24 | {
25 | ConcurrentBag notifications = (ConcurrentBag) cache.Get("notificationArray");
26 | return notifications;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery-validation-unobtrusive/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-validation-unobtrusive",
3 | "version": "3.2.6",
4 | "homepage": "https://github.com/aspnet/jquery-validation-unobtrusive",
5 | "description": "Add-on to jQuery Validation to enable unobtrusive validation options in data-* attributes.",
6 | "main": [
7 | "jquery.validate.unobtrusive.js"
8 | ],
9 | "ignore": [
10 | "**/.*",
11 | "*.json",
12 | "*.md",
13 | "*.txt",
14 | "gulpfile.js"
15 | ],
16 | "keywords": [
17 | "jquery",
18 | "asp.net",
19 | "mvc",
20 | "validation",
21 | "unobtrusive"
22 | ],
23 | "authors": [
24 | "Microsoft"
25 | ],
26 | "license": "http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm",
27 | "repository": {
28 | "type": "git",
29 | "url": "git://github.com/aspnet/jquery-validation-unobtrusive.git"
30 | },
31 | "dependencies": {
32 | "jquery-validation": ">=1.8",
33 | "jquery": ">=1.8"
34 | },
35 | "_release": "3.2.6",
36 | "_resolution": {
37 | "type": "version",
38 | "tag": "v3.2.6",
39 | "commit": "13386cd1b5947d8a5d23a12b531ce3960be1eba7"
40 | },
41 | "_source": "git://github.com/aspnet/jquery-validation-unobtrusive.git",
42 | "_target": "3.2.6",
43 | "_originalSource": "jquery-validation-unobtrusive"
44 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery-validation-unobtrusive/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-validation-unobtrusive",
3 | "version": "3.2.6",
4 | "homepage": "https://github.com/aspnet/jquery-validation-unobtrusive",
5 | "description": "Add-on to jQuery Validation to enable unobtrusive validation options in data-* attributes.",
6 | "main": [
7 | "jquery.validate.unobtrusive.js"
8 | ],
9 | "ignore": [
10 | "**/.*",
11 | "*.json",
12 | "*.md",
13 | "*.txt",
14 | "gulpfile.js"
15 | ],
16 | "keywords": [
17 | "jquery",
18 | "asp.net",
19 | "mvc",
20 | "validation",
21 | "unobtrusive"
22 | ],
23 | "authors": [
24 | "Microsoft"
25 | ],
26 | "license": "http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm",
27 | "repository": {
28 | "type": "git",
29 | "url": "git://github.com/aspnet/jquery-validation-unobtrusive.git"
30 | },
31 | "dependencies": {
32 | "jquery-validation": ">=1.8",
33 | "jquery": ">=1.8"
34 | },
35 | "_release": "3.2.6",
36 | "_resolution": {
37 | "type": "version",
38 | "tag": "v3.2.6",
39 | "commit": "13386cd1b5947d8a5d23a12b531ce3960be1eba7"
40 | },
41 | "_source": "git://github.com/aspnet/jquery-validation-unobtrusive.git",
42 | "_target": "3.2.6",
43 | "_originalSource": "jquery-validation-unobtrusive"
44 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Models/Notification.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
5 | {
6 | // A change notification.
7 | public class Notification
8 | {
9 | // The type of change.
10 | [JsonProperty(PropertyName = "changeType")]
11 | public string ChangeType { get; set; }
12 |
13 | // The client state used to verify that the notification is from Microsoft Graph. Compare the value received with the notification to the value you sent with the subscription request.
14 | [JsonProperty(PropertyName = "clientState")]
15 | public string ClientState { get; set; }
16 |
17 | // The endpoint of the resource that changed. For example, a message uses the format ../Users/{user-id}/Messages/{message-id}
18 | [JsonProperty(PropertyName = "resource")]
19 | public string Resource { get; set; }
20 |
21 | // The UTC date and time when the webhooks subscription expires.
22 | [JsonProperty(PropertyName = "subscriptionExpirationDateTime")]
23 | public DateTimeOffset SubscriptionExpirationDateTime { get; set; }
24 |
25 | // The unique identifier for the webhooks subscription.
26 | [JsonProperty(PropertyName = "subscriptionId")]
27 | public string SubscriptionId { get; set; }
28 |
29 | // Properties of the changed resource.
30 | [JsonProperty(PropertyName = "resourceData")]
31 | public ResourceData ResourceData { get; set; }
32 | }
33 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Models/Notification.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
5 | {
6 | // A change notification.
7 | public class Notification
8 | {
9 | // The type of change.
10 | [JsonProperty(PropertyName = "changeType")]
11 | public string ChangeType { get; set; }
12 |
13 | // The client state used to verify that the notification is from Microsoft Graph. Compare the value received with the notification to the value you sent with the subscription request.
14 | [JsonProperty(PropertyName = "clientState")]
15 | public string ClientState { get; set; }
16 |
17 | // The endpoint of the resource that changed. For example, a message uses the format ../Users/{user-id}/Messages/{message-id}
18 | [JsonProperty(PropertyName = "resource")]
19 | public string Resource { get; set; }
20 |
21 | // The UTC date and time when the webhooks subscription expires.
22 | [JsonProperty(PropertyName = "subscriptionExpirationDateTime")]
23 | public DateTimeOffset SubscriptionExpirationDateTime { get; set; }
24 |
25 | // The unique identifier for the webhooks subscription.
26 | [JsonProperty(PropertyName = "subscriptionId")]
27 | public string SubscriptionId { get; set; }
28 |
29 | // Properties of the changed resource.
30 | [JsonProperty(PropertyName = "resourceData")]
31 | public ResourceData ResourceData { get; set; }
32 | }
33 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Views/Subscription/Index.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewBag.Title = "Index";
3 | bool isAuthenticated = Context.User.Identity.IsAuthenticated;
4 | }
5 |
Microsoft Graph Webhooks
6 |
7 |
You can subscribe to webhooks for specific resources (such as messages, events, and drive root items) to get notified about changes to the resource.
8 |
This sample creates a subscription for the me/mailFolders('Inbox')/messages resource and the created change type. The request body looks like this:
32 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Models/Message.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 |
6 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
7 | {
8 | /*
9 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
10 | * See LICENSE in the source repository root for complete license information.
11 | */
12 |
13 | using System;
14 | using Newtonsoft.Json;
15 | using System.Collections.Generic;
16 |
17 | namespace GraphWebhooks.Models
18 | {
19 | // An Outlook mail message (partial representation).
20 | // See https://developer.microsoft.com/graph/docs/api-reference/v1.0/resources/message
21 | public class Message
22 | {
23 | [JsonProperty(PropertyName = "id")]
24 | public string Id { get; set; }
25 |
26 | [JsonProperty(PropertyName = "subject")]
27 | public string Subject { get; set; }
28 |
29 | [JsonProperty(PropertyName = "bodyPreview")]
30 | public string BodyPreview { get; set; }
31 |
32 | [JsonProperty(PropertyName = "createdDateTime")]
33 | public DateTimeOffset CreatedDateTime { get; set; }
34 |
35 | [JsonProperty(PropertyName = "isRead")]
36 | public Boolean IsRead { get; set; }
37 |
38 | [JsonProperty(PropertyName = "conversationId")]
39 | public string ConversationId { get; set; }
40 |
41 | [JsonProperty(PropertyName = "changeKey")]
42 | public string ChangeKey { get; set; }
43 | }
44 |
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Models/Message.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 |
6 | namespace MicrosoftGraphAspNetCoreConnectSample.Models
7 | {
8 | /*
9 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
10 | * See LICENSE in the source repository root for complete license information.
11 | */
12 |
13 | using System;
14 | using Newtonsoft.Json;
15 | using System.Collections.Generic;
16 |
17 | namespace GraphWebhooks.Models
18 | {
19 | // An Outlook mail message (partial representation).
20 | // See https://developer.microsoft.com/graph/docs/api-reference/v1.0/resources/message
21 | public class Message
22 | {
23 | [JsonProperty(PropertyName = "id")]
24 | public string Id { get; set; }
25 |
26 | [JsonProperty(PropertyName = "subject")]
27 | public string Subject { get; set; }
28 |
29 | [JsonProperty(PropertyName = "bodyPreview")]
30 | public string BodyPreview { get; set; }
31 |
32 | [JsonProperty(PropertyName = "createdDateTime")]
33 | public DateTimeOffset CreatedDateTime { get; set; }
34 |
35 | [JsonProperty(PropertyName = "isRead")]
36 | public Boolean IsRead { get; set; }
37 |
38 | [JsonProperty(PropertyName = "conversationId")]
39 | public string ConversationId { get; set; }
40 |
41 | [JsonProperty(PropertyName = "changeKey")]
42 | public string ChangeKey { get; set; }
43 | }
44 |
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using System.Threading.Tasks;
26 |
27 | namespace Batch
28 | {
29 | class Program
30 | {
31 | static void Main(string[] args)
32 | {
33 | RunAsync(args).GetAwaiter().GetResult();
34 | }
35 |
36 | static async Task RunAsync(string[] args)
37 | {
38 | var batchDemo = new BatchDemo();
39 | await batchDemo.RunAsync();
40 |
41 | System.Console.WriteLine("Press ENTER to continue.");
42 | System.Console.ReadLine();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch-final/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using System.Threading.Tasks;
26 |
27 | namespace Batch
28 | {
29 | class Program
30 | {
31 | static void Main(string[] args)
32 | {
33 | RunAsync(args).GetAwaiter().GetResult();
34 | }
35 |
36 | static async Task RunAsync(string[] args)
37 | {
38 | var batchDemo = new BatchDemo();
39 | await batchDemo.RunAsync();
40 |
41 | System.Console.WriteLine("Press ENTER to continue.");
42 | System.Console.ReadLine();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright jQuery Foundation and other contributors, https://jquery.org/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright jQuery Foundation and other contributors, https://jquery.org/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphSDKHelper.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using System.Net.Http.Headers;
7 | using Microsoft.Graph;
8 |
9 | namespace MicrosoftGraphAspNetCoreConnectSample.Helpers
10 | {
11 | public class GraphSdkHelper : IGraphSdkHelper
12 | {
13 | private readonly IGraphAuthProvider _authProvider;
14 | private GraphServiceClient _graphClient;
15 |
16 | public GraphSdkHelper(IGraphAuthProvider authProvider)
17 | {
18 | _authProvider = authProvider;
19 | }
20 |
21 | // Get an authenticated Microsoft Graph Service client.
22 | public GraphServiceClient GetAuthenticatedClient(string userId)
23 | {
24 | _graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(
25 | async requestMessage =>
26 | {
27 | // Passing tenant ID to the sample auth provider to use as a cache key
28 | var accessToken = await _authProvider.GetUserAccessTokenAsync(userId);
29 |
30 | // Append the access token to the request
31 | requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
32 |
33 | // This header identifies the sample in the Microsoft Graph service. If extracting this code for your project please remove.
34 | requestMessage.Headers.Add("SampleID", "aspnetcore-connect-sample");
35 | }));
36 |
37 | return _graphClient;
38 | }
39 | }
40 | public interface IGraphSdkHelper
41 | {
42 | GraphServiceClient GetAuthenticatedClient(string userId);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphSDKHelper.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using System.Net.Http.Headers;
7 | using Microsoft.Graph;
8 |
9 | namespace MicrosoftGraphAspNetCoreConnectSample.Helpers
10 | {
11 | public class GraphSdkHelper : IGraphSdkHelper
12 | {
13 | private readonly IGraphAuthProvider _authProvider;
14 | private GraphServiceClient _graphClient;
15 |
16 | public GraphSdkHelper(IGraphAuthProvider authProvider)
17 | {
18 | _authProvider = authProvider;
19 | }
20 |
21 | // Get an authenticated Microsoft Graph Service client.
22 | public GraphServiceClient GetAuthenticatedClient(string userId)
23 | {
24 | _graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(
25 | async requestMessage =>
26 | {
27 | // Passing tenant ID to the sample auth provider to use as a cache key
28 | var accessToken = await _authProvider.GetUserAccessTokenAsync(userId);
29 |
30 | // Append the access token to the request
31 | requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
32 |
33 | // This header identifies the sample in the Microsoft Graph service. If extracting this code for your project please remove.
34 | requestMessage.Headers.Add("SampleID", "aspnetcore-connect-sample");
35 | }));
36 |
37 | return _graphClient;
38 | }
39 | }
40 | public interface IGraphSdkHelper
41 | {
42 | GraphServiceClient GetAuthenticatedClient(string userId);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Views/Notification/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewBag.Title = "Notification";
5 | }
6 |
7 |
8 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/01-user-changes-final/README.md:
--------------------------------------------------------------------------------
1 | # User changes delta query exercise
2 |
3 | This is a .NET Core console app and can be loaded, run and debugged through VS 2017 or VS Code. It uses
4 | both the Microsoft Authentication Library (MSAL) and the Microsoft Graph SDK.
5 |
6 | ## Pre-requisites
7 |
8 | 1. VS 2017 or VS Code
9 | 2. .NET Core 2.1 SDK
10 | 3. If using VS Code, you'll need the **C# for Visual Studio Code** extension
11 |
12 | ## Instructions
13 |
14 | ### Getting started
15 |
16 | 1. Clone or download the repo from here: [https://github.com/Azure-Samples/active-directory-coding-exercises](https://github.com/Azure-Samples/active-directory-coding-exercises)
17 | 2. Go to the `dev015-making-apps-more-powerful\01-user-changes` folder and open the solution file in VS 2017, or in VS Code open the 01-user-changes folder.
18 | 1. When opening in VS Code, click yes to resolve any required C# elements and also click to restore packages.
19 | 2. If package restore doesn't work as part of building the solution, you can do this manually too: Terminal -> New Terminal, and then in the new terminal, type:
20 | * `dotnet add package Microsoft.Graph`, and hit Restore button when prompted (if prompted)
21 | * `dotnet add package Microsoft.Identity.Client`, and hit Restore button when prompted (if prompted)
22 | 1. Go to the private preview app registration experience at [http://aka.ms/registeredappsprod](http://aka.ms/registeredappsprod). Register a new single tenant app, and create a new secret. Also get the client id. Configure the app with User.ReadWrite.All and then **grant** the app this permission.
23 | 3. Update the Config class in the Program.cs file with your app's co-ordinates.
24 | 4. In VS Code, Debug -> Open Configuration, and then click "Add Configuration" button. Then select an appropriate option (.NET: Launch .Net Core Console App)
25 | * Change "program" to the same execuatable name as in the existing .Net Core console app config
26 | * Change "console" to "externalTerminal" (not sure if this is platform independent - may need to look online)
27 | * Change "name" to "External Console"
28 | 8. Start Debugging (or F5/equivalent), but switch debug to use "External Console"
29 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 |
3 |
4 | @{
5 | ViewData["Title"] = "Home Page";
6 | }
7 |
8 |
This sample uses the OAuth2 client credentials flow using delegate permissions and the Azure AD v2.0 endpoint (MSAL). The sample uses only delegate permissions, therefore it does not require admin consent.
23 |
24 |
25 |
Get started
26 |
Change the email address in the box below to another valid account's email in the same tenant and click Load data!
This sample uses the OAuth2 client credentials flow using delegate permissions and the Azure AD v2.0 endpoint (MSAL). The sample uses only delegate permissions, therefore it does not require admin consent.
23 |
24 |
25 |
Get started
26 |
Change the email address in the box below to another valid account's email in the same tenant and click Load data!
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
@ViewData["Response"]
38 |
39 |
40 |
41 |
42 |
Send an email
43 |
51 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/01-user-changes/UsersDeltaQuery/Config.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using System;
26 | using System.Net.Http.Headers;
27 | using System.Threading.Tasks;
28 | using System.Collections.Generic;
29 |
30 | namespace UsersDeltaQuery
31 | {
32 | public static class Config
33 | {
34 | ///
35 | /// Static dictionary to store config parameters
36 | /// Fill in your app's values here
37 | ///
38 | private static Dictionary _config = new Dictionary() {
39 | // Adding Items to the dictionary
40 | {"clientId", "{your-client-id}" },
41 | {"clientSecret", "{your-client-secret}" },
42 | {"tenantId", "{your-tenant-name}" },
43 | {"authorityFormat", "https://login.microsoftonline.com/{0}/v2.0" },
44 | {"replyUri", "{your-reply-uri}" }
45 | };
46 |
47 | ///
48 | /// Access the Dictionary from external sources
49 | ///
50 | public static String GetConfig(String key)
51 | {
52 | // Try to get the result in the static Dictionary
53 | String result;
54 | if (_config.TryGetValue(key, out result))
55 | {
56 | return result;
57 | }
58 | else
59 | {
60 | return null;
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/01-user-changes-final/UsersDeltaQuery/Config.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using System;
26 | using System.Net.Http.Headers;
27 | using System.Threading.Tasks;
28 | using System.Collections.Generic;
29 |
30 | namespace UsersDeltaQuery
31 | {
32 | public static class Config
33 | {
34 | ///
35 | /// Static dictionary to store config parameters
36 | /// Fill in your app's values here
37 | ///
38 | private static Dictionary _config = new Dictionary() {
39 | // Adding Items to the dictionary
40 | {"clientId", "{your-client-id}" },
41 | {"clientSecret", "{your-client-secret}" },
42 | {"tenantId", "{your-tenant-name}" },
43 | {"authorityFormat", "https://login.microsoftonline.com/{0}/v2.0" },
44 | {"replyUri", "{your-reply-uri}" }
45 | };
46 |
47 | ///
48 | /// Access the Dictionary from external sources
49 | ///
50 | public static String GetConfig(String key)
51 | {
52 | // Try to get the result in the static Dictionary
53 | String result;
54 | if (_config.TryGetValue(key, out result))
55 | {
56 | return result;
57 | }
58 | else
59 | {
60 | return null;
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/wwwroot/email_template.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
Congratulations!
12 |
This is a message from the Microsoft Graph Connect Sample. You are well on your way to incorporating Microsoft Graph endpoints in your apps.
13 |
What's next?
14 |
Check out developer.microsoft.com/graph to start building Microsoft Graph apps today with all the latest tools, templates, and guidance to get started quickly.
15 |
Use the Graph Explorer to explore the rest of the APIs and start your testing.
20 | If you have any trouble running this sample, please log an issue on our repository.
21 |
22 |
23 | For general questions about the Microsoft Graph API, post to Stack Overflow. Make sure that your questions or comments are tagged with [microsoftgraph].
24 |
25 |
26 | Thanks, and happy coding!
27 | Your Microsoft Graph samples development team
28 |
This is a message from the Microsoft Graph Connect Sample. You are well on your way to incorporating Microsoft Graph endpoints in your apps.
13 |
What's next?
14 |
Check out developer.microsoft.com/graph to start building Microsoft Graph apps today with all the latest tools, templates, and guidance to get started quickly.
15 |
Use the Graph Explorer to explore the rest of the APIs and start your testing.
20 | If you have any trouble running this sample, please log an issue on our repository.
21 |
22 |
23 | For general questions about the Microsoft Graph API, post to Stack Overflow. Make sure that your questions or comments are tagged with [microsoftgraph].
24 |
25 |
26 | Thanks, and happy coding!
27 | Your Microsoft Graph samples development team
28 |
46 |
47 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/README.md:
--------------------------------------------------------------------------------
1 | # Adding custom data to Microsoft Graph resources
2 |
3 | This exercise will walk you through working with custom data for resources using Microsoft Graph.
4 | It uses .Net Core 2.1, MSAL, and raw REST requests to Microsoft Graph.
5 | It also uses the newly (preview) supported device code flow using MSAL.
6 |
7 | ## Pre-requisites
8 |
9 | 1. VS 2017 or VS Code
10 | 2. .NET Core 2.1 SDK
11 | 3. If using VS Code, you'll need the **C# for Visual Studio Code** extension
12 | 4. An administrative user
13 |
14 | ## Instructions
15 |
16 | ### Getting started
17 |
18 | 1. Clone or download the repo from here: [https://github.com/Azure-Samples/active-directory-coding-exercises](https://github.com/Azure-Samples/active-directory-coding-exercises)
19 | 2. Go to the `dev015-making-apps-more-powerful\04-custom-data` folder and open the solution file in VS 2017, or in VS Code open the `04-custom-data` folder.
20 | 1. When opening in VS Code, click yes to resolve any required C# elements and also click to restore packages.
21 | 2. If package restore doesn't work as part of building the solution, you can do this manually too: Terminal -> New Terminal, and then in the new terminal, type:
22 | * `dotnet add package Microsoft.Graph`, and hit Restore button when prompted (if prompted)
23 | * `dotnet add package Microsoft.Identity.Client`, and hit Restore button when prompted (if prompted)
24 | 3. Go to the private preview app registration experience at [http://aka.ms/registeredappsprod](http://aka.ms/registeredappsprod).
25 | 1. Register a new single tenant **public client** app (on the first creation page, change "web app" to "public client" and create).
26 | 2. Go to Manage -> Manifest and open the app manifest. (The app manifest is simply a GET/PATCH on the `/application` resource in Microsoft Graph.) Due to a bug, you'll need to change the `allowPublicClient` property to `true`.
27 | 3. Now get the client id. You'll need this for the next step.
28 | 4. Update the `appsettings.json` file with your app's co-ordinates (clientId and tenant - like contoso.onmicrosoft.com).
29 | 5. In VS Code, Debug -> Open Configuration, and then click "Add Configuration" button. Then select an appropriate option (.NET: Launch .Net Core Console App)
30 | * Change "program" to the same execuatable name as in the existing .Net Core console app config
31 | * Change "console" to "externalTerminal" (not sure if this is platform independent - may need to look online)
32 | * Change "name" to "External Console"
33 |
34 | 6. Start Debugging (or F5/equivalent), but switch debug to use "External Console"
35 | 7. In the partially built state, you'll be asked to go through the device code flow.
36 | 1. Per the instructions in the console, copy the `code`, and go to [https://mmicrosoft.com/devicelogin](https://mmicrosoft.com/devicelogin).
37 | 2. Enter the code and click continue
38 | 3. Now follow the standard flow for sign in
39 |
40 | You should now be signed in to the app, and in the console window you'll see the signed-in user's profile and manager, open extensions and schema extensions manipulations.
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch/README.md:
--------------------------------------------------------------------------------
1 | # User changes delta query exercise
2 |
3 | This is a .NET Core console app and can be loaded, run and debugged through VS 2017 or VS Code. It uses
4 | both the Microsoft Authentication Library (MSAL) and the Microsoft Graph SDK.
5 | It's partially completed, and the instuctions walk through the steps you'll need
6 | to take to complete the exercise - by adding code and guidance on what to add in the right places, such as:
7 |
8 | ```C#
9 | ///
10 | /// Some hints that can help you.
11 | /// This topic also provides relevant background https://developer.microsoft.com/en-us/graph/docs/concepts/delta_query_users
12 | ///
13 |
14 | /// ADD CODE HERE
15 | ```
16 |
17 | All changes in this exercise are in the `Program.cs` file, although the getting started steps include some changes to the configuration in `Config.cs`
18 |
19 | ## Pre-requisites
20 |
21 | 1. VS 2017 or VS Code
22 | 2. .NET Core 2.1 SDK
23 | 3. If using VS Code, you'll need the **C# for Visual Studio Code** extension
24 |
25 | ## Instructions
26 |
27 | ### Getting started
28 |
29 | 1. Clone or download the repo from here: [https://github.com/Azure-Samples/active-directory-coding-exercises](https://github.com/Azure-Samples/active-directory-coding-exercises)
30 | 2. Go to the `dev015-making-apps-more-powerful\03-batch` folder and open the solution file in VS 2017, or in VS Code open the `03-batch` folder.
31 | 1. When opening in VS Code, click yes to resolve any required C# elements and also click to restore packages.
32 | 2. If package restore doesn't work as part of building the solution, you can do this manually too: Terminal -> New Terminal, and then in the new terminal, type:
33 | * `dotnet add package Microsoft.Graph`, and hit Restore button when prompted (if prompted)
34 | * `dotnet add package Microsoft.Identity.Client`, and hit Restore button when prompted (if prompted)
35 | 1. Go to the private preview app registration experience at [http://aka.ms/appregprivatepreview](http://aka.ms/appregprivatepreview) . Register a new single tenant app, and create a new secret. Also get the client id. Configure the app with **User.Read.All** and **Sites.Read.All** permissions and then **grant** the app this permission.
36 | 3. Update the Config class in the Program.cs file with your app's co-ordinates.
37 | 4. In VS Code, Debug -> Open Configuration, and then click "Add Configuration" button. Then select an appropriate option (.NET: Launch .Net Core Console App)
38 | * Change "program" to the same execuatable name as in the existing .Net Core console app config
39 | * Change "console" to "externalTerminal" (not sure if this is platform independent - may need to look online)
40 | * Change "name" to "External Console"
41 | 8. Start Debugging (or F5/equivalent), but switch debug to use "External Console"
42 | 9. In the partially built state, the app should run, and appear to create a user, ask you to press a key, and then it cleans up, and is done.
43 |
44 | ### Excercise
45 |
46 | Generate the batch request in order to fetch below data
47 |
48 | 1. User's first and last name along with job title.
49 | 2. Recent documents that user has been working on.
50 |
51 | Ensure documents are not fetched in case of error accessing the user profile.
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch-final/README.md:
--------------------------------------------------------------------------------
1 | # User changes delta query exercise
2 |
3 | This is a .NET Core console app and can be loaded, run and debugged through VS 2017 or VS Code. It uses
4 | both the Microsoft Authentication Library (MSAL) and the Microsoft Graph SDK.
5 | It's partially completed, and the instuctions walk through the steps you'll need
6 | to take to complete the exercise - by adding code and guidance on what to add in the right places, such as:
7 |
8 | ```C#
9 | ///
10 | /// Some hints that can help you.
11 | /// This topic also provides relevant background https://developer.microsoft.com/en-us/graph/docs/concepts/delta_query_users
12 | ///
13 |
14 | /// ADD CODE HERE
15 | ```
16 |
17 | All changes in this exercise are in the `Program.cs` file, although the getting started steps include some changes to the configuration in `Config.cs`
18 |
19 | ## Pre-requisites
20 |
21 | 1. VS 2017 or VS Code
22 | 2. .NET Core 2.1 SDK
23 | 3. If using VS Code, you'll need the **C# for Visual Studio Code** extension
24 |
25 | ## Instructions
26 |
27 | ### Getting started
28 |
29 | 1. Clone or download the repo from here: [https://github.com/Azure-Samples/active-directory-coding-exercises](https://github.com/Azure-Samples/active-directory-coding-exercises)
30 | 2. Go to the `dev015-making-apps-more-powerful\05-batch-final` folder and open the solution file in VS 2017, or in VS Code open the `05-batch-final` folder.
31 | 1. When opening in VS Code, click yes to resolve any required C# elements and also click to restore packages.
32 | 2. If package restore doesn't work as part of building the solution, you can do this manually too: Terminal -> New Terminal, and then in the new terminal, type:
33 | * `dotnet add package Microsoft.Graph`, and hit Restore button when prompted (if prompted)
34 | * `dotnet add package Microsoft.Identity.Client`, and hit Restore button when prompted (if prompted)
35 | 1. Go to the private preview app registration experience at [http://aka.ms/appregprivatepreview](http://aka.ms/appregprivatepreview). Register a new single tenant app, and create a new secret. Also get the client id. Configure the app with User.Read.All and Sites.Read.All permissions and then **grant** the app this permission.
36 | 3. Update the Config class in the Program.cs file with your app's co-ordinates.
37 | 4. In VS Code, Debug -> Open Configuration, and then click "Add Configuration" button. Then select an appropriate option (.NET: Launch .Net Core Console App)
38 | * Change "program" to the same execuatable name as in the existing .Net Core console app config
39 | * Change "console" to "externalTerminal" (not sure if this is platform independent - may need to look online)
40 | * Change "name" to "External Console"
41 | 8. Start Debugging (or F5/equivalent), but switch debug to use "External Console"
42 | 9. In the partially built state, the app should run, and appear to create a user, ask you to press a key, and then it cleans up, and is done.
43 |
44 | ### Exercise
45 |
46 | Generate the batch request in order to fetch below data
47 |
48 | 1. User's first and last name along with job title.
49 | 2. Recent documents that user has been working on.
50 |
51 | Ensure documents are not fetched in case of error accessing the user profile.
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/add-custom-data/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using Microsoft.Identity.Client;
26 | using System;
27 | using System.Threading.Tasks;
28 |
29 | namespace add_custom_data
30 | {
31 | ///
32 | /// This sample signs-in a user in a two steps process:
33 | /// - it displays a URL and a code, and asks the user to navigate to the URL in a Web browser, and enter the code
34 | /// - then the user signs-in (and goes through multiple factor authentication if needed)
35 | /// and the sample displays information about the user by calling the Microsoft Graph in the name of the signed-in user
36 | ///
37 | /// It uses the Device code flow, which is normally used for devices which don't have a Web browser (which is the case for a
38 | /// .NET Core app, iOT, etc ...)
39 | ///
40 | /// For more information see https://aka.ms/msal-net-device-code-flow
41 | ///
42 | class Program
43 | {
44 | static void Main(string[] args)
45 | {
46 | try
47 | {
48 | RunAsync(args).GetAwaiter().GetResult();
49 | }
50 | catch (Exception ex)
51 | {
52 | Console.ForegroundColor = ConsoleColor.Red;
53 | Console.WriteLine(ex.Message);
54 | Console.ResetColor();
55 | }
56 |
57 | }
58 |
59 | static async Task RunAsync(string[] args)
60 | {
61 | AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
62 | var app = new PublicClientApplication(config.ClientId, config.Authority);
63 |
64 | MyInformation myInformation = new MyInformation(app);
65 | await myInformation.DisplayMeAndMyManagerAsync();
66 |
67 | var openExtensionsDemo = new OpenExtensionsDemo(app);
68 | await openExtensionsDemo.RunAsync();
69 |
70 | var schemaExtensionDemo = new SchemaExtensionsDemo(app);
71 | await schemaExtensionDemo.RunAsync();
72 |
73 | System.Console.WriteLine("Press ENTER to continue.");
74 | System.Console.ReadLine();
75 | }
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/add-custom-data/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using Microsoft.Identity.Client;
26 | using System;
27 | using System.Threading.Tasks;
28 |
29 | namespace add_custom_data
30 | {
31 | ///
32 | /// This sample signs-in a user in a two steps process:
33 | /// - it displays a URL and a code, and asks the user to navigate to the URL in a Web browser, and enter the code
34 | /// - then the user signs-in (and goes through multiple factor authentication if needed)
35 | /// and the sample displays information about the user by calling the Microsoft Graph in the name of the signed-in user
36 | ///
37 | /// It uses the Device code flow, which is normally used for devices which don't have a Web browser (which is the case for a
38 | /// .NET Core app, iOT, etc ...)
39 | ///
40 | /// For more information see https://aka.ms/msal-net-device-code-flow
41 | ///
42 | class Program
43 | {
44 | static void Main(string[] args)
45 | {
46 | try
47 | {
48 | RunAsync(args).GetAwaiter().GetResult();
49 | }
50 | catch (Exception ex)
51 | {
52 | Console.ForegroundColor = ConsoleColor.Red;
53 | Console.WriteLine(ex.Message);
54 | Console.ResetColor();
55 | }
56 |
57 | }
58 |
59 | static async Task RunAsync(string[] args)
60 | {
61 | AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
62 | var app = new PublicClientApplication(config.ClientId, config.Authority);
63 |
64 | MyInformation myInformation = new MyInformation(app);
65 | await myInformation.DisplayMeAndMyManagerAsync();
66 |
67 | var openExtensionsDemo = new OpenExtensionsDemo(app);
68 | await openExtensionsDemo.RunAsync();
69 |
70 | var schemaExtensionDemo = new SchemaExtensionsDemo(app);
71 | await schemaExtensionDemo.RunAsync();
72 |
73 | System.Console.WriteLine("Press ENTER to continue.");
74 | System.Console.ReadLine();
75 | }
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/dev019-doing-more-with-graph/EmailHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net.Http;
5 | using System.Net.Http.Headers;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.Azure.WebJobs.Host;
9 | using Microsoft.Graph;
10 | using Newtonsoft.Json;
11 |
12 | namespace InclusivityFeedbackLoop
13 | {
14 | class EmailHelper
15 | {
16 | ///
17 | /// Compose and send a new email.
18 | ///
19 | /// The subject line of the email.
20 | /// The body of the email.
21 | /// A semicolon-separated list of email addresses.
22 | ///
23 | public static async Task ComposeAndSendMailAsync(string subject,
24 | string bodyContent,
25 | string recipient,
26 | string token, TraceWriter log)
27 | {
28 | List recipientList = new List();
29 |
30 | recipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } });
31 |
32 | try
33 | {
34 | var email = new Message
35 | {
36 | Body = new ItemBody
37 | {
38 | Content = bodyContent,
39 | ContentType = BodyType.Html,
40 | },
41 | Subject = subject,
42 | ToRecipients = recipientList
43 | };
44 |
45 | try
46 | {
47 | //initialize HttpClient for REST call
48 | HttpClient client = new HttpClient();
49 | client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
50 |
51 | //setup the client post
52 | string contentString = JsonConvert.SerializeObject(email);
53 |
54 | HttpContent content = new StringContent("{\"message\":" + contentString + "}");
55 | //Specify the content type.
56 | content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
57 | HttpResponseMessage result = await client.PostAsync(
58 | "https://graph.microsoft.com/v1.0/users/" + recipient + "/sendMail", content);
59 |
60 | log.Info(result.ToString());
61 |
62 | if (result.IsSuccessStatusCode)
63 | {
64 | //email send successfully.
65 | log.Info("Email sent successfully. ");
66 | }
67 | }
68 | catch (ServiceException exception)
69 | {
70 | throw new Exception("We could not send the message: " + exception.Error == null ? "No error message returned." : exception.Error.Message);
71 | }
72 | }
73 |
74 | catch (Exception e)
75 | {
76 | throw new Exception("We could not send the message: " + e.Message);
77 | }
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch/BatchDemo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using Microsoft.Identity.Client;
26 | using Newtonsoft.Json.Linq;
27 | using System;
28 | using System.Net.Http;
29 | using System.Net.Http.Headers;
30 | using System.Text;
31 | using System.Threading.Tasks;
32 |
33 | namespace Batch
34 | {
35 | class BatchDemo
36 | {
37 | public async Task RunAsync()
38 | {
39 | var tenantId = Config.GetConfig("tenantId");
40 | ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(
41 | Config.GetConfig("clientId"),
42 | String.Format(Config.GetConfig("authorityFormat"), tenantId),
43 | Config.GetConfig("replyUri"),
44 | new ClientCredential(Config.GetConfig("clientSecret")),
45 | null,
46 | new TokenCache());
47 | var authenticationResult = await daemonClient.AcquireTokenForClientAsync(new string[] { "https://graph.microsoft.com/.default" });
48 | var accessToken = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
49 |
50 | using (var client = new HttpClient())
51 | {
52 | client.BaseAddress = new Uri("https://graph.microsoft.com/beta/");
53 | client.DefaultRequestHeaders.Authorization = accessToken;
54 |
55 | await DemoBatch(client);
56 | }
57 | }
58 |
59 | async Task DemoBatch(HttpClient client)
60 | {
61 | HttpRequestMessage request = null;
62 |
63 | ///
64 | /// Batching basics: https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching
65 | ///
66 |
67 | // Add code here to generate batch request to fetch user's givenName, surName and department, and documents that user worked on recently.
68 |
69 | var response = await client.SendAsync(request);
70 | response.WriteCodeAndReasonToConsole();
71 | Console.WriteLine(JValue.Parse(await response.Content.ReadAsStringAsync()).ToString(Newtonsoft.Json.Formatting.Indented));
72 | Console.WriteLine();
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Helpers/SessionTokenCache.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using Microsoft.Extensions.Caching.Memory;
7 | using Microsoft.Identity.Client;
8 | using System.Text;
9 |
10 | namespace MicrosoftGraphAspNetCoreConnectSample.Helpers
11 | {
12 | // Store the user's token information.
13 | public class SessionTokenCache
14 | {
15 | private static readonly object FileLock = new object();
16 | private readonly string _cacheId;
17 | private readonly IMemoryCache _memoryCache;
18 | private TokenCache _cache = new TokenCache();
19 |
20 | public SessionTokenCache(string userId, IMemoryCache memoryCache)
21 | {
22 | // not object, we want the SUB
23 | _cacheId = userId + "_TokenCache";
24 | _memoryCache = memoryCache;
25 |
26 | Load();
27 | }
28 |
29 | public TokenCache GetCacheInstance()
30 | {
31 | _cache.SetBeforeAccess(BeforeAccessNotification);
32 | _cache.SetAfterAccess(AfterAccessNotification);
33 | Load();
34 |
35 | return _cache;
36 | }
37 |
38 | public void SaveUserStateValue(string state)
39 | {
40 | lock (FileLock)
41 | {
42 | _memoryCache.Set(_cacheId + "_state", Encoding.ASCII.GetBytes(state));
43 | }
44 | }
45 |
46 | public string ReadUserStateValue()
47 | {
48 | string state;
49 | lock (FileLock)
50 | {
51 | state = Encoding.ASCII.GetString(_memoryCache.Get(_cacheId + "_state") as byte[]);
52 | }
53 |
54 | return state;
55 | }
56 |
57 | public void Load()
58 | {
59 | lock (FileLock)
60 | {
61 | _cache.Deserialize(_memoryCache.Get(_cacheId) as byte[]);
62 | }
63 | }
64 |
65 | public void Persist()
66 | {
67 | lock (FileLock)
68 | {
69 | // reflect changes in the persistent store
70 | _memoryCache.Set(_cacheId, _cache.Serialize());
71 | // once the write operation took place, restore the HasStateChanged bit to false
72 | _cache.HasStateChanged = false;
73 | }
74 | }
75 |
76 | // Empties the persistent store.
77 | public void Clear()
78 | {
79 | _cache = null;
80 | lock (FileLock) {
81 | _memoryCache.Remove(_cacheId);
82 | }
83 | }
84 |
85 | // Triggered right before MSAL needs to access the cache.
86 | // Reload the cache from the persistent store in case it changed since the last access.
87 | private void BeforeAccessNotification(TokenCacheNotificationArgs args)
88 | {
89 | Load();
90 | }
91 |
92 | // Triggered right after MSAL accessed the cache.
93 | private void AfterAccessNotification(TokenCacheNotificationArgs args)
94 | {
95 | // if the access operation resulted in a cache update
96 | if (_cache.HasStateChanged)
97 | {
98 | Persist();
99 | }
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Startup.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using Microsoft.AspNetCore.Authentication.Cookies;
7 | using Microsoft.AspNetCore.Authentication.OpenIdConnect;
8 | using Microsoft.AspNetCore.Builder;
9 | using Microsoft.AspNetCore.Hosting;
10 | using Microsoft.Extensions.Configuration;
11 | using Microsoft.Extensions.DependencyInjection;
12 | using Microsoft.Extensions.Logging;
13 | using MicrosoftGraphAspNetCoreConnectSample.Extensions;
14 | using MicrosoftGraphAspNetCoreConnectSample.Helpers;
15 |
16 | namespace MicrosoftGraphAspNetCoreConnectSample
17 | {
18 | public class Startup
19 | {
20 | public Startup(IConfiguration configuration)
21 | {
22 | Configuration = configuration;
23 | }
24 |
25 | public IConfiguration Configuration { get; }
26 | public const string ObjectIdentifierType = "http://schemas.microsoft.com/identity/claims/objectidentifier";
27 | public const string TenantIdType = "http://schemas.microsoft.com/identity/claims/tenantid";
28 |
29 | // This method gets called by the runtime. Use this method to add services to the container.
30 | public void ConfigureServices(IServiceCollection services)
31 | {
32 | services.AddAuthentication(sharedOptions =>
33 | {
34 | sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
35 | sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
36 | sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
37 | })
38 | .AddAzureAd(options => Configuration.Bind("AzureAd", options))
39 | .AddCookie();
40 |
41 | services.AddMvc();
42 |
43 | // This sample uses an in-memory cache for tokens and subscriptions. Production apps will typically use some method of persistent storage.
44 | services.AddMemoryCache();
45 | services.AddSession();
46 |
47 | // Add application services.
48 | //services.AddSingleton(Configuration);
49 | services.AddSingleton();
50 | services.AddTransient();
51 | }
52 |
53 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
54 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
55 | {
56 | loggerFactory.AddConsole(Configuration.GetSection("Logging"));
57 | loggerFactory.AddDebug();
58 |
59 | if (env.IsDevelopment())
60 | {
61 | app.UseDeveloperExceptionPage();
62 | app.UseBrowserLink();
63 | }
64 | else
65 | {
66 | app.UseExceptionHandler("/Home/Error");
67 | }
68 |
69 | app.UseStaticFiles();
70 |
71 | app.UseSession();
72 |
73 | app.UseAuthentication();
74 |
75 | app.UseMvc(routes =>
76 | {
77 | routes.MapRoute(
78 | name: "default",
79 | template: "{controller=Home}/{action=Index}/{id?}");
80 | });
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Helpers/SessionTokenCache.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using Microsoft.Extensions.Caching.Memory;
7 | using Microsoft.Identity.Client;
8 | using System.Text;
9 |
10 | namespace MicrosoftGraphAspNetCoreConnectSample.Helpers
11 | {
12 | // Store the user's token information.
13 | public class SessionTokenCache
14 | {
15 | private static readonly object FileLock = new object();
16 | private readonly string _cacheId;
17 | private readonly IMemoryCache _memoryCache;
18 | private TokenCache _cache = new TokenCache();
19 |
20 | public SessionTokenCache(string userId, IMemoryCache memoryCache)
21 | {
22 | // not object, we want the SUB
23 | _cacheId = userId + "_TokenCache";
24 | _memoryCache = memoryCache;
25 |
26 | Load();
27 | }
28 |
29 | public TokenCache GetCacheInstance()
30 | {
31 | _cache.SetBeforeAccess(BeforeAccessNotification);
32 | _cache.SetAfterAccess(AfterAccessNotification);
33 | Load();
34 |
35 | return _cache;
36 | }
37 |
38 | public void SaveUserStateValue(string state)
39 | {
40 | lock (FileLock)
41 | {
42 | _memoryCache.Set(_cacheId + "_state", Encoding.ASCII.GetBytes(state));
43 | }
44 | }
45 |
46 | public string ReadUserStateValue()
47 | {
48 | string state;
49 | lock (FileLock)
50 | {
51 | state = Encoding.ASCII.GetString(_memoryCache.Get(_cacheId + "_state") as byte[]);
52 | }
53 |
54 | return state;
55 | }
56 |
57 | public void Load()
58 | {
59 | lock (FileLock)
60 | {
61 | _cache.Deserialize(_memoryCache.Get(_cacheId) as byte[]);
62 | }
63 | }
64 |
65 | public void Persist()
66 | {
67 | lock (FileLock)
68 | {
69 | // reflect changes in the persistent store
70 | _memoryCache.Set(_cacheId, _cache.Serialize());
71 | // once the write operation took place, restore the HasStateChanged bit to false
72 | _cache.HasStateChanged = false;
73 | }
74 | }
75 |
76 | // Empties the persistent store.
77 | public void Clear()
78 | {
79 | _cache = null;
80 | lock (FileLock) {
81 | _memoryCache.Remove(_cacheId);
82 | }
83 | }
84 |
85 | // Triggered right before MSAL needs to access the cache.
86 | // Reload the cache from the persistent store in case it changed since the last access.
87 | private void BeforeAccessNotification(TokenCacheNotificationArgs args)
88 | {
89 | Load();
90 | }
91 |
92 | // Triggered right after MSAL accessed the cache.
93 | private void AfterAccessNotification(TokenCacheNotificationArgs args)
94 | {
95 | // if the access operation resulted in a cache update
96 | if (_cache.HasStateChanged)
97 | {
98 | Persist();
99 | }
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Startup.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using Microsoft.AspNetCore.Authentication.Cookies;
7 | using Microsoft.AspNetCore.Authentication.OpenIdConnect;
8 | using Microsoft.AspNetCore.Builder;
9 | using Microsoft.AspNetCore.Hosting;
10 | using Microsoft.Extensions.Configuration;
11 | using Microsoft.Extensions.DependencyInjection;
12 | using Microsoft.Extensions.Logging;
13 | using MicrosoftGraphAspNetCoreConnectSample.Extensions;
14 | using MicrosoftGraphAspNetCoreConnectSample.Helpers;
15 |
16 | namespace MicrosoftGraphAspNetCoreConnectSample
17 | {
18 | public class Startup
19 | {
20 | public Startup(IConfiguration configuration)
21 | {
22 | Configuration = configuration;
23 | }
24 |
25 | public IConfiguration Configuration { get; }
26 | public const string ObjectIdentifierType = "http://schemas.microsoft.com/identity/claims/objectidentifier";
27 | public const string TenantIdType = "http://schemas.microsoft.com/identity/claims/tenantid";
28 |
29 | // This method gets called by the runtime. Use this method to add services to the container.
30 | public void ConfigureServices(IServiceCollection services)
31 | {
32 | services.AddAuthentication(sharedOptions =>
33 | {
34 | sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
35 | sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
36 | sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
37 | })
38 | .AddAzureAd(options => Configuration.Bind("AzureAd", options))
39 | .AddCookie();
40 |
41 | services.AddMvc();
42 |
43 | // This sample uses an in-memory cache for tokens and subscriptions. Production apps will typically use some method of persistent storage.
44 | services.AddMemoryCache();
45 | services.AddSession();
46 |
47 | // Add application services.
48 | //services.AddSingleton(Configuration);
49 | services.AddSingleton();
50 | services.AddTransient();
51 | }
52 |
53 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
54 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
55 | {
56 | loggerFactory.AddConsole(Configuration.GetSection("Logging"));
57 | loggerFactory.AddDebug();
58 |
59 | if (env.IsDevelopment())
60 | {
61 | app.UseDeveloperExceptionPage();
62 | app.UseBrowserLink();
63 | }
64 | else
65 | {
66 | app.UseExceptionHandler("/Home/Error");
67 | }
68 |
69 | app.UseStaticFiles();
70 |
71 | app.UseSession();
72 |
73 | app.UseAuthentication();
74 |
75 | app.UseMvc(routes =>
76 | {
77 | routes.MapRoute(
78 | name: "default",
79 | template: "{controller=Home}/{action=Index}/{id?}");
80 | });
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphAuthProvider.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using System;
7 | using System.Threading.Tasks;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Caching.Memory;
10 | using Microsoft.Identity.Client;
11 | using Microsoft.Graph;
12 | using System.Linq;
13 | using MicrosoftGraphAspNetCoreConnectSample.Extensions;
14 |
15 | namespace MicrosoftGraphAspNetCoreConnectSample.Helpers
16 | {
17 | public class GraphAuthProvider : IGraphAuthProvider
18 | {
19 | private readonly IMemoryCache _memoryCache;
20 | private TokenCache _userTokenCache;
21 |
22 | // Properties used to get and manage an access token.
23 | private readonly string _appId;
24 | private readonly ClientCredential _credential;
25 | private readonly string[] _scopes;
26 | private readonly string _redirectUri;
27 | private static string _notificationUrl;
28 |
29 | public GraphAuthProvider(IMemoryCache memoryCache, IConfiguration configuration)
30 | {
31 | var azureOptions = new AzureAdOptions();
32 | configuration.Bind("AzureAd", azureOptions);
33 |
34 | _appId = azureOptions.ClientId;
35 | _credential = new ClientCredential(azureOptions.ClientSecret);
36 | _scopes = azureOptions.GraphScopes.Split(new[] { ' ' });
37 | _redirectUri = azureOptions.BaseUrl + azureOptions.CallbackPath;
38 | _notificationUrl = azureOptions.NotificationUrl;
39 | _memoryCache = memoryCache;
40 | }
41 |
42 | // Gets an access token. First tries to get the access token from the token cache.
43 | // Using password (secret) to authenticate. Production apps should use a certificate.
44 | public async Task GetUserAccessTokenAsync(string userId)
45 | {
46 | _userTokenCache = new SessionTokenCache(userId, _memoryCache).GetCacheInstance();
47 |
48 | var cca = new ConfidentialClientApplication(
49 | _appId,
50 | _redirectUri,
51 | _credential,
52 | _userTokenCache,
53 | null);
54 |
55 | if (!cca.Users.Any()) throw new ServiceException(new Error
56 | {
57 | Code = "TokenNotFound",
58 | Message = "User not found in token cache. Maybe the server was restarted."
59 | });
60 |
61 | try
62 | {
63 | var result = await cca.AcquireTokenSilentAsync(_scopes, cca.Users.First());
64 | return result.AccessToken;
65 | }
66 |
67 | // Unable to retrieve the access token silently.
68 | catch (Exception)
69 | {
70 | throw new ServiceException(new Error
71 | {
72 | Code = GraphErrorCode.AuthenticationFailure.ToString(),
73 | Message = "Caller needs to authenticate. Unable to retrieve the access token silently."
74 | });
75 | }
76 | }
77 |
78 | public static string GetNotificationUrl()
79 | {
80 | return _notificationUrl;
81 | }
82 | }
83 |
84 | public interface IGraphAuthProvider
85 | {
86 | Task GetUserAccessTokenAsync(string userId);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks-final/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphAuthProvider.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | using System;
7 | using System.Threading.Tasks;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Caching.Memory;
10 | using Microsoft.Identity.Client;
11 | using Microsoft.Graph;
12 | using System.Linq;
13 | using MicrosoftGraphAspNetCoreConnectSample.Extensions;
14 |
15 | namespace MicrosoftGraphAspNetCoreConnectSample.Helpers
16 | {
17 | public class GraphAuthProvider : IGraphAuthProvider
18 | {
19 | private readonly IMemoryCache _memoryCache;
20 | private TokenCache _userTokenCache;
21 |
22 | // Properties used to get and manage an access token.
23 | private readonly string _appId;
24 | private readonly ClientCredential _credential;
25 | private readonly string[] _scopes;
26 | private readonly string _redirectUri;
27 | private static string _notificationUrl;
28 |
29 | public GraphAuthProvider(IMemoryCache memoryCache, IConfiguration configuration)
30 | {
31 | var azureOptions = new AzureAdOptions();
32 | configuration.Bind("AzureAd", azureOptions);
33 |
34 | _appId = azureOptions.ClientId;
35 | _credential = new ClientCredential(azureOptions.ClientSecret);
36 | _scopes = azureOptions.GraphScopes.Split(new[] { ' ' });
37 | _redirectUri = azureOptions.BaseUrl + azureOptions.CallbackPath;
38 | _notificationUrl = azureOptions.NotificationUrl;
39 | _memoryCache = memoryCache;
40 | }
41 |
42 | // Gets an access token. First tries to get the access token from the token cache.
43 | // Using password (secret) to authenticate. Production apps should use a certificate.
44 | public async Task GetUserAccessTokenAsync(string userId)
45 | {
46 | _userTokenCache = new SessionTokenCache(userId, _memoryCache).GetCacheInstance();
47 |
48 | var cca = new ConfidentialClientApplication(
49 | _appId,
50 | _redirectUri,
51 | _credential,
52 | _userTokenCache,
53 | null);
54 |
55 | if (!cca.Users.Any()) throw new ServiceException(new Error
56 | {
57 | Code = "TokenNotFound",
58 | Message = "User not found in token cache. Maybe the server was restarted."
59 | });
60 |
61 | try
62 | {
63 | var result = await cca.AcquireTokenSilentAsync(_scopes, cca.Users.First());
64 | return result.AccessToken;
65 | }
66 |
67 | // Unable to retrieve the access token silently.
68 | catch (Exception)
69 | {
70 | throw new ServiceException(new Error
71 | {
72 | Code = GraphErrorCode.AuthenticationFailure.ToString(),
73 | Message = "Caller needs to authenticate. Unable to retrieve the access token silently."
74 | });
75 | }
76 | }
77 |
78 | public static string GetNotificationUrl()
79 | {
80 | return _notificationUrl;
81 | }
82 | }
83 |
84 | public interface IGraphAuthProvider
85 | {
86 | Task GetUserAccessTokenAsync(string userId);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data/add-custom-data/AuthenticationConfig.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using System;
27 | using System.Globalization;
28 | using System.IO;
29 |
30 | namespace add_custom_data
31 | {
32 | ///
33 | /// Description of the configuration of an AzureAD public client application (desktop/mobile application). This should
34 | /// match the application registration done in the Azure portal
35 | ///
36 | public class AuthenticationConfig
37 | {
38 | ///
39 | /// instance of Azure AD, for example public Azure or a Sovereign cloud (Azure China, Germany, US government, etc ...)
40 | ///
41 | public string AzureADInstance { get; set; } = "https://login.microsoftonline.com/{0}";
42 |
43 | ///
44 | /// The Tenant is:
45 | /// - either the tenant ID of the Azure AD tenant in which this application is registered (a guid)
46 | /// or a domain name associated with the tenant
47 | /// - or 'organizations' (for a multi-tenant application)
48 | ///
49 | public string Tenant { get; set; }
50 |
51 | ///
52 | /// Guid used by the application to uniquely identify itself to Azure AD
53 | ///
54 | public string ClientId { get; set; }
55 |
56 | ///
57 | /// URL of the authority
58 | ///
59 | public string Authority
60 | {
61 | get
62 | {
63 | return String.Format(CultureInfo.InvariantCulture, AzureADInstance, Tenant);
64 | }
65 | }
66 |
67 | ///
68 | /// Reads the configuration from a json file
69 | ///
70 | /// Path to the configuration json file
71 | /// AuthenticationConfig read from the json file
72 | public static AuthenticationConfig ReadFromJsonFile(string path)
73 | {
74 | IConfigurationRoot Configuration;
75 |
76 | var builder = new ConfigurationBuilder()
77 | .SetBasePath(Directory.GetCurrentDirectory())
78 | .AddJsonFile(path);
79 |
80 | Configuration = builder.Build();
81 | return Configuration.Get();
82 | }
83 | }
84 |
85 |
86 |
87 | }
88 |
89 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/04-custom-data-final/add-custom-data/AuthenticationConfig.cs:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2015 Microsoft Corporation
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using System;
27 | using System.Globalization;
28 | using System.IO;
29 |
30 | namespace add_custom_data
31 | {
32 | ///
33 | /// Description of the configuration of an AzureAD public client application (desktop/mobile application). This should
34 | /// match the application registration done in the Azure portal
35 | ///
36 | public class AuthenticationConfig
37 | {
38 | ///
39 | /// instance of Azure AD, for example public Azure or a Sovereign cloud (Azure China, Germany, US government, etc ...)
40 | ///
41 | public string AzureADInstance { get; set; } = "https://login.microsoftonline.com/{0}";
42 |
43 | ///
44 | /// The Tenant is:
45 | /// - either the tenant ID of the Azure AD tenant in which this application is registered (a guid)
46 | /// or a domain name associated with the tenant
47 | /// - or 'organizations' (for a multi-tenant application)
48 | ///
49 | public string Tenant { get; set; }
50 |
51 | ///
52 | /// Guid used by the application to uniquely identify itself to Azure AD
53 | ///
54 | public string ClientId { get; set; }
55 |
56 | ///
57 | /// URL of the authority
58 | ///
59 | public string Authority
60 | {
61 | get
62 | {
63 | return String.Format(CultureInfo.InvariantCulture, AzureADInstance, Tenant);
64 | }
65 | }
66 |
67 | ///
68 | /// Reads the configuration from a json file
69 | ///
70 | /// Path to the configuration json file
71 | /// AuthenticationConfig read from the json file
72 | public static AuthenticationConfig ReadFromJsonFile(string path)
73 | {
74 | IConfigurationRoot Configuration;
75 |
76 | var builder = new ConfigurationBuilder()
77 | .SetBasePath(Directory.GetCurrentDirectory())
78 | .AddJsonFile(path);
79 |
80 | Configuration = builder.Build();
81 | return Configuration.Get();
82 | }
83 | }
84 |
85 |
86 |
87 | }
88 |
89 |
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/02-webhooks/MicrosoftGraphAspNetCoreConnectSample/Controllers/SubscriptionController.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3 | * See LICENSE in the source repository root for complete license information.
4 | */
5 |
6 | namespace MicrosoftGraphAspNetCoreConnectSample.Controllers
7 | {
8 | using System;
9 | using System.Threading.Tasks;
10 | using Newtonsoft.Json;
11 | using Microsoft.AspNetCore.Authorization;
12 | using Microsoft.AspNetCore.Hosting;
13 | using Microsoft.AspNetCore.Mvc;
14 | using Microsoft.Extensions.Configuration;
15 | using MicrosoftGraphAspNetCoreConnectSample.Helpers;
16 | using MicrosoftGraphAspNetCoreConnectSample.Models;
17 | using ServiceException = Microsoft.Graph.ServiceException;
18 | using Subscription = Microsoft.Graph.Subscription;
19 |
20 | public class SubscriptionController : Controller
21 | {
22 | private readonly IConfiguration _configuration;
23 | private readonly IHostingEnvironment _env;
24 | private readonly IGraphSdkHelper _graphSdkHelper;
25 | private static string subscriptionId;
26 |
27 | public SubscriptionController(IConfiguration configuration, IHostingEnvironment hostingEnvironment, IGraphSdkHelper graphSdkHelper)
28 | {
29 | _configuration = configuration;
30 | _env = hostingEnvironment;
31 | _graphSdkHelper = graphSdkHelper;
32 | }
33 |
34 | public ActionResult Index()
35 | {
36 | return View();
37 | }
38 |
39 | [Authorize]
40 | public async Task CreateSubscription()
41 | {
42 | if (User.Identity.IsAuthenticated)
43 | {
44 | string identifier = User.FindFirst(Startup.ObjectIdentifierType)?.Value;
45 | var graphClient = _graphSdkHelper.GetAuthenticatedClient(identifier);
46 | Subscription createdSubscription = null;
47 |
48 | ///
49 | /// Some hints that can help you.
50 | /// Creating subscription https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/subscription_post_subscriptions
51 | ///
52 |
53 | /// ADD CODE HERE
54 |
55 | SubscriptionViewModel viewModel = new SubscriptionViewModel
56 | {
57 | Subscription = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(createdSubscription))
58 | };
59 |
60 | SubscriptionStore.SaveSubscriptionInfo(viewModel.Subscription.Id,
61 | viewModel.Subscription.ClientState,
62 | User.FindFirst(Startup.ObjectIdentifierType)?.Value,
63 | User.FindFirst(Startup.TenantIdType)?.Value);
64 | subscriptionId = viewModel.Subscription.Id;
65 |
66 | return View("Subscription", createdSubscription);
67 | }
68 |
69 | return View("Subscription", null);
70 | }
71 |
72 | // Delete the current webhooks subscription and sign out the user.
73 | [Authorize]
74 | public async Task DeleteSubscription()
75 | {
76 | string subscriptionId = SubscriptionController.subscriptionId;
77 |
78 | string identifier = User.FindFirst(Startup.ObjectIdentifierType)?.Value;
79 | var graphClient = _graphSdkHelper.GetAuthenticatedClient(identifier);
80 |
81 | try
82 | {
83 | await graphClient.Subscriptions[subscriptionId].Request().DeleteAsync();
84 | }
85 | catch (ServiceException e)
86 | {
87 |
88 | }
89 |
90 | return RedirectToAction("SignOut", "Account");
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/dev015-making-apps-more-powerful/03-batch/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Config file (to prevent accidental upload of secrets
14 | Config.cs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | build/
24 | bld/
25 | [Bb]in/
26 | [Oo]bj/
27 |
28 | # Visual Studo 2015 and VS Code cache/options directory
29 | .vs/
30 | .vscode/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | *_i.c
46 | *_p.c
47 | *_i.h
48 | *.ilk
49 | *.meta
50 | *.obj
51 | *.pch
52 | *.pdb
53 | *.pgc
54 | *.pgd
55 | *.rsp
56 | *.sbr
57 | *.tlb
58 | *.tli
59 | *.tlh
60 | *.tmp
61 | *.tmp_proj
62 | *.log
63 | *.vspscc
64 | *.vssscc
65 | .builds
66 | *.pidb
67 | *.svclog
68 | *.scc
69 |
70 | # Chutzpah Test files
71 | _Chutzpah*
72 |
73 | # Visual C++ cache files
74 | ipch/
75 | *.aps
76 | *.ncb
77 | *.opensdf
78 | *.sdf
79 | *.cachefile
80 |
81 | # Visual Studio profiler
82 | *.psess
83 | *.vsp
84 | *.vspx
85 |
86 | # TFS 2012 Local Workspace
87 | $tf/
88 |
89 | # Guidance Automation Toolkit
90 | *.gpState
91 |
92 | # ReSharper is a .NET coding add-in
93 | _ReSharper*/
94 | *.[Rr]e[Ss]harper
95 | *.DotSettings.user
96 |
97 | # JustCode is a .NET coding addin-in
98 | .JustCode
99 |
100 | # TeamCity is a build add-in
101 | _TeamCity*
102 |
103 | # DotCover is a Code Coverage Tool
104 | *.dotCover
105 |
106 | # NCrunch
107 | _NCrunch_*
108 | .*crunch*.local.xml
109 |
110 | # MightyMoose
111 | *.mm.*
112 | AutoTest.Net/
113 |
114 | # Web workbench (sass)
115 | .sass-cache/
116 |
117 | # Installshield output folder
118 | [Ee]xpress/
119 |
120 | # DocProject is a documentation generator add-in
121 | DocProject/buildhelp/
122 | DocProject/Help/*.HxT
123 | DocProject/Help/*.HxC
124 | DocProject/Help/*.hhc
125 | DocProject/Help/*.hhk
126 | DocProject/Help/*.hhp
127 | DocProject/Help/Html2
128 | DocProject/Help/html
129 |
130 | # Click-Once directory
131 | publish/
132 |
133 | # Publish Web Output
134 | *.[Pp]ublish.xml
135 | *.azurePubxml
136 | # TODO: Comment the next line if you want to checkin your web deploy settings
137 | # but database connection strings (with potential passwords) will be unencrypted
138 | *.pubxml
139 | *.publishproj
140 |
141 | # NuGet Packages
142 | *.nupkg
143 | # The packages folder can be ignored because of Package Restore
144 | **/packages/*
145 | # except build/, which is used as an MSBuild target.
146 | !**/packages/build/
147 | # Uncomment if necessary however generally it will be regenerated when needed
148 | #!**/packages/repositories.config
149 |
150 | # Windows Azure Build Output
151 | csx/
152 | *.build.csdef
153 |
154 | # Windows Store app package directory
155 | AppPackages/
156 |
157 | # Others
158 | *.[Cc]ache
159 | ClientBin/
160 | [Ss]tyle[Cc]op.*
161 | ~$*
162 | *~
163 | *.dbmdl
164 | *.dbproj.schemaview
165 | *.pfx
166 | *.publishsettings
167 | node_modules/
168 | bower_components/
169 |
170 | # RIA/Silverlight projects
171 | Generated_Code/
172 |
173 | # Backup & report files from converting an old project file
174 | # to a newer Visual Studio version. Backup files are not needed,
175 | # because we have git ;-)
176 | _UpgradeReport_Files/
177 | Backup*/
178 | UpgradeLog*.XML
179 | UpgradeLog*.htm
180 |
181 | # SQL Server files
182 | *.mdf
183 | *.ldf
184 |
185 | # Business Intelligence projects
186 | *.rdl.data
187 | *.bim.layout
188 | *.bim_*.settings
189 |
190 | # Microsoft Fakes
191 | FakesAssemblies/
192 |
193 | # Node.js Tools for Visual Studio
194 | .ntvs_analysis.dat
195 |
196 | # Visual Studio 6 build log
197 | *.plg
198 |
199 | # Visual Studio 6 workspace options file
200 | *.opt
201 |
--------------------------------------------------------------------------------