Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #4] Adds an Azure Active Directory B2C package
* Adds extension methods to configure Azure Active Directory B2C authentication for Web applications and APIs. * Adds all the supporting controllers/pages to support handling UI flows. * Adds a sample using B2C to authenticate in a web application.
- Loading branch information
Showing
82 changed files
with
25,278 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version:2.1.0-preview3-15746 | ||
commithash:bd7208b1b1533dad0fac5440948312ff269f0fb9 | ||
version:2.1.0-preview3-17001 | ||
commithash:dda68c56abf0d3b911fe6a2315872c446b314585 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks> | ||
<TargetFrameworks Condition=" '$(DeveloperBuild)' != 'true' ">$(TargetFrameworks);netcoreapp2.0</TargetFrameworks> | ||
<TargetFrameworks Condition=" '$(DeveloperBuild)' != 'true' AND '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net461</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<RazorCompileOnBuild>true</RazorCompileOnBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Authentication.AzureADB2C.UI\Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="$(MicrosoftAspNetCoreHttpsPolicyPackageVersion)" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="$(MicrosoftAspNetCoreServerIISIntegrationPackageVersion)" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" /> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(MicrosoftAspNetCoreStaticFilesPackageVersion)" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationJsonPackageVersion)" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsolePackageVersion)" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(MicrosoftExtensionsLoggingDebugPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@page | ||
@model IndexModel | ||
@{ | ||
ViewData["Title"] = "Home page"; | ||
} | ||
|
||
<div> | ||
<h1>@User.Identity.Name</h1> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace AzureADB2CSample.Pages | ||
{ | ||
public class IndexModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>@ViewData["Title"] - AzureADB2CSample</title> | ||
|
||
<environment include="Development"> | ||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /> | ||
<link rel="stylesheet" href="~/css/site.css" /> | ||
</environment> | ||
<environment exclude="Development"> | ||
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css" | ||
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css" | ||
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" /> | ||
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" /> | ||
</environment> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-inverse navbar-fixed-top"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | ||
<span class="sr-only">Toggle navigation</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a asp-page="/Index" class="navbar-brand">AzureADB2CSample</a> | ||
</div> | ||
<div class="navbar-collapse collapse"> | ||
<ul class="nav navbar-nav"> | ||
<li><a asp-page="/Index">Home</a></li> | ||
</ul> | ||
@await Html.PartialAsync("_LoginPartial") | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<div class="container body-content"> | ||
@RenderBody() | ||
<hr /> | ||
<footer> | ||
<p>© 2018 - AzureADB2CSample</p> | ||
</footer> | ||
</div> | ||
|
||
<environment include="Development"> | ||
<script src="~/lib/jquery/dist/jquery.js"></script> | ||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> | ||
<script src="~/js/site.js" asp-append-version="true"></script> | ||
</environment> | ||
<environment exclude="Development"> | ||
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js" | ||
asp-fallback-src="~/lib/jquery/dist/jquery.min.js" | ||
asp-fallback-test="window.jQuery" | ||
crossorigin="anonymous" | ||
integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk"> | ||
</script> | ||
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js" | ||
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js" | ||
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal" | ||
crossorigin="anonymous" | ||
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"> | ||
</script> | ||
<script src="~/js/site.min.js" asp-append-version="true"></script> | ||
</environment> | ||
|
||
@RenderSection("Scripts", required: false) | ||
</body> | ||
</html> |
26 changes: 26 additions & 0 deletions
26
samples/AzureADB2CSample/Pages/Shared/_LoginPartial.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI | ||
@using Microsoft.Extensions.Options | ||
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions | ||
@{ | ||
var options = AzureADB2COptions.Get(AzureADB2CDefaults.AuthenticationScheme); | ||
} | ||
@if (User.Identity.IsAuthenticated) | ||
{ | ||
<ul class="nav navbar-nav navbar-right"> | ||
@if (!string.IsNullOrEmpty(options.EditProfilePolicyId)) | ||
{ | ||
<li><a asp-area="AzureADB2C" asp-controller="Account" asp-action="EditProfile">Hello @User.Identity.Name!</a></li> | ||
} | ||
else | ||
{ | ||
<li class="navbar-text">Hello @User.Identity.Name!</li> | ||
} | ||
<li><a asp-area="AzureADB2C" asp-controller="Account" asp-action="SignOut">Sign out</a></li> | ||
</ul> | ||
} | ||
else | ||
{ | ||
<ul class="nav navbar-nav navbar-right"> | ||
<li><a asp-area="AzureADB2C" asp-controller="Account" asp-action="Signin">Sign in</a></li> | ||
</ul> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@namespace AzureADB2CSample.Pages | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace AzureADB2CSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateWebHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
new WebHostBuilder() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.ConfigureAppConfiguration((hostingContext, config) =>{ | ||
var env = hostingContext.HostingEnvironment; | ||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | ||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); | ||
config.AddEnvironmentVariables(); | ||
}) | ||
.ConfigureLogging(factory => | ||
{ | ||
factory | ||
.AddConsole() | ||
.AddDebug(); | ||
}) | ||
.UseIISIntegration() | ||
.UseKestrel() | ||
.UseStartup<Startup>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:59361/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"AzureADB2CSample": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:44315/;http://localhost:59364/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authentication.AzureADB2C.UI; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace AzureADB2CSample | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme) | ||
.AddAzureADB2C(options => Configuration.GetSection("AzureADB2C").Bind(options)); | ||
|
||
services.AddMvc(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseHttpsRedirection(); | ||
app.UseAuthentication(); | ||
app.UseStaticFiles(); | ||
app.UseMvcWithDefaultRoute(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"AzureADB2C": { | ||
"Instance": "https://login.microsoftonline.com/tfp/", | ||
"ClientId": "64f31f76-2750-49e4-aab9-f5de105b5172", | ||
"CallbackPath": "/signin-oidc", | ||
"Domain": "jacalvarb2c.onmicrosoft.com", | ||
"SignUpSignInPolicyId": "B2C_1_SiUpIn", | ||
"ResetPasswordPolicyId": "B2C_1_SSPR", | ||
"EditProfilePolicyId": "B2C_1_SiPe" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
} | ||
} |
Oops, something went wrong.