Skip to content

Commit a2fa549

Browse files
author
Kalyan Krishna
committed
Updated the skeleton with the correct source projects
1 parent c8effda commit a2fa549

File tree

96 files changed

+10655
-25951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+10655
-25951
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@
8181
/4-WebApp-your-API/4-1-Your-API/.vs/Web-API-Calls-Graph/DesignTimeBuild
8282
/4-WebApp-your-API/4-1-Your-API/TodoListWebApp/bin/Debug/netcoreapp2.2
8383
/4-WebApp-your-API/4-1-Your-API/TodoListWebApp/obj
84+
/4-WebApp-your-API/4-1-Your-API/.vs/WebApp-OpenIDConnect-DotNet/v16
85+
/4-WebApp-your-API/4-1-Your-API/Client/bin/Debug/netcoreapp2.2
86+
/4-WebApp-your-API/4-1-Your-API/Client/obj
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
72
using Microsoft.AspNetCore.Mvc;
8-
using TodoListWebApp.Models;
3+
using Microsoft.Identity.Web.Client;
4+
using System.Diagnostics;
5+
using WebApp_OpenIDConnect_DotNet.Models;
96

10-
namespace TodoListWebApp.Controllers
7+
namespace WebApp_OpenIDConnect_DotNet.Controllers
118
{
129
[Authorize]
1310
public class HomeController : Controller
1411
{
15-
public IActionResult Index()
12+
private readonly ITokenAcquisition tokenAcquisition;
13+
14+
public HomeController(ITokenAcquisition tokenAcquisition)
1615
{
17-
return View();
16+
this.tokenAcquisition = tokenAcquisition;
1817
}
1918

20-
public IActionResult Privacy()
19+
public IActionResult Index()
2120
{
2221
return View();
2322
}
@@ -29,4 +28,4 @@ public IActionResult Error()
2928
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
3029
}
3130
}
32-
}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace WebApp_OpenIDConnect_DotNet.Infrastructure
2+
{
3+
public static class Constants
4+
{
5+
public const string ScopeUserRead = "User.Read";
6+
public const string BearerAuthorizationScheme = "Bearer";
7+
}
8+
}

4-WebApp-your-API/4-1-Your-API/TodoListWebApp/Models/ErrorViewModel.cs renamed to 4-WebApp-your-API/4-1-Your-API/Client/Models/ErrorViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace TodoListWebApp.Models
1+
namespace WebApp_OpenIDConnect_DotNet.Models
42
{
53
public class ErrorViewModel
64
{

4-WebApp-your-API/4-1-Your-API/TodoListWebApp/Program.cs renamed to 4-WebApp-your-API/4-1-Your-API/Client/Program.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
1+
using Microsoft.AspNetCore;
72
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
103

11-
namespace TodoListWebApp
4+
namespace WebApp_OpenIDConnect_DotNet
125
{
136
public class Program
147
{
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{
1+
{
22
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:56871",
7-
"sslPort": 44327
6+
"applicationUrl": "http://localhost:3110/",
7+
"sslPort": 44321
88
}
99
},
1010
"profiles": {
@@ -15,13 +15,13 @@
1515
"ASPNETCORE_ENVIRONMENT": "Development"
1616
}
1717
},
18-
"TodoListWebApp": {
18+
"webApp": {
1919
"commandName": "Project",
2020
"launchBrowser": true,
21-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
2221
"environmentVariables": {
2322
"ASPNETCORE_ENVIRONMENT": "Development"
24-
}
23+
},
24+
"applicationUrl": "http://localhost:3110/"
2525
}
2626
}
2727
}

4-WebApp-your-API/4-1-Your-API/TodoListWebApp/Startup.cs renamed to 4-WebApp-your-API/4-1-Your-API/Client/Startup.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Authentication;
6-
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
7-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
82
using Microsoft.AspNetCore.Builder;
93
using Microsoft.AspNetCore.Hosting;
104
using Microsoft.AspNetCore.Http;
11-
using Microsoft.AspNetCore.HttpsPolicy;
125
using Microsoft.AspNetCore.Mvc;
136
using Microsoft.AspNetCore.Mvc.Authorization;
147
using Microsoft.Extensions.Configuration;
158
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Identity.Web;
10+
using Microsoft.Identity.Web.Client.TokenCacheProviders;
11+
using System;
12+
using WebApp_OpenIDConnect_DotNet.Infrastructure;
1613

17-
namespace TodoListWebApp
14+
namespace WebApp_OpenIDConnect_DotNet
1815
{
1916
public class Startup
2017
{
@@ -35,8 +32,15 @@ public void ConfigureServices(IServiceCollection services)
3532
options.MinimumSameSitePolicy = SameSiteMode.None;
3633
});
3734

38-
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
39-
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
35+
services.AddOptions();
36+
37+
// Token acquisition service based on MSAL.NET
38+
// and chosen token cache implementation
39+
services.AddAzureAdV2Authentication(Configuration)
40+
.AddMsal(new string[] { Constants.ScopeUserRead })
41+
.AddInMemoryTokenCaches();
42+
43+
// Add APIs
4044

4145
services.AddMvc(options =>
4246
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<UserSecretsId>aspnet-WebApp_OpenIDConnect_DotNet-81EA87AD-E64D-4755-A1CC-5EA47F49B5D8</UserSecretsId>
6+
<WebProject_DirectoryAccessLevelKey>0</WebProject_DirectoryAccessLevelKey>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Compile Remove="AppCreationScripts\**" />
11+
<Compile Remove="ReadmeFiles\**" />
12+
<Content Remove="AppCreationScripts\**" />
13+
<Content Remove="ReadmeFiles\**" />
14+
<EmbeddedResource Remove="AppCreationScripts\**" />
15+
<EmbeddedResource Remove="ReadmeFiles\**" />
16+
<None Remove="AppCreationScripts\**" />
17+
<None Remove="ReadmeFiles\**" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.AspNetCore.App" />
22+
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.2.0" />
23+
<PackageReference Include="Microsoft.Graph" Version="1.12.0" />
24+
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<ProjectReference Include="..\..\..\Microsoft.Identity.Web\Microsoft.Identity.Web.csproj" />
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<Folder Include="Services\" />
33+
</ItemGroup>
34+
35+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<h1>
6+
Integrating Azure AD V2 into an ASP.NET Core web app and calling the Microsoft Graph API, ARM and Azure Storage on behalf of the user
7+
</h1>
8+
<p>
9+
This sample shows how to build a .NET Core 2.1 MVC Web app that uses OpenID Connect to sign in users. Users can use personal accounts (including outlook.com, live.com, and others) as well as work and school accounts from any company or organization that has integrated with Azure Active Directory. It leverages the ASP.NET Core OpenID Connect middleware
10+
and MSAL.NET.
11+
</p>
12+
<img src="https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/raw/master/3-WebApp-multi-APIs/ReadmeFiles/architecture.png"/>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
ViewData["Title"] = "Privacy Policy";
33
}
4-
<h1>@ViewData["Title"]</h1>
4+
<h2>@ViewData["Title"]</h2>
55

66
<p>Use this page to detail your site's privacy policy.</p>

0 commit comments

Comments
 (0)