From fa284e8b370ad436bab4af1cfb16a554f0379e6b Mon Sep 17 00:00:00 2001 From: Omer Abubaker Date: Wed, 14 Jul 2021 12:50:21 -0400 Subject: [PATCH 1/4] Set up end point for graph explorer application mode proxy --- .../GraphExplorerAppModeService.csproj | 12 ++++ .../Interfaces/IGraphAppAuthProvider.cs | 12 ++++ .../Interfaces/IGraphServiceClient.cs | 12 ++++ .../Services/GraphAppAuthProvider.cs | 19 ++++++ .../Services/GraphClientService.cs | 18 ++++++ .../GraphExplorerAppModeController.cs | 60 +++++++++++++++++++ GraphWebApi/GraphWebApi.csproj | 1 + GraphWebApi/appsettings.json | 9 ++- MSGraphWebApi.sln | 6 ++ 9 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 GraphExplorerAppModeService/GraphExplorerAppModeService.csproj create mode 100644 GraphExplorerAppModeService/Interfaces/IGraphAppAuthProvider.cs create mode 100644 GraphExplorerAppModeService/Interfaces/IGraphServiceClient.cs create mode 100644 GraphExplorerAppModeService/Services/GraphAppAuthProvider.cs create mode 100644 GraphExplorerAppModeService/Services/GraphClientService.cs create mode 100644 GraphWebApi/Controllers/GraphExplorerAppModeController.cs diff --git a/GraphExplorerAppModeService/GraphExplorerAppModeService.csproj b/GraphExplorerAppModeService/GraphExplorerAppModeService.csproj new file mode 100644 index 000000000..522ad66e5 --- /dev/null +++ b/GraphExplorerAppModeService/GraphExplorerAppModeService.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + dotnet-GraphExplorerAppModeService-10DEC1C0-DF4C-4EA8-B0A8-54951DB93792 + Library + + + + + + diff --git a/GraphExplorerAppModeService/Interfaces/IGraphAppAuthProvider.cs b/GraphExplorerAppModeService/Interfaces/IGraphAppAuthProvider.cs new file mode 100644 index 000000000..669e3feeb --- /dev/null +++ b/GraphExplorerAppModeService/Interfaces/IGraphAppAuthProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GraphExplorerAppModeService.Interfaces +{ + interface IGraphAppAuthProvider + { + } +} diff --git a/GraphExplorerAppModeService/Interfaces/IGraphServiceClient.cs b/GraphExplorerAppModeService/Interfaces/IGraphServiceClient.cs new file mode 100644 index 000000000..21d8c5757 --- /dev/null +++ b/GraphExplorerAppModeService/Interfaces/IGraphServiceClient.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GraphExplorerAppModeService.Interfaces +{ + interface IGraphServiceClient + { + } +} diff --git a/GraphExplorerAppModeService/Services/GraphAppAuthProvider.cs b/GraphExplorerAppModeService/Services/GraphAppAuthProvider.cs new file mode 100644 index 000000000..67f55c01a --- /dev/null +++ b/GraphExplorerAppModeService/Services/GraphAppAuthProvider.cs @@ -0,0 +1,19 @@ +using GraphExplorerAppModeService.Interfaces; +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace GraphExplorerAppModeService.Services +{ + public class GraphAppAuthProvider : IGraphAppAuthProvider + { + public GraphAppAuthProvider(IConfiguration configuration) + { + + } + } +} diff --git a/GraphExplorerAppModeService/Services/GraphClientService.cs b/GraphExplorerAppModeService/Services/GraphClientService.cs new file mode 100644 index 000000000..eb90cd15b --- /dev/null +++ b/GraphExplorerAppModeService/Services/GraphClientService.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GraphExplorerAppModeService.Interfaces; +using Microsoft.Extensions.Configuration; + +namespace GraphExplorerAppModeService.Services +{ + class GraphClientService : IGraphServiceClient + { + public GraphClientService(IConfiguration configuration) + { + + } + } +} diff --git a/GraphWebApi/Controllers/GraphExplorerAppModeController.cs b/GraphWebApi/Controllers/GraphExplorerAppModeController.cs new file mode 100644 index 000000000..af90065a6 --- /dev/null +++ b/GraphWebApi/Controllers/GraphExplorerAppModeController.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using GraphExplorerAppModeService.Interfaces; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GraphWebApi.Controllers +{ + [ApiController] + public class GraphExplorerAppModeController : ControllerBase + { + [Route("api/[controller]/{*all}")] + [Route("graphproxy/{*all}")] + [HttpGet] + public async Task GetAsync(string all) + { + return await ProcessRequestAsync("GET", all, null).ConfigureAwait(false); + } + + [Route("api/[controller]/{*all}")] + [Route("graphproxy/{*all}")] + [HttpPost] + public async Task PostAsync(string all, [FromBody] object body) + { + return await ProcessRequestAsync("POST", all, body).ConfigureAwait(false); + } + + [Route("api/[controller]/{*all}")] + [Route("graphproxy/{*all}")] + [HttpDelete] + public async Task DeleteAsync(string all) + { + return await ProcessRequestAsync("DELETE", all, null).ConfigureAwait(false); + } + + [Route("api/[controller]/{*all}")] + [Route("graphproxy/{*all}")] + [HttpPut] + public async Task PutAsync(string all, [FromBody] object body) + { + return await ProcessRequestAsync("PUT", all, body).ConfigureAwait(false); + } + + [Route("api/[controller]/{*all}")] + [Route("graphproxy/{*all}")] + [HttpPatch] + public async Task PatchAsync(string all, [FromBody] object body) + { + return await ProcessRequestAsync("PATCH", all, body).ConfigureAwait(false); + } + + private async Task ProcessRequestAsync(string method, string all, object content) + { + return Ok(); + } + } +} diff --git a/GraphWebApi/GraphWebApi.csproj b/GraphWebApi/GraphWebApi.csproj index 9daa4263b..d2424b25c 100644 --- a/GraphWebApi/GraphWebApi.csproj +++ b/GraphWebApi/GraphWebApi.csproj @@ -61,6 +61,7 @@ + diff --git a/GraphWebApi/appsettings.json b/GraphWebApi/appsettings.json index b349e66a9..e596398ee 100644 --- a/GraphWebApi/appsettings.json +++ b/GraphWebApi/appsettings.json @@ -3,7 +3,11 @@ "Instance": "https://login.microsoftonline.com/", "TenantId": "ENTER_TENANT_ID", "Audience": "ENTER_APP_ID_URI", - "Issuer": "ENTER_ISSUER_URI" + "Issuer": "ENTER_ISSUER_URI", + "ClientId": "YOUR_APP_ID_HERE", + "ClientSecret": "YOUR_APP_PASSWORD_HERE", + "Scopes": "openid email profile offline_access", + "GraphResourceId": "https://graph.microsoft.com/" }, "Logging": { "LogLevel": { @@ -52,5 +56,8 @@ "SampleQueries": "24", "Permissions": "24", "ChangeLog": "24" + }, + "GEApplicationMode": { + } } \ No newline at end of file diff --git a/MSGraphWebApi.sln b/MSGraphWebApi.sln index 95c992d8c..600414ab3 100644 --- a/MSGraphWebApi.sln +++ b/MSGraphWebApi.sln @@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UtilityService", "UtilitySe EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UtilityService.Test", "UtilityService.Test\UtilityService.Test.csproj", "{0F4A15DC-F4CD-415D-A62D-6B0D95ED25E8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphExplorerAppModeService", "GraphExplorerAppModeService\GraphExplorerAppModeService.csproj", "{AF515BB3-08B5-41A1-80E6-4529670A6B1C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -129,6 +131,10 @@ Global {0F4A15DC-F4CD-415D-A62D-6B0D95ED25E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {0F4A15DC-F4CD-415D-A62D-6B0D95ED25E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {0F4A15DC-F4CD-415D-A62D-6B0D95ED25E8}.Release|Any CPU.Build.0 = Release|Any CPU + {AF515BB3-08B5-41A1-80E6-4529670A6B1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF515BB3-08B5-41A1-80E6-4529670A6B1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF515BB3-08B5-41A1-80E6-4529670A6B1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF515BB3-08B5-41A1-80E6-4529670A6B1C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 10ed6eb682db4f8b6bc03c6ebd5ba131661a9fa2 Mon Sep 17 00:00:00 2001 From: Omer Abubaker Date: Fri, 16 Jul 2021 05:09:43 -0400 Subject: [PATCH 2/4] Added Authorization header retrieval parameter --- .../GraphExplorerAppModeController.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/GraphWebApi/Controllers/GraphExplorerAppModeController.cs b/GraphWebApi/Controllers/GraphExplorerAppModeController.cs index af90065a6..e8668b485 100644 --- a/GraphWebApi/Controllers/GraphExplorerAppModeController.cs +++ b/GraphWebApi/Controllers/GraphExplorerAppModeController.cs @@ -15,45 +15,46 @@ public class GraphExplorerAppModeController : ControllerBase [Route("api/[controller]/{*all}")] [Route("graphproxy/{*all}")] [HttpGet] - public async Task GetAsync(string all) + public async Task GetAsync(string all, [FromHeader] string Authorization) { - return await ProcessRequestAsync("GET", all, null).ConfigureAwait(false); + return await ProcessRequestAsync("GET", all, null, Authorization).ConfigureAwait(false); } [Route("api/[controller]/{*all}")] [Route("graphproxy/{*all}")] [HttpPost] - public async Task PostAsync(string all, [FromBody] object body) + public async Task PostAsync(string all, [FromBody] object body, [FromHeader] string Authorization) { - return await ProcessRequestAsync("POST", all, body).ConfigureAwait(false); + return await ProcessRequestAsync("POST", all, body, Authorization).ConfigureAwait(false); } [Route("api/[controller]/{*all}")] [Route("graphproxy/{*all}")] [HttpDelete] - public async Task DeleteAsync(string all) + public async Task DeleteAsync(string all, [FromHeader] string Authorization) { - return await ProcessRequestAsync("DELETE", all, null).ConfigureAwait(false); + return await ProcessRequestAsync("DELETE", all, null, Authorization).ConfigureAwait(false); } [Route("api/[controller]/{*all}")] [Route("graphproxy/{*all}")] [HttpPut] - public async Task PutAsync(string all, [FromBody] object body) + public async Task PutAsync(string all, [FromBody] object body, [FromHeader] string Authorization) { - return await ProcessRequestAsync("PUT", all, body).ConfigureAwait(false); + return await ProcessRequestAsync("PUT", all, body, Authorization).ConfigureAwait(false); } [Route("api/[controller]/{*all}")] [Route("graphproxy/{*all}")] [HttpPatch] - public async Task PatchAsync(string all, [FromBody] object body) + public async Task PatchAsync(string all, [FromBody] object body, [FromHeader] string Authorization) { - return await ProcessRequestAsync("PATCH", all, body).ConfigureAwait(false); + return await ProcessRequestAsync("PATCH", all, body, Authorization).ConfigureAwait(false); } - private async Task ProcessRequestAsync(string method, string all, object content) + private async Task ProcessRequestAsync(string method, string all, object content, string Authorizaton) { + return Ok(); } } From 21d336c986f79f9727fbbaa3d9a76baccdc34714 Mon Sep 17 00:00:00 2001 From: Omer Abubaker Date: Fri, 16 Jul 2021 11:36:57 -0400 Subject: [PATCH 3/4] Added Authentication error handling to allow testing through postman (should be removed before being merged in) --- GraphWebApi/Startup.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/GraphWebApi/Startup.cs b/GraphWebApi/Startup.cs index 0ccb62e18..057c77435 100644 --- a/GraphWebApi/Startup.cs +++ b/GraphWebApi/Startup.cs @@ -27,6 +27,7 @@ using TelemetrySanitizerService; using OpenAPIService.Interfaces; using OpenAPIService; +using System.Threading.Tasks; namespace GraphWebApi { @@ -57,6 +58,14 @@ public void ConfigureServices(IServiceCollection services) ValidAudience = Configuration["AzureAd:Audience"], ValidIssuer = Configuration["AzureAd:Issuer"] }; + option.Events = new JwtBearerEvents() + { + OnAuthenticationFailed = context => + { + context.NoResult(); + return Task.FromResult(0); + } + }; }); #region AppInsights From 7f64746214ea8bcf6499998c122131a29a93a8c3 Mon Sep 17 00:00:00 2001 From: Omer Abubaker Date: Wed, 21 Jul 2021 14:06:47 -0400 Subject: [PATCH 4/4] Added comment for testing services --- GraphWebApi/Startup.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GraphWebApi/Startup.cs b/GraphWebApi/Startup.cs index 057c77435..106cde847 100644 --- a/GraphWebApi/Startup.cs +++ b/GraphWebApi/Startup.cs @@ -58,6 +58,8 @@ public void ConfigureServices(IServiceCollection services) ValidAudience = Configuration["AzureAd:Audience"], ValidIssuer = Configuration["AzureAd:Issuer"] }; + // This is to allow local testing using postman + // To be removed when merged into dev option.Events = new JwtBearerEvents() { OnAuthenticationFailed = context =>