Skip to content

Commit

Permalink
[Fixes #4] Adds an Azure Active Directory B2C package
Browse files Browse the repository at this point in the history
* 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
javiercn committed Mar 22, 2018
1 parent 8947b81 commit af05248
Show file tree
Hide file tree
Showing 82 changed files with 25,278 additions and 9 deletions.
38 changes: 34 additions & 4 deletions AADIntegration.sln
Expand Up @@ -3,16 +3,46 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{75A812B0-D98C-45F3-B2A9-357BBDF7331A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8CF63E1D-F9F7-4CB4-AD90-88C4077F7BFF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{57F46508-E53D-4F6B-B77C-2EFE95925AEF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureADB2CSample", "samples\AzureADB2CSample\AzureADB2CSample.csproj", "{5D2378D4-9DDA-468F-82C6-AE4DAA54E96C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authentication.AzureADB2C.UI", "src\Microsoft.AspNetCore.Authentication.AzureADB2C.UI\Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj", "{16912327-C9B3-49FC-87E0-49FEDED0A065}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test", "test\Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test\Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test.csproj", "{454089F9-ED16-4A11-9C52-2BA74DCF5D35}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5D2378D4-9DDA-468F-82C6-AE4DAA54E96C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D2378D4-9DDA-468F-82C6-AE4DAA54E96C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D2378D4-9DDA-468F-82C6-AE4DAA54E96C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D2378D4-9DDA-468F-82C6-AE4DAA54E96C}.Release|Any CPU.Build.0 = Release|Any CPU
{16912327-C9B3-49FC-87E0-49FEDED0A065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16912327-C9B3-49FC-87E0-49FEDED0A065}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16912327-C9B3-49FC-87E0-49FEDED0A065}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16912327-C9B3-49FC-87E0-49FEDED0A065}.Release|Any CPU.Build.0 = Release|Any CPU
{454089F9-ED16-4A11-9C52-2BA74DCF5D35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{454089F9-ED16-4A11-9C52-2BA74DCF5D35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{454089F9-ED16-4A11-9C52-2BA74DCF5D35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{454089F9-ED16-4A11-9C52-2BA74DCF5D35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5D2378D4-9DDA-468F-82C6-AE4DAA54E96C} = {8CF63E1D-F9F7-4CB4-AD90-88C4077F7BFF}
{16912327-C9B3-49FC-87E0-49FEDED0A065} = {75A812B0-D98C-45F3-B2A9-357BBDF7331A}
{454089F9-ED16-4A11-9C52-2BA74DCF5D35} = {57F46508-E53D-4F6B-B77C-2EFE95925AEF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6DBF56C-E862-46EA-A4E0-993D2950D78D}
EndGlobalSection
EndGlobal
11 changes: 10 additions & 1 deletion NuGetPackageVerifier.json
Expand Up @@ -2,6 +2,15 @@
"Default": {
"rules": [
"DefaultCompositeRule"
]
],
"packages": {
"Microsoft.AspNetCore.Authentication.AzureADB2C.UI": {
"Exclusions": {
"DOC_MISSING": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "This library contains precompiled views."
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@ ASP.NET Core Azure Active Directory Integration
Travis: [![Travis](https://travis-ci.org/aspnet/AADIntegration.svg?branch=dev)](https://travis-ci.org/aspnet/aadintegration) -->

ASP.NET Core MVC AAD Integration provides seamless authentication integration with different Azure Active Directory services like Azure Active Directory and Azure Active Directory B2C for ASP.NET Core applications.
ASP.NET Core Azure Active Directory Integration provides seamless authentication integration with different Azure Active Directory services like Azure Active Directory and Azure Active Directory B2C for ASP.NET Core applications.

This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo.

Expand Down
1 change: 0 additions & 1 deletion build/dependencies.props
Expand Up @@ -5,7 +5,6 @@
<PropertyGroup Label="Package Versions">
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview3-15746</InternalAspNetCoreSdkPackageVersion>
<MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>
<MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>
<MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>
<MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>
<MicrosoftAspNetCoreHttpsPolicyPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreHttpsPolicyPackageVersion>
Expand Down
4 changes: 2 additions & 2 deletions korebuild-lock.txt
@@ -1,2 +1,2 @@
version:2.1.0-preview3-15746
commithash:bd7208b1b1533dad0fac5440948312ff269f0fb9
version:2.1.0-preview3-17001
commithash:dda68c56abf0d3b911fe6a2315872c446b314585
27 changes: 27 additions & 0 deletions samples/AzureADB2CSample/AzureADB2CSample.csproj
@@ -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>
9 changes: 9 additions & 0 deletions samples/AzureADB2CSample/Pages/Index.cshtml
@@ -0,0 +1,9 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}

<div>
<h1>@User.Identity.Name</h1>
</div>
11 changes: 11 additions & 0 deletions samples/AzureADB2CSample/Pages/Index.cshtml.cs
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace AzureADB2CSample.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
}
}
71 changes: 71 additions & 0 deletions samples/AzureADB2CSample/Pages/Shared/_Layout.cshtml
@@ -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>&copy; 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 samples/AzureADB2CSample/Pages/Shared/_LoginPartial.cshtml
@@ -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>
}
2 changes: 2 additions & 0 deletions samples/AzureADB2CSample/Pages/_ViewImports.cshtml
@@ -0,0 +1,2 @@
@namespace AzureADB2CSample.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions samples/AzureADB2CSample/Pages/_ViewStart.cshtml
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
39 changes: 39 additions & 0 deletions samples/AzureADB2CSample/Program.cs
@@ -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>();
}
}
27 changes: 27 additions & 0 deletions samples/AzureADB2CSample/Properties/launchSettings.json
@@ -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/"
}
}
}
39 changes: 39 additions & 0 deletions samples/AzureADB2CSample/Startup.cs
@@ -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();
}
}
}
9 changes: 9 additions & 0 deletions samples/AzureADB2CSample/appsettings.Development.json
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
16 changes: 16 additions & 0 deletions samples/AzureADB2CSample/appsettings.json
@@ -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"
}
}
}

0 comments on commit af05248

Please sign in to comment.