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

Commit 775eb5e

Browse files
committed
Split Security into AuthN/AuthZ
AuthenticationType -> Scheme Move Active/Passive into AutomaticAuthenticationHandler Security -> Authorization/Authentication assemblies 401-403 logic Switch from ClaimsIdentity to ClaimsPrincipal
1 parent d864b72 commit 775eb5e

File tree

245 files changed

+1701
-1169
lines changed

Some content is hidden

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

245 files changed

+1701
-1169
lines changed

samples/CookieSample/Startup.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Security.Claims;
22
using Microsoft.AspNet.Builder;
33
using Microsoft.AspNet.Http;
4-
using Microsoft.AspNet.Security.Cookies;
4+
using Microsoft.AspNet.Authentication.Cookies;
55
using Microsoft.Framework.DependencyInjection;
66

77
namespace CookieSample
@@ -23,8 +23,7 @@ public void Configure(IApplicationBuilder app)
2323
{
2424
if (context.User == null || !context.User.Identity.IsAuthenticated)
2525
{
26-
context.Response.SignIn(new ClaimsIdentity(new[] { new Claim("name", "bob") }, CookieAuthenticationDefaults.AuthenticationType));
27-
26+
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", "bob") })));
2827
context.Response.ContentType = "text/plain";
2928
await context.Response.WriteAsync("Hello First timer");
3029
return;

samples/CookieSample/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
3+
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
44
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
55
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
66
"Kestrel": "1.0.0-*"

samples/CookieSessionSample/MemoryCacheSessionStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
3-
using Microsoft.AspNet.Security;
4-
using Microsoft.AspNet.Security.Cookies.Infrastructure;
3+
using Microsoft.AspNet.Authentication;
4+
using Microsoft.AspNet.Authentication.Cookies.Infrastructure;
55
using Microsoft.Framework.Cache.Memory;
66

77
namespace CookieSessionSample

samples/CookieSessionSample/Startup.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Security.Claims;
33
using Microsoft.AspNet.Builder;
44
using Microsoft.AspNet.Http;
5-
using Microsoft.AspNet.Security.Cookies;
5+
using Microsoft.AspNet.Authentication.Cookies;
66
using Microsoft.Framework.DependencyInjection;
77

88
namespace CookieSessionSample
@@ -32,8 +32,7 @@ public void Configure(IApplicationBuilder app)
3232
{
3333
claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));
3434
}
35-
context.Response.SignIn(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationType));
36-
35+
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims)));
3736
context.Response.ContentType = "text/plain";
3837
await context.Response.WriteAsync("Hello First timer");
3938
return;

samples/CookieSessionSample/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
3+
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
44
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
55
"Microsoft.Framework.Cache.Memory": "1.0.0-*",
66
"Kestrel": "1.0.0-*",

samples/OpenIdConnectSample/Startup.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Microsoft.AspNet.Builder;
22
using Microsoft.AspNet.Http;
3-
using Microsoft.AspNet.Http.Security;
4-
using Microsoft.AspNet.Security;
5-
using Microsoft.AspNet.Security.Cookies;
6-
using Microsoft.AspNet.Security.OpenIdConnect;
3+
using Microsoft.AspNet.Http.Authentication;
4+
using Microsoft.AspNet.Authentication;
5+
using Microsoft.AspNet.Authentication.Cookies;
6+
using Microsoft.AspNet.Authentication.OpenIdConnect;
77
using Microsoft.Framework.DependencyInjection;
88

99
namespace OpenIdConnectSample
@@ -17,7 +17,7 @@ public void Configure(IApplicationBuilder app)
1717
services.AddDataProtection();
1818
services.Configure<ExternalAuthenticationOptions>(options =>
1919
{
20-
options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType;
20+
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
2121
});
2222

2323
});
@@ -37,7 +37,7 @@ public void Configure(IApplicationBuilder app)
3737
{
3838
if (context.User == null || !context.User.Identity.IsAuthenticated)
3939
{
40-
context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
40+
context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme);
4141

4242
context.Response.ContentType = "text/plain";
4343
await context.Response.WriteAsync("Hello First timer");

samples/OpenIdConnectSample/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"dependencies": {
33
"Kestrel": "1.0.0-*",
4-
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
4+
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
55
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
6-
"Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-*",
6+
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
77
"Microsoft.AspNet.Server.WebListener": "1.0.0-*"
88
},
99
"frameworks": {

samples/SocialSample/Startup.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
using Microsoft.AspNet.Builder;
55
using Microsoft.AspNet.DataProtection;
66
using Microsoft.AspNet.Http;
7-
using Microsoft.AspNet.Http.Security;
8-
using Microsoft.AspNet.Security;
9-
using Microsoft.AspNet.Security.Cookies;
10-
using Microsoft.AspNet.Security.Google;
11-
using Microsoft.AspNet.Security.MicrosoftAccount;
12-
using Microsoft.AspNet.Security.OAuth;
7+
using Microsoft.AspNet.Http.Authentication;
8+
using Microsoft.AspNet.Authentication;
9+
using Microsoft.AspNet.Authentication.Cookies;
10+
using Microsoft.AspNet.Authentication.Google;
11+
using Microsoft.AspNet.Authentication.MicrosoftAccount;
12+
using Microsoft.AspNet.Authentication.OAuth;
1313
using Microsoft.Framework.DependencyInjection;
1414
using Newtonsoft.Json.Linq;
1515

@@ -26,7 +26,7 @@ public void Configure(IApplicationBuilder app)
2626
services.AddDataProtection();
2727
services.Configure<ExternalAuthenticationOptions>(options =>
2828
{
29-
options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType;
29+
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
3030
});
3131
});
3232

@@ -121,6 +121,7 @@ k web
121121
options.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
122122
options.TokenEndpoint = "https://github.com/login/oauth/access_token";
123123
options.UserInformationEndpoint = "https://api.github.com/user";
124+
options.ClaimsIssuer = "OAuth2-Github";
124125
// Retrieving user information is unique to each provider.
125126
options.Notifications = new OAuthAuthenticationNotifications()
126127
{
@@ -136,33 +137,33 @@ k web
136137
JObject user = JObject.Parse(text);
137138

138139
var identity = new ClaimsIdentity(
139-
context.Options.AuthenticationType,
140+
context.Options.AuthenticationScheme,
140141
ClaimsIdentity.DefaultNameClaimType,
141142
ClaimsIdentity.DefaultRoleClaimType);
142143

143144
JToken value;
144145
var id = user.TryGetValue("id", out value) ? value.ToString() : null;
145146
if (!string.IsNullOrEmpty(id))
146147
{
147-
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, id, ClaimValueTypes.String, context.Options.AuthenticationType));
148+
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, id, ClaimValueTypes.String, context.Options.ClaimsIssuer));
148149
}
149150
var userName = user.TryGetValue("login", out value) ? value.ToString() : null;
150151
if (!string.IsNullOrEmpty(userName))
151152
{
152-
identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userName, ClaimValueTypes.String, context.Options.AuthenticationType));
153+
identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userName, ClaimValueTypes.String, context.Options.ClaimsIssuer));
153154
}
154155
var name = user.TryGetValue("name", out value) ? value.ToString() : null;
155156
if (!string.IsNullOrEmpty(name))
156157
{
157-
identity.AddClaim(new Claim("urn:github:name", name, ClaimValueTypes.String, context.Options.AuthenticationType));
158+
identity.AddClaim(new Claim("urn:github:name", name, ClaimValueTypes.String, context.Options.ClaimsIssuer));
158159
}
159160
var link = user.TryGetValue("url", out value) ? value.ToString() : null;
160161
if (!string.IsNullOrEmpty(link))
161162
{
162-
identity.AddClaim(new Claim("urn:github:url", link, ClaimValueTypes.String, context.Options.AuthenticationType));
163+
identity.AddClaim(new Claim("urn:github:url", link, ClaimValueTypes.String, context.Options.ClaimsIssuer));
163164
}
164165

165-
context.Identity = identity;
166+
context.Principal = new ClaimsPrincipal(identity);
166167
},
167168
};
168169
});
@@ -172,7 +173,7 @@ k web
172173
{
173174
signoutApp.Run(async context =>
174175
{
175-
string authType = context.Request.Query["authtype"];
176+
string authType = context.Request.Query["authscheme"];
176177
if (!string.IsNullOrEmpty(authType))
177178
{
178179
// By default the client will be redirect back to the URL that issued the challenge (/login?authtype=foo),
@@ -183,10 +184,10 @@ k web
183184

184185
context.Response.ContentType = "text/html";
185186
await context.Response.WriteAsync("<html><body>");
186-
await context.Response.WriteAsync("Choose an authentication type: <br>");
187-
foreach (var type in context.GetAuthenticationTypes())
187+
await context.Response.WriteAsync("Choose an authentication scheme: <br>");
188+
foreach (var type in context.GetAuthenticationSchemes())
188189
{
189-
await context.Response.WriteAsync("<a href=\"?authtype=" + type.AuthenticationType + "\">" + (type.Caption ?? "(suppressed)") + "</a><br>");
190+
await context.Response.WriteAsync("<a href=\"?authscheme=" + type.AuthenticationScheme + "\">" + (type.Caption ?? "(suppressed)") + "</a><br>");
190191
}
191192
await context.Response.WriteAsync("</body></html>");
192193
});
@@ -197,7 +198,7 @@ k web
197198
{
198199
signoutApp.Run(async context =>
199200
{
200-
context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationType);
201+
context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationScheme);
201202
context.Response.ContentType = "text/html";
202203
await context.Response.WriteAsync("<html><body>");
203204
await context.Response.WriteAsync("You have been logged out. Goodbye " + context.User.Identity.Name + "<br>");

samples/SocialSample/project.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"dependencies": {
33
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
4-
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
5-
"Microsoft.AspNet.Security.Facebook": "1.0.0-*",
6-
"Microsoft.AspNet.Security.Google": "1.0.0-*",
7-
"Microsoft.AspNet.Security.MicrosoftAccount": "1.0.0-*",
8-
"Microsoft.AspNet.Security.Twitter": "1.0.0-*",
4+
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
5+
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
6+
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
7+
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*",
8+
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
99
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
1010
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
1111
"Kestrel": "1.0.0-*"

src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationDefaults.cs renamed to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationDefaults.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
54
using System.Diagnostics.CodeAnalysis;
65
using Microsoft.AspNet.Http;
76

8-
namespace Microsoft.AspNet.Security.Cookies
7+
namespace Microsoft.AspNet.Authentication.Cookies
98
{
109
/// <summary>
1110
/// Default values related to cookie-based authentication middleware
1211
/// </summary>
1312
public static class CookieAuthenticationDefaults
1413
{
1514
/// <summary>
16-
/// The default value used for CookieAuthenticationOptions.AuthenticationType
15+
/// The default value used for CookieAuthenticationOptions.AuthenticationScheme
1716
/// </summary>
18-
public const string AuthenticationType = "Cookies";
17+
public const string AuthenticationScheme = "Cookies";
1918

2019
/// <summary>
2120
/// The prefix used to provide a default CookieAuthenticationOptions.CookieName

src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationExtensions.cs renamed to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.AspNet.Security.Cookies;
4+
using System;
5+
using Microsoft.AspNet.Authentication.Cookies;
56
using Microsoft.Framework.DependencyInjection;
67
using Microsoft.Framework.OptionsModel;
7-
using System;
88

99
namespace Microsoft.AspNet.Builder
1010
{

0 commit comments

Comments
 (0)