Skip to content

Commit cbbb92d

Browse files
author
Tiago Brenck
committed
Skeleton project
1 parent f060f80 commit cbbb92d

Some content is hidden

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

61 files changed

+24296
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Diagnostics;
4+
using WebApp_OpenIDConnect_DotNet.Models;
5+
6+
namespace WebApp_OpenIDConnect_DotNet.Controllers
7+
{
8+
public class HomeController : Controller
9+
{
10+
public HomeController()
11+
{
12+
}
13+
14+
public IActionResult Index()
15+
{
16+
return View();
17+
}
18+
19+
[AllowAnonymous]
20+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
21+
public IActionResult Error()
22+
{
23+
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
24+
}
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace WebApp_OpenIDConnect_DotNet.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}

1-WebApp-OIDC/1-5-B2C/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore;
2+
using Microsoft.AspNetCore.Hosting;
3+
4+
namespace WebApp_OpenIDConnect_DotNet
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateWebHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
14+
WebHost.CreateDefaultBuilder(args)
15+
.UseStartup<Startup>();
16+
}
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:3110/",
7+
"sslPort": 44321
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"webApp": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:3110/"
25+
}
26+
}
27+
}
22.8 KB
Loading
43.7 KB
Loading

1-WebApp-OIDC/1-5-B2C/Startup.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.Authorization;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Identity.Web;
11+
12+
namespace WebApp_OpenIDConnect_DotNet
13+
{
14+
public class Startup
15+
{
16+
public Startup(IConfiguration configuration)
17+
{
18+
Configuration = configuration;
19+
}
20+
21+
public IConfiguration Configuration { get; }
22+
23+
// This method gets called by the runtime. Use this method to add services to the container.
24+
public void ConfigureServices(IServiceCollection services)
25+
{
26+
services.Configure<CookiePolicyOptions>(options =>
27+
{
28+
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
29+
options.CheckConsentNeeded = context => true;
30+
options.MinimumSameSitePolicy = SameSiteMode.None;
31+
});
32+
33+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
34+
}
35+
36+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
37+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
38+
{
39+
if (env.IsDevelopment())
40+
{
41+
app.UseDeveloperExceptionPage();
42+
}
43+
else
44+
{
45+
app.UseExceptionHandler("/Home/Error");
46+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
47+
app.UseHsts();
48+
}
49+
50+
app.UseHttpsRedirection();
51+
app.UseStaticFiles();
52+
app.UseCookiePolicy();
53+
54+
app.UseAuthentication();
55+
56+
app.UseMvc(routes =>
57+
{
58+
routes.MapRoute(
59+
name: "default",
60+
template: "{controller=Home}/{action=Index}/{id?}");
61+
});
62+
}
63+
}
64+
}
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+
ASP.NET Core web app signing-in users in your organization
7+
</h1>
8+
<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.
10+
</p>
11+
<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
12+
"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h2>@ViewData["Title"]</h2>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<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.
22+
</p>

0 commit comments

Comments
 (0)