Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

[Design] Authentication 2.0 #1065

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e91a4be
Initial compiling snapshot of Authentication2 + Cookies
HaoK Dec 12, 2016
dbda89c
AddCookies sugar + hook response starting
HaoK Dec 12, 2016
30f4320
Split out classes
HaoK Dec 12, 2016
aed1ee3
Add working cookie2 sample
HaoK Dec 12, 2016
34c0cb0
Delete legacy artifacts
HaoK Dec 13, 2016
44f6c5f
Restore orig cookie sample
HaoK Dec 13, 2016
8bc8425
Remove chaff
HaoK Dec 13, 2016
b82766a
Update sample with login flow
HaoK Dec 13, 2016
9ea9f93
Add logout to sample, AddCookiesAuthentication
HaoK Dec 13, 2016
32a10e5
Add twitter, OAuth, RemoteAuth
HaoK Dec 14, 2016
d5f6c28
Mostly Working twitter + social auth + cookies sample
HaoK Dec 14, 2016
3cbf2c7
Remove IHttpContextAccessor, share common BaseContext/BaseAuthContext
HaoK Dec 15, 2016
61f237b
Cleanup, split classes into their own files
HaoK Dec 15, 2016
2b3548e
Add Google support
HaoK Dec 15, 2016
68a922a
Each scheme instance has its own options instance
HaoK Dec 19, 2016
bf8cc8d
Fix cookie sample to use default cookie
HaoK Dec 19, 2016
630d451
Add explicit validation step in UseAuthentication()
HaoK Dec 19, 2016
5d0d5b9
Add jwt
HaoK Dec 20, 2016
f69111e
Enable tests for auth 2
HaoK Dec 20, 2016
f125b63
Fix missing SignInScheme for google tests
HaoK Dec 20, 2016
8ec845f
Guard against unknown schemes
HaoK Dec 20, 2016
5a31699
Fix error message, tests
HaoK Dec 20, 2016
3e1e783
Use AuthenticateResult for error flow, fix jwtbearer tests
HaoK Dec 20, 2016
3ba3ae1
Restore default of scheme for claims issuer, disable claims transform…
HaoK Dec 20, 2016
87e956f
Disable google tests that call facebook for now
HaoK Dec 20, 2016
2b0e999
Add OIDC
HaoK Dec 21, 2016
58b613c
Add facebook and MSA
HaoK Dec 23, 2016
4541e7a
Fix
HaoK Dec 23, 2016
f244c65
Fix some OIDC tests
HaoK Dec 27, 2016
d174327
Fix OIDC tests
HaoK Dec 27, 2016
ab3eba7
Fix test settings
HaoK Dec 27, 2016
9a12a17
Bring back claims transformation
HaoK Dec 27, 2016
39188bb
Fix tests to pass authority
HaoK Dec 28, 2016
d0eb5f3
Restore authority validation tests
HaoK Dec 28, 2016
b199328
Reenable OIDC event tests
HaoK Dec 28, 2016
b7dcab7
Add DefaultSignInScheme to AuthenticationOptions
HaoK Dec 28, 2016
af553b9
Port facebook tests, eliminate validation pass
HaoK Dec 29, 2016
ea4004d
Enable configuration of schemes options
HaoK Jan 9, 2017
fd4c351
Move events to handler, scheme options singletons
HaoK Jan 10, 2017
d8b47f8
Cleanup, remove unused bypass from HandleRequest
HaoK Jan 11, 2017
932c187
Elimnate bool from HandleUnauthorized/Forbidden
HaoK Jan 11, 2017
7fe6238
Update add default challenge
HaoK Jan 23, 2017
e33d14c
Merge from dev
HaoK Jan 23, 2017
150efff
Upgrade to csproj
HaoK Jan 24, 2017
f8e206a
Fixes
HaoK Jan 24, 2017
15e7795
Fix build
HaoK Jan 24, 2017
673e527
Restore automatic challenge
HaoK Jan 24, 2017
8b51273
Reenable tests
HaoK Jan 24, 2017
5c5f6be
Reenable test
HaoK Jan 24, 2017
0669b49
Add instance overload for cookies options
HaoK Jan 25, 2017
c0552fb
Fix cookie instance overload
HaoK Jan 25, 2017
53193b7
IAuthenticationManager2 => IAuthenticationService
HaoK Jan 25, 2017
86ec995
Support old UseCookieAuth
HaoK Jan 26, 2017
ecb6aa4
Push legacy pattern into UseLegacyAuthentication
HaoK Jan 26, 2017
6778511
Add locking for AddScheme now that its exposed
HaoK Feb 2, 2017
a38ad40
Add todo for switching to ActivatorUtilities
HaoK Feb 2, 2017
3ce12bf
Make ISystemClock a service
HaoK Feb 2, 2017
1289da6
Address some feedback
HaoK Feb 3, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
307 changes: 297 additions & 10 deletions Security.sln

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions samples/Cookie2Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;

namespace Cookie2Sample
{
public static class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
28 changes: 28 additions & 0 deletions samples/Cookie2Sample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:1788/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"CookieSample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:12345",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:12345"
}
}
}
}
96 changes: 96 additions & 0 deletions samples/Cookie2Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication2;
using Microsoft.AspNetCore.Authentication2.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Cookie2Sample
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddCookieAuthentication(o => o.LoginPath = "/Account/Login");
services.AddCookieAuthentication("Cookies2", o =>
{
o.LoginPath = "/Account/Login2";
});
services.AddAuthentication(o => o.DefaultAuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme);
}

public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(LogLevel.Information);

app.UseAuthentication();

app.Run(async context =>
{
if (context.Request.Path == CookieAuthenticationDefaults.AccessDeniedPath)
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Access Denied");
return;
}

if (context.Request.Path == "/login")
{
var u = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "User1") }, CookieAuthenticationDefaults.AuthenticationScheme));
await context.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, u);

context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Cookie1 Logged in");
return;
}

if (context.Request.Path == "/login2")
{
var u = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "User2") }, CookieAuthenticationDefaults.AuthenticationScheme));
await context.SignInAsync("Cookies2", u);

context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Cookie2 Logged in");
return;
}

if (context.Request.Path == "/logout")
{
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Logged out");
return;
}

if (context.Request.Path == "/forbid")
{
await context.ForbidAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return;
}

if (context.Request.Path == CookieAuthenticationDefaults.LoginPath)
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Normally this would log you in, but you have to go to /login");
return;
}

// [Authorize] would usually handle this
var user = context.User; // We can do this because of UseAuthentication
if (user?.Identity?.IsAuthenticated ?? false)
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello "+user.Identity.Name);
}
else
{
await context.ChallengeAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}
});
}
}
}
9 changes: 9 additions & 0 deletions samples/Cookie2Sample/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
18 changes: 18 additions & 0 deletions samples/CookieSample/CookieSample.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>558c2c2a-aed8-49de-bb60-d5f8ae06c714</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>22569</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
9 changes: 9 additions & 0 deletions samples/CookieSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"CookieSample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:12345",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:12345"
}
}
}
}
8 changes: 4 additions & 4 deletions samples/SocialSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54540",
"sslPort": 44318
"applicationUrl": "http://localhost:17626/",
"sslPort": 0
}
},
"profiles": {
Expand All @@ -19,10 +19,10 @@
"SocialSample": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:44318/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:44318/"
}
}
}
47 changes: 47 additions & 0 deletions samples/SocialSample2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.IO;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;

namespace SocialSample
{
public static class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel(options =>
{
//Configure SSL
var serverCertificate = LoadCertificate();
options.UseHttps(serverCertificate);
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}

private static X509Certificate2 LoadCertificate()
{
var socialSampleAssembly = typeof(Startup).GetTypeInfo().Assembly;
var embeddedFileProvider = new EmbeddedFileProvider(socialSampleAssembly, "SocialSample2");
var certificateFileInfo = embeddedFileProvider.GetFileInfo("compiler/resources/cert.pfx");
using (var certificateStream = certificateFileInfo.CreateReadStream())
{
byte[] certificatePayload;
using (var memoryStream = new MemoryStream())
{
certificateStream.CopyTo(memoryStream);
certificatePayload = memoryStream.ToArray();
}

return new X509Certificate2(certificatePayload, "testPassword");
}
}
}
}
29 changes: 29 additions & 0 deletions samples/SocialSample2/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54540",
"sslPort": 44318
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "https://localhost:44318/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SocialSample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "https://localhost:44318/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://localhost:44318/"
}
}
}
}
Loading