Skip to content

Commit e50fcbb

Browse files
Tiago Brenckjmprieur
Tiago Brenck
authored andcommitted
Aspnetcore3 (#214)
* Initial changes for Microsoft.Identity.Web and 1.1 * 2.2 * Removed IIS Express option * 1.3 * 1.4 * 1.5 * updated readmes * 2.1 * 2.2 * 2.2 fixes to distributed token cache * 2.3 * 2.4 * 3 * 4.1 * 5.1 * 5.2 * 1.1 adjusts * Index adjustments * fixing image * Index.cshtml changes * Removed trailing that was causing error * Fixed unnecessary trailing * Ind Index.cshtml fixes
1 parent c627919 commit e50fcbb

File tree

214 files changed

+48674
-18245
lines changed

Some content is hidden

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

214 files changed

+48674
-18245
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,24 @@
3838
/2-WebApp-graph-user/2-3-Multi-Tenant/.vs
3939
/2-WebApp-graph-user/2-3-Multi-Tenant/bin
4040
/2-WebApp-graph-user/2-3-Multi-Tenant/obj
41+
/2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph/.vs
42+
/2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph/bin
43+
/2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph/obj
4144
/3-WebApp-multi-APIs/.vs
4245
/3-WebApp-multi-APIs/bin
4346
/3-WebApp-multi-APIs/obj
4447
/4-WebApp-your-API/.vs
4548
/4-WebApp-your-API/bin
4649
/4-WebApp-your-API/obj
50+
/4-WebApp-your-API/Client/.vs
51+
/4-WebApp-your-API/Client/bin
52+
/4-WebApp-your-API/Client/obj
53+
/5-WebApp-AuthZ/5-1-Roles/.vs
54+
/5-WebApp-AuthZ/5-1-Roles/bin
55+
/5-WebApp-AuthZ/5-1-Roles/obj
56+
/5-WebApp-AuthZ/5-2-Groups/.vs
57+
/5-WebApp-AuthZ/5-2-Groups/bin
58+
/5-WebApp-AuthZ/5-2-Groups/obj
4759
/5-WebApp-AuthZ-Roles-Groups/.vs
4860
/5-WebApp-AuthZ-Roles-Groups/bin
4961
/5-WebApp-AuthZ-Roles-Groups/obj
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Logging;
34
using System.Diagnostics;
45
using WebApp_OpenIDConnect_DotNet.Models;
56

@@ -8,20 +9,28 @@ namespace WebApp_OpenIDConnect_DotNet.Controllers
89
[Authorize]
910
public class HomeController : Controller
1011
{
11-
public HomeController()
12+
private readonly ILogger<HomeController> _logger;
13+
14+
public HomeController(ILogger<HomeController> logger)
1215
{
16+
_logger = logger;
1317
}
1418

1519
public IActionResult Index()
1620
{
1721
return View();
1822
}
1923

24+
public IActionResult Privacy()
25+
{
26+
return View();
27+
}
28+
2029
[AllowAnonymous]
2130
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
2231
public IActionResult Error()
2332
{
24-
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
33+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
2534
}
2635
}
2736
}

1-WebApp-OIDC/1-1-MyOrg/Program.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
using Microsoft.AspNetCore;
2-
using Microsoft.AspNetCore.Hosting;
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
33

44
namespace WebApp_OpenIDConnect_DotNet
55
{
66
public class Program
77
{
88
public static void Main(string[] args)
99
{
10-
CreateWebHostBuilder(args).Build().Run();
10+
CreateHostBuilder(args).Build().Run();
1111
}
1212

13-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
14-
WebHost.CreateDefaultBuilder(args)
15-
.UseStartup<Startup>();
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
1619
}
1720
}

1-WebApp-OIDC/1-1-MyOrg/Properties/launchSettings.json

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,13 @@
88
}
99
},
1010
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"launchBrowser": true,
14-
"environmentVariables": {
15-
"ASPNETCORE_ENVIRONMENT": "Development"
16-
}
17-
},
18-
"webApp": {
11+
"WebApp_OpenIDConnect_DotNet": {
1912
"commandName": "Project",
2013
"launchBrowser": true,
14+
"applicationUrl": "https://localhost:44366;http://localhost:3110",
2115
"environmentVariables": {
2216
"ASPNETCORE_ENVIRONMENT": "Development"
23-
},
24-
"applicationUrl": "http://localhost:3110/"
17+
}
2518
}
2619
}
2720
}

1-WebApp-OIDC/1-1-MyOrg/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endpoint: Microsoft identity platform
1515

1616
## Scenario
1717

18-
This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Connect to sign in users. Users can only sign-in with their `work and school` accounts in their own organization. It leverages the ASP.NET Core OpenID Connect middleware.
18+
This sample shows how to build a .NET Core MVC Web app that uses OpenID Connect to sign in users. Users can only sign-in with their `work and school` accounts in their own organization. It leverages the ASP.NET Core OpenID Connect middleware.
1919

2020
![Sign in with Azure AD](ReadmeFiles/sign-in.png)
2121

@@ -26,7 +26,7 @@ This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Conn
2626

2727
To run this sample:
2828

29-
> Pre-requisites: Install .NET Core 2.2 or later (for example for Windows) by following the instructions at [.NET and C# - Get Started in 10 Minutes](https://www.microsoft.com/net/core). In addition to developing on Windows, you can develop on [Linux](https://www.microsoft.com/net/core#linuxredhat), [Mac](https://www.microsoft.com/net/core#macos), or [Docker](https://www.microsoft.com/net/core#dockercmd).
29+
> Pre-requisites: Install .NET Core 3.0 or later (for example for Windows) by following the instructions at [.NET and C# - Get Started in 10 Minutes](https://www.microsoft.com/net/core). In addition to developing on Windows, you can develop on [Linux](https://www.microsoft.com/net/core#linuxredhat), [Mac](https://www.microsoft.com/net/core#macos), or [Docker](https://www.microsoft.com/net/core#dockercmd).
3030
3131
### Step 1: Register the sample with your Azure AD tenant
3232

@@ -178,14 +178,13 @@ cd "1-WebApp-OIDC\1-1-MyOrg"
178178
179179
2. Open your web browser and make a request to the app. Accept the IIS Express SSL certificate if needed. The app immediately attempts to authenticate you via the identity platform endpoint. Sign in with your personal account or with work or school account.
180180
181-
182181
## Toubleshooting
183182
184183
### known issue on iOS 12
185184
186185
ASP.NET core applications create session cookies that represent the identity of the caller. Some Safari users using iOS 12 had issues which are described in [ASP.NET Core #4467](https://github.com/aspnet/AspNetCore/issues/4647) and the Web kit bugs database [Bug 188165 - iOS 12 Safari breaks ASP.NET Core 2.1 OIDC authentication](https://bugs.webkit.org/show_bug.cgi?id=188165).
187186
188-
If your web site needs to be accessed from users using iOS 12, you probably want to disable the SameSite protection, but also ensure that state changes are protected with CSRF anti-forgery mecanism. See the how to fix section of [Microsoft Security Advisory: iOS12 breaks social, WSFed and OIDC logins #4647](https://github.com/aspnet/AspNetCore/issues/4647)
187+
If your web site needs to be accessed from users using iOS 12, you probably want to disable the SameSite protection, but also ensure that state changes are protected with CSRF anti-forgery mechanism. See the how to fix section of [Microsoft Security Advisory: iOS12 breaks social, WSFed and OIDC logins #4647](https://github.com/aspnet/AspNetCore/issues/4647)
189188
190189
> Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the [GitHub Issues](../../../../issues) page.
191190

1-WebApp-OIDC/1-1-MyOrg/Startup.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
2-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
32
using Microsoft.AspNetCore.Builder;
43
using Microsoft.AspNetCore.Hosting;
54
using Microsoft.AspNetCore.Http;
6-
using Microsoft.AspNetCore.Mvc;
75
using Microsoft.AspNetCore.Mvc.Authorization;
86
using Microsoft.Extensions.Configuration;
97
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
109
using Microsoft.Identity.Web;
1110

1211
namespace WebApp_OpenIDConnect_DotNet
@@ -33,18 +32,18 @@ public void ConfigureServices(IServiceCollection services)
3332
// Sign-in users with the Microsoft identity platform
3433
services.AddMicrosoftIdentityPlatformAuthentication(Configuration);
3534

36-
services.AddMvc(options =>
35+
services.AddControllersWithViews(options =>
3736
{
3837
var policy = new AuthorizationPolicyBuilder()
3938
.RequireAuthenticatedUser()
4039
.Build();
4140
options.Filters.Add(new AuthorizeFilter(policy));
42-
})
43-
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
41+
});
42+
services.AddRazorPages();
4443
}
4544

4645
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
47-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
46+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4847
{
4948
if (env.IsDevelopment())
5049
{
@@ -61,13 +60,17 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
6160
app.UseStaticFiles();
6261
app.UseCookiePolicy();
6362

63+
app.UseRouting();
64+
6465
app.UseAuthentication();
66+
app.UseAuthorization();
6567

66-
app.UseMvc(routes =>
68+
app.UseEndpoints(endpoints =>
6769
{
68-
routes.MapRoute(
70+
endpoints.MapControllerRoute(
6971
name: "default",
70-
template: "{controller=Home}/{action=Index}/{id?}");
72+
pattern: "{controller=Home}/{action=Index}/{id?}");
73+
endpoints.MapRazorPages();
7174
});
7275
}
7376
}

1-WebApp-OIDC/1-1-MyOrg/Views/Home/Index.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ASP.NET Core web app signing-in users in your organization
77
</h1>
88
<p>
9-
This sample shows how to build a .NET Core 2.2 MVC Web app that uses OpenID Connect to sign in users in your organization. It leverages the ASP.NET Core OpenID Connect middleware.
9+
This sample shows how to build a .NET Core MVC Web app that uses OpenID Connect to sign in users in your organization. It leverages the ASP.NET Core OpenID Connect middleware.
1010
</p>
1111
<img src="https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/raw/master/1-WebApp-OIDC/1-1-MyOrg/ReadmeFiles/sign-in.png
1212
"/>

1-WebApp-OIDC/1-1-MyOrg/Views/Shared/Error.cshtml

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
1919
</p>
2020
<p>
21-
<strong>Development environment should not be enabled in deployed applications</strong>, 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 <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
2225
</p>

1-WebApp-OIDC/1-1-MyOrg/Views/Shared/_CookieConsentPartial.cshtml

-40
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,49 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>@ViewData["Title"] - WebApp_OpenIDConnect_DotNet</title>
7-
8-
<environment include="Development">
9-
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
10-
<link rel="stylesheet" href="~/css/site.css" />
11-
</environment>
12-
<environment exclude="Development">
13-
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
14-
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
15-
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
16-
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
17-
</environment>
6+
<title>@ViewData["Title"] - WebApp_OpenIDConnect_DotNet</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" />
189
</head>
1910
<body>
20-
<nav class="navbar navbar-inverse navbar-fixed-top">
21-
<div class="container">
22-
<div class="navbar-header">
23-
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
24-
<span class="sr-only">Toggle navigation</span>
25-
<span class="icon-bar"></span>
26-
<span class="icon-bar"></span>
27-
<span class="icon-bar"></span>
11+
<header>
12+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
13+
<div class="container">
14+
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">WebApp_OpenIDConnect_DotNet</a>
15+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
16+
aria-expanded="false" aria-label="Toggle navigation">
17+
<span class="navbar-toggler-icon"></span>
2818
</button>
29-
<a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">WebApp_OpenIDConnect_DotNet</a>
30-
</div>
31-
<div class="navbar-collapse collapse">
32-
<ul class="nav navbar-nav">
33-
<li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
34-
</ul>
35-
<partial name="_LoginPartial" />
19+
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
20+
<partial name="_LoginPartial" />
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
24+
</li>
25+
<li class="nav-item">
26+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
27+
</li>
28+
</ul>
29+
</div>
3630
</div>
37-
</div>
38-
</nav>
39-
40-
<partial name="_CookieConsentPartial" />
41-
42-
<div class="container body-content">
43-
@RenderBody()
44-
<hr />
45-
<footer>
46-
<p>&copy; 2018 - WebApp_OpenIDConnect_DotNet</p>
47-
</footer>
31+
</nav>
32+
</header>
33+
<div class="container">
34+
<main role="main" class="pb-3">
35+
@RenderBody()
36+
</main>
4837
</div>
4938

50-
<environment include="Development">
51-
<script src="~/lib/jquery/dist/jquery.js"></script>
52-
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
53-
<script src="~/js/site.js" asp-append-version="true"></script>
54-
</environment>
55-
<environment exclude="Development">
56-
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"
57-
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
58-
asp-fallback-test="window.jQuery"
59-
crossorigin="anonymous"
60-
integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT">
61-
</script>
62-
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
63-
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
64-
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
65-
crossorigin="anonymous"
66-
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
67-
</script>
68-
<script src="~/js/site.min.js" asp-append-version="true"></script>
69-
</environment>
70-
39+
<footer class="border-top footer text-muted">
40+
<div class="container">
41+
&copy; 2019 - WebApp_OpenIDConnect_DotNet - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
42+
</div>
43+
</footer>
44+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
45+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
46+
<script src="~/js/site.js" asp-append-version="true"></script>
7147
@RenderSection("Scripts", required: false)
7248
</body>
7349
</html>

0 commit comments

Comments
 (0)