Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions GraphWebApi/Controllers/GraphExplorerAppModeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Identity.Web;
using System.Net.Http;
using System.Net.Http.Headers;

namespace GraphWebApi.Controllers
{
[ApiController]
public class GraphExplorerAppModeController : ControllerBase
{
private readonly ITokenAcquisition tokenAcquisition;
public GraphExplorerAppModeController(ITokenAcquisition tokenAcquisition)
{
this.tokenAcquisition = tokenAcquisition;
}
[Route("api/[controller]/{*all}")]
[Route("graphproxy/{*all}")]
[HttpGet]
Expand All @@ -20,6 +28,17 @@ public async Task<IActionResult> GetAsync(string all, [FromHeader] string Author
return await ProcessRequestAsync("GET", all, null, Authorization).ConfigureAwait(false);
}

[Route("api/[controller]/{*all}")]
[Route("graphproxy/token/{tenantId}")]
[HttpGet]
[AuthorizeForScopes(Scopes = new[] { "https://graph.microsoft.com/.default" })]
public async Task<string> GetTokenAsync(string tenantId)
{
// Acquire the access token.
string scopes = "https://graph.microsoft.com/.default";
return await tokenAcquisition.GetAccessTokenForAppAsync(scopes, tenantId, null);
}

[Route("api/[controller]/{*all}")]
[Route("graphproxy/{*all}")]
[HttpPost]
Expand Down
4 changes: 3 additions & 1 deletion GraphWebApi/GraphWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.17.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.14.1" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.14.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Serilog" Version="2.10.0" />
Expand Down
7 changes: 7 additions & 0 deletions GraphWebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
using OpenAPIService.Interfaces;
using OpenAPIService;
using System.Threading.Tasks;
using Microsoft.Identity.Web;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;

namespace GraphWebApi
{
Expand All @@ -46,6 +48,11 @@ public Startup(IConfiguration configuration, IWebHostEnvironment hostingEnvironm
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration, "AzureAd")
.EnableTokenAcquisitionToCallDownstreamApi()
.AddInMemoryTokenCaches();
services.AddDistributedMemoryCache();
services.AddAuthentication(option =>
{
option.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
Expand Down
10 changes: 4 additions & 6 deletions GraphWebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"TenantId": "ENTER_TENANT_ID",
"TenantId": "TENANT_ID",
"ClientId": "CLIENT_ID",
"ClientSecret": "CLIENT_SECRET",
"Audience": "ENTER_APP_ID_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/"
"Issuer": "ENTER_ISSUER_URI"
},
"Logging": {
"LogLevel": {
Expand Down