diff --git a/samples/CookieSample/Startup.cs b/samples/CookieSample/Startup.cs index 7e481c220e..d5b0814fa2 100644 --- a/samples/CookieSample/Startup.cs +++ b/samples/CookieSample/Startup.cs @@ -1,7 +1,7 @@ using System.Security.Claims; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Cookies; +using Microsoft.AspNet.Authentication.Cookies; using Microsoft.Framework.DependencyInjection; namespace CookieSample @@ -23,8 +23,7 @@ namespace CookieSample { if (context.User == null || !context.User.Identity.IsAuthenticated) { - context.Response.SignIn(new ClaimsIdentity(new[] { new Claim("name", "bob") }, CookieAuthenticationDefaults.AuthenticationType)); - + context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", "bob") }))); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello First timer"); return; diff --git a/samples/CookieSample/project.json b/samples/CookieSample/project.json index 2cda02680e..4840de91aa 100644 --- a/samples/CookieSample/project.json +++ b/samples/CookieSample/project.json @@ -1,6 +1,6 @@ { "dependencies": { - "Microsoft.AspNet.Security.Cookies": "1.0.0-*", + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*", "Kestrel": "1.0.0-*" diff --git a/samples/CookieSessionSample/MemoryCacheSessionStore.cs b/samples/CookieSessionSample/MemoryCacheSessionStore.cs index 9877ded68d..4bb62d3aba 100644 --- a/samples/CookieSessionSample/MemoryCacheSessionStore.cs +++ b/samples/CookieSessionSample/MemoryCacheSessionStore.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Security; -using Microsoft.AspNet.Security.Cookies.Infrastructure; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Cookies.Infrastructure; using Microsoft.Framework.Cache.Memory; namespace CookieSessionSample diff --git a/samples/CookieSessionSample/Startup.cs b/samples/CookieSessionSample/Startup.cs index ff72c04694..dacb7956fc 100644 --- a/samples/CookieSessionSample/Startup.cs +++ b/samples/CookieSessionSample/Startup.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Security.Claims; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Cookies; +using Microsoft.AspNet.Authentication.Cookies; using Microsoft.Framework.DependencyInjection; namespace CookieSessionSample @@ -32,8 +32,7 @@ namespace CookieSessionSample { claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe")); } - context.Response.SignIn(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationType)); - + context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims))); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello First timer"); return; diff --git a/samples/CookieSessionSample/project.json b/samples/CookieSessionSample/project.json index 684c765174..18401fb77c 100644 --- a/samples/CookieSessionSample/project.json +++ b/samples/CookieSessionSample/project.json @@ -1,6 +1,6 @@ { "dependencies": { - "Microsoft.AspNet.Security.Cookies": "1.0.0-*", + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.Framework.Cache.Memory": "1.0.0-*", "Kestrel": "1.0.0-*", diff --git a/samples/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index bd443424ef..c232bc349b 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -1,9 +1,9 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.AspNet.Security.OpenIdConnect; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Cookies; +using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.Framework.DependencyInjection; namespace OpenIdConnectSample @@ -17,7 +17,7 @@ namespace OpenIdConnectSample services.AddDataProtection(); services.Configure(options => { - options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType; + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); }); @@ -37,7 +37,7 @@ namespace OpenIdConnectSample { if (context.User == null || !context.User.Identity.IsAuthenticated) { - context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType); + context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello First timer"); diff --git a/samples/OpenIdConnectSample/project.json b/samples/OpenIdConnectSample/project.json index 65652110bb..382c6b1691 100644 --- a/samples/OpenIdConnectSample/project.json +++ b/samples/OpenIdConnectSample/project.json @@ -1,9 +1,9 @@ { "dependencies": { "Kestrel": "1.0.0-*", - "Microsoft.AspNet.Security.Cookies": "1.0.0-*", + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*", - "Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-*", + "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*" }, "frameworks": { diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index d0b8d92801..dab45953da 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -4,12 +4,12 @@ using System.Security.Claims; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.AspNet.Security.Google; -using Microsoft.AspNet.Security.MicrosoftAccount; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Cookies; +using Microsoft.AspNet.Authentication.Google; +using Microsoft.AspNet.Authentication.MicrosoftAccount; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json.Linq; @@ -26,7 +26,7 @@ namespace CookieSample services.AddDataProtection(); services.Configure(options => { - options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType; + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); }); @@ -121,6 +121,7 @@ namespace CookieSample options.AuthorizationEndpoint = "https://github.com/login/oauth/authorize"; options.TokenEndpoint = "https://github.com/login/oauth/access_token"; options.UserInformationEndpoint = "https://api.github.com/user"; + options.ClaimsIssuer = "OAuth2-Github"; // Retrieving user information is unique to each provider. options.Notifications = new OAuthAuthenticationNotifications() { @@ -136,7 +137,7 @@ namespace CookieSample JObject user = JObject.Parse(text); var identity = new ClaimsIdentity( - context.Options.AuthenticationType, + context.Options.AuthenticationScheme, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); @@ -144,25 +145,25 @@ namespace CookieSample var id = user.TryGetValue("id", out value) ? value.ToString() : null; if (!string.IsNullOrEmpty(id)) { - identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, id, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, id, ClaimValueTypes.String, context.Options.ClaimsIssuer)); } var userName = user.TryGetValue("login", out value) ? value.ToString() : null; if (!string.IsNullOrEmpty(userName)) { - identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userName, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userName, ClaimValueTypes.String, context.Options.ClaimsIssuer)); } var name = user.TryGetValue("name", out value) ? value.ToString() : null; if (!string.IsNullOrEmpty(name)) { - identity.AddClaim(new Claim("urn:github:name", name, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim("urn:github:name", name, ClaimValueTypes.String, context.Options.ClaimsIssuer)); } var link = user.TryGetValue("url", out value) ? value.ToString() : null; if (!string.IsNullOrEmpty(link)) { - identity.AddClaim(new Claim("urn:github:url", link, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim("urn:github:url", link, ClaimValueTypes.String, context.Options.ClaimsIssuer)); } - context.Identity = identity; + context.Principal = new ClaimsPrincipal(identity); }, }; }); @@ -172,7 +173,7 @@ namespace CookieSample { signoutApp.Run(async context => { - string authType = context.Request.Query["authtype"]; + string authType = context.Request.Query["authscheme"]; if (!string.IsNullOrEmpty(authType)) { // By default the client will be redirect back to the URL that issued the challenge (/login?authtype=foo), @@ -183,10 +184,10 @@ namespace CookieSample context.Response.ContentType = "text/html"; await context.Response.WriteAsync(""); - await context.Response.WriteAsync("Choose an authentication type:
"); - foreach (var type in context.GetAuthenticationTypes()) + await context.Response.WriteAsync("Choose an authentication scheme:
"); + foreach (var type in context.GetAuthenticationSchemes()) { - await context.Response.WriteAsync("" + (type.Caption ?? "(suppressed)") + "
"); + await context.Response.WriteAsync("" + (type.Caption ?? "(suppressed)") + "
"); } await context.Response.WriteAsync(""); }); @@ -197,7 +198,7 @@ namespace CookieSample { signoutApp.Run(async context => { - context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationType); + context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationScheme); context.Response.ContentType = "text/html"; await context.Response.WriteAsync(""); await context.Response.WriteAsync("You have been logged out. Goodbye " + context.User.Identity.Name + "
"); diff --git a/samples/SocialSample/project.json b/samples/SocialSample/project.json index f457d3a9d4..d925cf66b4 100644 --- a/samples/SocialSample/project.json +++ b/samples/SocialSample/project.json @@ -1,11 +1,11 @@ { "dependencies": { "Microsoft.AspNet.Diagnostics": "1.0.0-*", - "Microsoft.AspNet.Security.Cookies": "1.0.0-*", - "Microsoft.AspNet.Security.Facebook": "1.0.0-*", - "Microsoft.AspNet.Security.Google": "1.0.0-*", - "Microsoft.AspNet.Security.MicrosoftAccount": "1.0.0-*", - "Microsoft.AspNet.Security.Twitter": "1.0.0-*", + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", + "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", + "Microsoft.AspNet.Authentication.Google": "1.0.0-*", + "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*", + "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Kestrel": "1.0.0-*" diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationDefaults.cs similarity index 92% rename from src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationDefaults.cs index 6ee3c8c5b9..d02b337f30 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationDefaults.cs @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System.Diagnostics.CodeAnalysis; using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Default values related to cookie-based authentication middleware @@ -13,9 +12,9 @@ namespace Microsoft.AspNet.Security.Cookies public static class CookieAuthenticationDefaults { /// - /// The default value used for CookieAuthenticationOptions.AuthenticationType + /// The default value used for CookieAuthenticationOptions.AuthenticationScheme /// - public const string AuthenticationType = "Cookies"; + public const string AuthenticationScheme = "Cookies"; /// /// The prefix used to provide a default CookieAuthenticationOptions.CookieName diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs similarity index 97% rename from src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs index 191d44da82..08f4cc71a6 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security.Cookies; +using System; +using Microsoft.AspNet.Authentication.Cookies; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; -using System; namespace Microsoft.AspNet.Builder { diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs similarity index 87% rename from src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs index c8f964ee7a..5a72a142e7 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs @@ -7,20 +7,19 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Http.Authentication; using Microsoft.Framework.Logging; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { - internal class CookieAuthenticationHandler : AuthenticationHandler + internal class CookieAuthenticationHandler : AutomaticAuthenticationHandler { private const string HeaderNameCacheControl = "Cache-Control"; private const string HeaderNamePragma = "Pragma"; private const string HeaderNameExpires = "Expires"; private const string HeaderValueNoCache = "no-cache"; private const string HeaderValueMinusOne = "-1"; - private const string SessionIdClaim = "Microsoft.AspNet.Security.Cookies-SessionId"; + private const string SessionIdClaim = "Microsoft.AspNet.Authentication.Cookies-SessionId"; private readonly ILogger _logger; @@ -60,7 +59,7 @@ namespace Microsoft.AspNet.Security.Cookies if (Options.SessionStore != null) { - Claim claim = ticket.Identity.Claims.FirstOrDefault(c => c.Type.Equals(SessionIdClaim)); + Claim claim = ticket.Principal.Claims.FirstOrDefault(c => c.Type.Equals(SessionIdClaim)); if (claim == null) { _logger.WriteWarning(@"SessionId missing"); @@ -103,11 +102,11 @@ namespace Microsoft.AspNet.Security.Cookies } } - var context = new CookieValidateIdentityContext(Context, ticket, Options); + var context = new CookieValidatePrincipalContext(Context, ticket, Options); - await Options.Notifications.ValidateIdentity(context); + await Options.Notifications.ValidatePrincipal(context); - return new AuthenticationTicket(context.Identity, context.Properties); + return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme); } catch (Exception exception) { @@ -129,7 +128,7 @@ namespace Microsoft.AspNet.Security.Cookies protected override async Task ApplyResponseGrantAsync() { - var signin = SignInIdentityContext; + var signin = SignInContext; bool shouldSignin = signin != null; var signout = SignOutContext; bool shouldSignout = signout != null; @@ -162,8 +161,8 @@ namespace Microsoft.AspNet.Security.Cookies var signInContext = new CookieResponseSignInContext( Context, Options, - Options.AuthenticationType, - signin.Identity, + Options.AuthenticationScheme, + signin.Principal, signin.Properties, cookieOptions); @@ -191,7 +190,7 @@ namespace Microsoft.AspNet.Security.Cookies signInContext.CookieOptions.Expires = expiresUtc.ToUniversalTime().DateTime; } - model = new AuthenticationTicket(signInContext.Identity, signInContext.Properties); + model = new AuthenticationTicket(signInContext.Principal, signInContext.Properties, signInContext.AuthenticationScheme); if (Options.SessionStore != null) { if (_sessionKey != null) @@ -199,10 +198,11 @@ namespace Microsoft.AspNet.Security.Cookies await Options.SessionStore.RemoveAsync(_sessionKey); } _sessionKey = await Options.SessionStore.StoreAsync(model); - ClaimsIdentity identity = new ClaimsIdentity( - new[] { new Claim(SessionIdClaim, _sessionKey) }, - Options.AuthenticationType); - model = new AuthenticationTicket(identity, null); + var principal = new ClaimsPrincipal( + new ClaimsIdentity( + new[] { new Claim(SessionIdClaim, _sessionKey) }, + Options.AuthenticationScheme)); + model = new AuthenticationTicket(principal, null, Options.AuthenticationScheme); } string cookieValue = Options.TicketDataFormat.Protect(model); @@ -215,8 +215,8 @@ namespace Microsoft.AspNet.Security.Cookies var signedInContext = new CookieResponseSignedInContext( Context, Options, - Options.AuthenticationType, - signInContext.Identity, + Options.AuthenticationScheme, + signInContext.Principal, signInContext.Properties); Options.Notifications.ResponseSignedIn(signedInContext); @@ -248,10 +248,11 @@ namespace Microsoft.AspNet.Security.Cookies if (Options.SessionStore != null && _sessionKey != null) { await Options.SessionStore.RenewAsync(_sessionKey, model); - ClaimsIdentity identity = new ClaimsIdentity( - new[] { new Claim(SessionIdClaim, _sessionKey) }, - Options.AuthenticationType); - model = new AuthenticationTicket(identity, null); + var principal = new ClaimsPrincipal( + new ClaimsIdentity( + new[] { new Claim(SessionIdClaim, _sessionKey) }, + Options.AuthenticationScheme)); + model = new AuthenticationTicket(principal, null, Options.AuthenticationScheme); } string cookieValue = Options.TicketDataFormat.Protect(model); @@ -327,8 +328,8 @@ namespace Microsoft.AspNet.Security.Cookies return; } - // Active middleware should redirect on 401 even if there wasn't an explicit challenge. - if (ChallengeContext == null && Options.AuthenticationMode == AuthenticationMode.Passive) + // Automatic middleware should redirect on 401 even if there wasn't an explicit challenge. + if (ChallengeContext == null && !Options.AutomaticAuthentication) { return; } diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs similarity index 84% rename from src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs index ba81365599..ba933d2358 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs @@ -1,17 +1,17 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; +using Microsoft.AspNet.Authentication.Cookies.Infrastructure; +using Microsoft.AspNet.Authentication.DataHandler; +using Microsoft.AspNet.Authentication.Cookies.Infrastructure; +using Microsoft.AspNet.Authentication.DataHandler; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.Cookies.Infrastructure; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.Infrastructure; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { public class CookieAuthenticationMiddleware : AuthenticationMiddleware { @@ -31,12 +31,12 @@ namespace Microsoft.AspNet.Security.Cookies } if (String.IsNullOrEmpty(Options.CookieName)) { - Options.CookieName = CookieAuthenticationDefaults.CookiePrefix + Options.AuthenticationType; + Options.CookieName = CookieAuthenticationDefaults.CookiePrefix + Options.AuthenticationScheme; } if (Options.TicketDataFormat == null) { IDataProtector dataProtector = dataProtectionProvider.CreateProtector( - typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v2"); + typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v2"); Options.TicketDataFormat = new TicketDataFormat(dataProtector); } if (Options.CookieManager == null) diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs index ec6e102063..12ff4f9956 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs @@ -1,19 +1,17 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Diagnostics.CodeAnalysis; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Cookies.Infrastructure; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Authentication.Cookies.Infrastructure; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Contains the options used by the CookiesAuthenticationMiddleware /// - public class CookieAuthenticationOptions : AuthenticationOptions + public class CookieAuthenticationOptions : AutomaticAuthenticationOptions { private string _cookieName; @@ -22,7 +20,8 @@ namespace Microsoft.AspNet.Security.Cookies /// public CookieAuthenticationOptions() { - AuthenticationType = CookieAuthenticationDefaults.AuthenticationType; + AutomaticAuthentication = true; + AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme; ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter; ExpireTimeSpan = TimeSpan.FromDays(14); SlidingExpiration = true; @@ -34,7 +33,7 @@ namespace Microsoft.AspNet.Security.Cookies /// /// Determines the cookie name used to persist the identity. The default value is ".AspNet.Cookies". - /// This value should be changed if you change the name of the AuthenticationType, especially if your + /// This value should be changed if you change the name of the AuthenticationScheme, especially if your /// system uses the cookie authentication middleware multiple times. /// public string CookieName diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieSecureOption.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieSecureOption.cs similarity index 97% rename from src/Microsoft.AspNet.Security.Cookies/CookieSecureOption.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieSecureOption.cs index c98ae07511..c8309612b8 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieSecureOption.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieSecureOption.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Determines how the identity cookie's security property is set. diff --git a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/ChunkingCookieManager.cs b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/ChunkingCookieManager.cs similarity index 99% rename from src/Microsoft.AspNet.Security.Cookies/Infrastructure/ChunkingCookieManager.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/ChunkingCookieManager.cs index 07fc0db347..1f953593b2 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/ChunkingCookieManager.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/ChunkingCookieManager.cs @@ -7,7 +7,7 @@ using System.Globalization; using System.Linq; using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Cookies.Infrastructure +namespace Microsoft.AspNet.Authentication.Cookies.Infrastructure { /// /// This handles cookies that are limited by per cookie length. It breaks down long cookies for responses, and reassembles them diff --git a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/Constants.cs similarity index 84% rename from src/Microsoft.AspNet.Security.Cookies/Infrastructure/Constants.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/Constants.cs index ef8db8e9e0..b3c3bb3a71 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/Constants.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Cookies.Infrastructure +namespace Microsoft.AspNet.Authentication.Cookies.Infrastructure { internal static class Constants { diff --git a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/IAuthenticationSessionStore.cs b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/IAuthenticationSessionStore.cs similarity index 96% rename from src/Microsoft.AspNet.Security.Cookies/Infrastructure/IAuthenticationSessionStore.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/IAuthenticationSessionStore.cs index 9f449b098b..6a6fa574b8 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/IAuthenticationSessionStore.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/IAuthenticationSessionStore.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Cookies.Infrastructure +namespace Microsoft.AspNet.Authentication.Cookies.Infrastructure { /// /// This provides an abstract storage mechanic to preserve identity information on the server diff --git a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/ICookieManager.cs b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/ICookieManager.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Cookies/Infrastructure/ICookieManager.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/ICookieManager.cs index b523b1bad7..966d3f9352 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Infrastructure/ICookieManager.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Infrastructure/ICookieManager.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Cookies.Infrastructure +namespace Microsoft.AspNet.Authentication.Cookies.Infrastructure { /// /// This is used by the CookieAuthenticationMiddleware to process request and response cookies. diff --git a/src/Microsoft.AspNet.Security.Cookies/Microsoft.AspNet.Security.Cookies.kproj b/src/Microsoft.AspNet.Authentication.Cookies/Microsoft.AspNet.Authentication.Cookies.kproj similarity index 95% rename from src/Microsoft.AspNet.Security.Cookies/Microsoft.AspNet.Security.Cookies.kproj rename to src/Microsoft.AspNet.Authentication.Cookies/Microsoft.AspNet.Authentication.Cookies.kproj index 31c09ed577..3480de791a 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Microsoft.AspNet.Security.Cookies.kproj +++ b/src/Microsoft.AspNet.Authentication.Cookies/Microsoft.AspNet.Authentication.Cookies.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,4 @@ 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.Facebook/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.Cookies/NotNullAttribute.cs similarity index 86% rename from src/Microsoft.AspNet.Security.Facebook/NotNullAttribute.cs rename to src/Microsoft.AspNet.Authentication.Cookies/NotNullAttribute.cs index 6a4d82b169..44c9fcbb20 100644 --- a/src/Microsoft.AspNet.Security.Facebook/NotNullAttribute.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/NotNullAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Cookies { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] internal sealed class NotNullAttribute : Attribute diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieApplyRedirectContext.cs similarity index 93% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieApplyRedirectContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieApplyRedirectContext.cs index 34907eabab..877e9c5ea9 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieApplyRedirectContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieApplyRedirectContext.cs @@ -4,9 +4,9 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Context passed when a Challenge, SignIn, or SignOut causes a redirect in the cookie middleware diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs similarity index 92% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs index c38489ed83..f4c29dca4a 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs @@ -5,7 +5,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// This default implementation of the ICookieAuthenticationNotifications may be used if the @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Security.Cookies /// public CookieAuthenticationNotifications() { - OnValidateIdentity = context => Task.FromResult(0); + OnValidatePrincipal = context => Task.FromResult(0); OnResponseSignIn = context => { }; OnResponseSignedIn = context => { }; OnResponseSignOut = context => { }; @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Security.Cookies /// /// A delegate assigned to this property will be invoked when the related method is called /// - public Func OnValidateIdentity { get; set; } + public Func OnValidatePrincipal { get; set; } /// /// A delegate assigned to this property will be invoked when the related method is called @@ -62,9 +62,9 @@ namespace Microsoft.AspNet.Security.Cookies /// /// /// - public virtual Task ValidateIdentity(CookieValidateIdentityContext context) + public virtual Task ValidatePrincipal(CookieValidatePrincipalContext context) { - return OnValidateIdentity.Invoke(context); + return OnValidatePrincipal.Invoke(context); } /// diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieExceptionContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieExceptionContext.cs similarity index 96% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieExceptionContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieExceptionContext.cs index e8e4fc80bb..852e90b68f 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieExceptionContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieExceptionContext.cs @@ -4,9 +4,9 @@ using System; using System.Diagnostics.CodeAnalysis; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Context object passed to the ICookieAuthenticationProvider method Exception. diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignInContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignInContext.cs similarity index 74% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignInContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignInContext.cs index 28b47c6fe2..bf448a8ddf 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignInContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignInContext.cs @@ -4,10 +4,10 @@ using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Context object passed to the ICookieAuthenticationProvider method ResponseSignIn. @@ -19,35 +19,35 @@ namespace Microsoft.AspNet.Security.Cookies /// /// The HTTP request context /// The middleware options - /// Initializes AuthenticationType property - /// Initializes Identity property + /// Initializes AuthenticationScheme property + /// Initializes Principal property /// Initializes Extra property /// Initializes options for the authentication cookie. public CookieResponseSignInContext( HttpContext context, CookieAuthenticationOptions options, - string authenticationType, - ClaimsIdentity identity, + string authenticationScheme, + ClaimsPrincipal principal, AuthenticationProperties properties, CookieOptions cookieOptions) : base(context, options) { - AuthenticationType = authenticationType; - Identity = identity; + AuthenticationScheme = authenticationScheme; + Principal = principal; Properties = properties; CookieOptions = cookieOptions; } /// - /// The name of the AuthenticationType creating a cookie + /// The name of the AuthenticationScheme creating a cookie /// - public string AuthenticationType { get; private set; } + public string AuthenticationScheme { get; private set; } /// /// Contains the claims about to be converted into the outgoing cookie. /// May be replaced or altered during the ResponseSignIn call. /// - public ClaimsIdentity Identity { get; set; } + public ClaimsPrincipal Principal { get; set; } /// /// Contains the extra data about to be contained in the outgoing cookie. diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignOutContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignOutContext.cs similarity index 91% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignOutContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignOutContext.cs index a7cf4129ac..4ba06bad37 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignOutContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignOutContext.cs @@ -3,9 +3,9 @@ using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Context object passed to the ICookieAuthenticationProvider method ResponseSignOut diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignedInContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignedInContext.cs similarity index 67% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignedInContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignedInContext.cs index 3366fb9f71..ec0c3b876d 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieResponseSignedInContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignedInContext.cs @@ -3,10 +3,10 @@ using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Context object passed to the ICookieAuthenticationNotifications method ResponseSignedIn. @@ -18,31 +18,31 @@ namespace Microsoft.AspNet.Security.Cookies /// /// The HTTP request context /// The middleware options - /// Initializes AuthenticationType property - /// Initializes Identity property + /// Initializes AuthenticationScheme property + /// Initializes Principal property /// Initializes Properties property public CookieResponseSignedInContext( HttpContext context, CookieAuthenticationOptions options, - string authenticationType, - ClaimsIdentity identity, + string authenticationScheme, + ClaimsPrincipal principal, AuthenticationProperties properties) : base(context, options) { - AuthenticationType = authenticationType; - Identity = identity; + AuthenticationScheme = authenticationScheme; + Principal = principal; Properties = properties; } /// - /// The name of the AuthenticationType creating a cookie + /// The name of the AuthenticationScheme creating a cookie /// - public string AuthenticationType { get; private set; } + public string AuthenticationScheme { get; private set; } /// /// Contains the claims that were converted into the outgoing cookie. /// - public ClaimsIdentity Identity { get; private set; } + public ClaimsPrincipal Principal { get; private set; } /// /// Contains the extra data that was contained in the outgoing cookie. diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieValidateIdentityContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieValidateIdentityContext.cs similarity index 53% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/CookieValidateIdentityContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieValidateIdentityContext.cs index 771d75d40c..328d93d2bb 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/CookieValidateIdentityContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieValidateIdentityContext.cs @@ -1,22 +1,18 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; using System.Security.Claims; using System.Security.Principal; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Http.Interfaces.Security; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// - /// Context object passed to the ICookieAuthenticationProvider method ValidateIdentity. + /// Context object passed to the ICookieAuthenticationProvider method ValidatePrincipal. /// - public class CookieValidateIdentityContext : BaseContext + public class CookieValidatePrincipalContext : BaseContext { /// /// Creates a new instance of the context object. @@ -24,18 +20,18 @@ namespace Microsoft.AspNet.Security.Cookies /// /// Contains the initial values for identity and extra data /// - public CookieValidateIdentityContext([NotNull] HttpContext context, [NotNull] AuthenticationTicket ticket, [NotNull] CookieAuthenticationOptions options) + public CookieValidatePrincipalContext([NotNull] HttpContext context, [NotNull] AuthenticationTicket ticket, [NotNull] CookieAuthenticationOptions options) : base(context, options) { - Identity = ticket.Identity; + Principal = ticket.Principal; Properties = ticket.Properties; } /// - /// Contains the claims identity arriving with the request. May be altered to change the + /// Contains the claims principal arriving with the request. May be altered to change the /// details of the authenticated user. /// - public ClaimsIdentity Identity { get; private set; } + public ClaimsPrincipal Principal { get; private set; } /// /// Contains the extra meta-data arriving with the request ticket. May be altered. @@ -43,22 +39,22 @@ namespace Microsoft.AspNet.Security.Cookies public AuthenticationProperties Properties { get; private set; } /// - /// Called to replace the claims identity. The supplied identity will replace the value of the - /// Identity property, which determines the identity of the authenticated request. + /// Called to replace the claims principal. The supplied principal will replace the value of the + /// Principal property, which determines the identity of the authenticated request. /// /// The identity used as the replacement - public void ReplaceIdentity(IIdentity identity) + public void ReplacePrincipal(IPrincipal principal) { - Identity = new ClaimsIdentity(identity); + Principal = new ClaimsPrincipal(principal); } /// - /// Called to reject the incoming identity. This may be done if the application has determined the + /// Called to reject the incoming principal. This may be done if the application has determined the /// account is no longer active, and the request should be treated as if it was anonymous. /// - public void RejectIdentity() + public void RejectPrincipal() { - Identity = null; + Principal = null; } } } diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/DefaultBehavior.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/DefaultBehavior.cs similarity index 97% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/DefaultBehavior.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/DefaultBehavior.cs index 65515c3296..0e0ed537c7 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/DefaultBehavior.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/DefaultBehavior.cs @@ -6,7 +6,7 @@ using System; using Microsoft.AspNet.Http; using Newtonsoft.Json; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { internal static class DefaultBehavior { diff --git a/src/Microsoft.AspNet.Security.Cookies/Notifications/ICookieAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/ICookieAuthenticationNotifications.cs similarity index 88% rename from src/Microsoft.AspNet.Security.Cookies/Notifications/ICookieAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Notifications/ICookieAuthenticationNotifications.cs index edfb6b69cc..0ede97ce6c 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Notifications/ICookieAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Notifications/ICookieAuthenticationNotifications.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> @@ -12,12 +12,12 @@ namespace Microsoft.AspNet.Security.Cookies public interface ICookieAuthenticationNotifications { /// - /// Called each time a request identity has been validated by the middleware. By implementing this method the - /// application may alter or reject the identity which has arrived with the request. + /// Called each time a request principal has been validated by the middleware. By implementing this method the + /// application may alter or reject the principal which has arrived with the request. /// /// Contains information about the login session as well as the user . /// A representing the completed operation. - Task ValidateIdentity(CookieValidateIdentityContext context); + Task ValidatePrincipal(CookieValidatePrincipalContext context); /// /// Called when an endpoint has provided sign in information before it is converted into a cookie. By diff --git a/src/Microsoft.AspNet.Security.Cookies/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.Cookies/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Cookies/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Resources.Designer.cs index 1a0258ba66..ef0e62fb41 100644 --- a/src/Microsoft.AspNet.Security.Cookies/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.Cookies { +namespace Microsoft.AspNet.Authentication.Cookies { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.Cookies { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.Cookies.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.Cookies.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.Cookies/Resources.resx b/src/Microsoft.AspNet.Authentication.Cookies/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.Cookies/Resources.resx rename to src/Microsoft.AspNet.Authentication.Cookies/Resources.resx diff --git a/src/Microsoft.AspNet.Security.Cookies/project.json b/src/Microsoft.AspNet.Authentication.Cookies/project.json similarity index 85% rename from src/Microsoft.AspNet.Security.Cookies/project.json rename to src/Microsoft.AspNet.Authentication.Cookies/project.json index 82f92b75b3..07d23fdcaf 100644 --- a/src/Microsoft.AspNet.Security.Cookies/project.json +++ b/src/Microsoft.AspNet.Authentication.Cookies/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET middleware that enables an application to use cookie based authentication, similar to ASP.NET's forms authentication.", "dependencies": { - "Microsoft.AspNet.Security": "1.0.0-*", + "Microsoft.AspNet.Authentication": "1.0.0-*", "Newtonsoft.Json": "6.0.6" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationDefaults.cs similarity index 82% rename from src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationDefaults.cs index 72addbef8b..92b56413a6 100644 --- a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationDefaults.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { public static class FacebookAuthenticationDefaults { - public const string AuthenticationType = "Facebook"; + public const string AuthenticationScheme = "Facebook"; public const string AuthorizationEndpoint = "https://www.facebook.com/v2.2/dialog/oauth"; diff --git a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationExtensions.cs similarity index 96% rename from src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationExtensions.cs index 51c5eac0e8..3664bb592b 100644 --- a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security.Facebook; +using Microsoft.AspNet.Authentication.Facebook; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; using System; diff --git a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs similarity index 78% rename from src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs index 7eabae1019..5f2d5b886a 100644 --- a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs @@ -11,13 +11,13 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Extensions; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.WebUtilities; using Microsoft.Framework.Logging; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { internal class FacebookAuthenticationHandler : OAuthAuthenticationHandler { @@ -65,41 +65,42 @@ namespace Microsoft.AspNet.Security.Facebook JObject user = JObject.Parse(text); var context = new FacebookAuthenticatedContext(Context, Options, user, tokens); - context.Identity = new ClaimsIdentity( - Options.AuthenticationType, + var identity = new ClaimsIdentity( + Options.AuthenticationScheme, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); if (!string.IsNullOrEmpty(context.Id)) { - context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id, ClaimValueTypes.String, Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.UserName)) { - context.Identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, context.UserName, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, context.UserName, ClaimValueTypes.String, Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.Email)) { - context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.Name)) { - context.Identity.AddClaim(new Claim("urn:facebook:name", context.Name, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim("urn:facebook:name", context.Name, ClaimValueTypes.String, Options.AuthenticationScheme)); // Many Facebook accounts do not set the UserName field. Fall back to the Name field instead. if (string.IsNullOrEmpty(context.UserName)) { - context.Identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, context.Name, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, context.Name, ClaimValueTypes.String, Options.AuthenticationScheme)); } } if (!string.IsNullOrEmpty(context.Link)) { - context.Identity.AddClaim(new Claim("urn:facebook:link", context.Link, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim("urn:facebook:link", context.Link, ClaimValueTypes.String, Options.AuthenticationScheme)); } context.Properties = properties; + context.Principal = new ClaimsPrincipal(identity); await Options.Notifications.Authenticated(context); - return new AuthenticationTicket(context.Identity, context.Properties); + return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme); } private string GenerateAppSecretProof(string accessToken) diff --git a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs index 4873ea2fd2..b74a5be1dd 100644 --- a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs @@ -4,13 +4,13 @@ using System; using System.Globalization; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.OAuth; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { /// /// An ASP.NET middleware for authenticating users using Facebook. diff --git a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationOptions.cs similarity index 88% rename from src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationOptions.cs index 1720571843..119bd25b89 100644 --- a/src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationOptions.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { /// /// Configuration options for . @@ -16,8 +16,8 @@ namespace Microsoft.AspNet.Security.Facebook /// public FacebookAuthenticationOptions() { - AuthenticationType = FacebookAuthenticationDefaults.AuthenticationType; - Caption = AuthenticationType; + AuthenticationScheme = FacebookAuthenticationDefaults.AuthenticationScheme; + Caption = AuthenticationScheme; CallbackPath = new PathString("/signin-facebook"); SendAppSecretProof = true; AuthorizationEndpoint = FacebookAuthenticationDefaults.AuthorizationEndpoint; diff --git a/src/Microsoft.AspNet.Security.Facebook/Microsoft.AspNet.Security.Facebook.kproj b/src/Microsoft.AspNet.Authentication.Facebook/Microsoft.AspNet.Authentication.Facebook.kproj similarity index 95% rename from src/Microsoft.AspNet.Security.Facebook/Microsoft.AspNet.Security.Facebook.kproj rename to src/Microsoft.AspNet.Authentication.Facebook/Microsoft.AspNet.Authentication.Facebook.kproj index 8a4224835e..ed5242e079 100644 --- a/src/Microsoft.AspNet.Security.Facebook/Microsoft.AspNet.Security.Facebook.kproj +++ b/src/Microsoft.AspNet.Authentication.Facebook/Microsoft.AspNet.Authentication.Facebook.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,4 @@ 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Facebook/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.Facebook/NotNullAttribute.cs new file mode 100644 index 0000000000..5ce6d99ddd --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.Facebook/NotNullAttribute.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Authentication.Facebook +{ + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + internal sealed class NotNullAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.Facebook/Notifications/FacebookAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Facebook/Notifications/FacebookAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs index aa4e07daaf..b64f6dd38e 100644 --- a/src/Microsoft.AspNet.Security.Facebook/Notifications/FacebookAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs @@ -3,10 +3,10 @@ using System.Net.Http; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { /// /// Contains information about the login session as well as the user . diff --git a/src/Microsoft.AspNet.Security.Facebook/Notifications/FacebookAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticationNotifications.cs similarity index 94% rename from src/Microsoft.AspNet.Security.Facebook/Notifications/FacebookAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticationNotifications.cs index f86287cc11..b89ad5c3be 100644 --- a/src/Microsoft.AspNet.Security.Facebook/Notifications/FacebookAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticationNotifications.cs @@ -3,9 +3,9 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { /// /// The default implementation. diff --git a/src/Microsoft.AspNet.Security.Facebook/Notifications/IFacebookAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/IFacebookAuthenticationNotifications.cs similarity index 90% rename from src/Microsoft.AspNet.Security.Facebook/Notifications/IFacebookAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Facebook/Notifications/IFacebookAuthenticationNotifications.cs index 0849a84a06..247715f930 100644 --- a/src/Microsoft.AspNet.Security.Facebook/Notifications/IFacebookAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/IFacebookAuthenticationNotifications.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. diff --git a/src/Microsoft.AspNet.Security.Facebook/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.Facebook/Resources.Designer.cs similarity index 94% rename from src/Microsoft.AspNet.Security.Facebook/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.Facebook/Resources.Designer.cs index 18a738d708..dd3f0e3fac 100644 --- a/src/Microsoft.AspNet.Security.Facebook/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.Facebook { +namespace Microsoft.AspNet.Authentication.Facebook { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.Facebook { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.Facebook.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.Facebook.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.Facebook/Resources.resx b/src/Microsoft.AspNet.Authentication.Facebook/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.Facebook/Resources.resx rename to src/Microsoft.AspNet.Authentication.Facebook/Resources.resx diff --git a/src/Microsoft.AspNet.Security.Facebook/project.json b/src/Microsoft.AspNet.Authentication.Facebook/project.json similarity index 81% rename from src/Microsoft.AspNet.Security.Facebook/project.json rename to src/Microsoft.AspNet.Authentication.Facebook/project.json index 3aad11e61d..fd1a44d159 100644 --- a/src/Microsoft.AspNet.Security.Facebook/project.json +++ b/src/Microsoft.AspNet.Authentication.Facebook/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 middleware that enables an application to support Facebook's OAuth 2.0 authentication workflow.", "dependencies": { - "Microsoft.AspNet.Security.OAuth": "1.0.0-*" + "Microsoft.AspNet.Authentication.OAuth": "1.0.0-*" }, "frameworks": { "aspnet50": { }, diff --git a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationDefaults.cs similarity index 83% rename from src/Microsoft.AspNet.Security.Google/GoogleAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationDefaults.cs index acf982906b..3c163c1115 100644 --- a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationDefaults.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { public static class GoogleAuthenticationDefaults { - public const string AuthenticationType = "Google"; + public const string AuthenticationScheme = "Google"; public const string AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/auth"; diff --git a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationExtensions.cs similarity index 97% rename from src/Microsoft.AspNet.Security.Google/GoogleAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationExtensions.cs index 474df5e322..fd46b062a9 100644 --- a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security.Google; +using Microsoft.AspNet.Authentication.Google; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; using System; diff --git a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs similarity index 78% rename from src/Microsoft.AspNet.Security.Google/GoogleAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs index 1d75c889f3..71e51f06ae 100644 --- a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs @@ -7,13 +7,13 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.WebUtilities; using Microsoft.Framework.Logging; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { internal class GoogleAuthenticationHandler : OAuthAuthenticationHandler { @@ -33,46 +33,47 @@ namespace Microsoft.AspNet.Security.Google JObject user = JObject.Parse(text); var context = new GoogleAuthenticatedContext(Context, Options, user, tokens); - context.Identity = new ClaimsIdentity( - Options.AuthenticationType, + var identity = new ClaimsIdentity( + Options.AuthenticationScheme, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); if (!string.IsNullOrEmpty(context.Id)) { - context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id, - ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id, + ClaimValueTypes.String, Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.GivenName)) { - context.Identity.AddClaim(new Claim(ClaimTypes.GivenName, context.GivenName, - ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.GivenName, context.GivenName, + ClaimValueTypes.String, Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.FamilyName)) { - context.Identity.AddClaim(new Claim(ClaimTypes.Surname, context.FamilyName, - ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.Surname, context.FamilyName, + ClaimValueTypes.String, Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.Name)) { - context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Name, ClaimValueTypes.String, - Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.Name, context.Name, ClaimValueTypes.String, + Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.Email)) { - context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, - Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, + Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.Profile)) { - context.Identity.AddClaim(new Claim("urn:google:profile", context.Profile, ClaimValueTypes.String, - Options.AuthenticationType)); + identity.AddClaim(new Claim("urn:google:profile", context.Profile, ClaimValueTypes.String, + Options.AuthenticationScheme)); } context.Properties = properties; + context.Principal = new ClaimsPrincipal(identity); await Options.Notifications.Authenticated(context); - return new AuthenticationTicket(context.Identity, context.Properties); + return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme); } // TODO: Abstract this properties override pattern into the base class? diff --git a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs similarity index 94% rename from src/Microsoft.AspNet.Security.Google/GoogleAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs index a72c0524f5..0da3f49284 100644 --- a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs @@ -5,15 +5,15 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net.Http; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.DataHandler; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { /// /// An ASP.NET middleware for authenticating users using Google OAuth 2.0. diff --git a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationOptions.cs similarity index 81% rename from src/Microsoft.AspNet.Security.Google/GoogleAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationOptions.cs index 4cfb97bbb2..e562a8f2c7 100644 --- a/src/Microsoft.AspNet.Security.Google/GoogleAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationOptions.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; using System.Net.Http; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { /// /// Configuration options for . @@ -20,8 +20,8 @@ namespace Microsoft.AspNet.Security.Google /// public GoogleAuthenticationOptions() { - AuthenticationType = GoogleAuthenticationDefaults.AuthenticationType; - Caption = AuthenticationType; + AuthenticationScheme = GoogleAuthenticationDefaults.AuthenticationScheme; + Caption = AuthenticationScheme; CallbackPath = new PathString("/signin-google"); AuthorizationEndpoint = GoogleAuthenticationDefaults.AuthorizationEndpoint; TokenEndpoint = GoogleAuthenticationDefaults.TokenEndpoint; diff --git a/src/Microsoft.AspNet.Security.Google/Microsoft.AspNet.Security.Google.kproj b/src/Microsoft.AspNet.Authentication.Google/Microsoft.AspNet.Authentication.Google.kproj similarity index 95% rename from src/Microsoft.AspNet.Security.Google/Microsoft.AspNet.Security.Google.kproj rename to src/Microsoft.AspNet.Authentication.Google/Microsoft.AspNet.Authentication.Google.kproj index 32f8d92b26..6c85b04cef 100644 --- a/src/Microsoft.AspNet.Security.Google/Microsoft.AspNet.Security.Google.kproj +++ b/src/Microsoft.AspNet.Authentication.Google/Microsoft.AspNet.Authentication.Google.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,4 @@ 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.Cookies/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.Google/NotNullAttribute.cs similarity index 87% rename from src/Microsoft.AspNet.Security.Cookies/NotNullAttribute.cs rename to src/Microsoft.AspNet.Authentication.Google/NotNullAttribute.cs index 0460d00166..504a02c4d7 100644 --- a/src/Microsoft.AspNet.Security.Cookies/NotNullAttribute.cs +++ b/src/Microsoft.AspNet.Authentication.Google/NotNullAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Google { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] internal sealed class NotNullAttribute : Attribute diff --git a/src/Microsoft.AspNet.Security.Google/Notifications/GoogleAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.Google/Notifications/GoogleAuthenticatedContext.cs similarity index 96% rename from src/Microsoft.AspNet.Security.Google/Notifications/GoogleAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.Google/Notifications/GoogleAuthenticatedContext.cs index 10fa2b3706..a18ba2040c 100644 --- a/src/Microsoft.AspNet.Security.Google/Notifications/GoogleAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.Google/Notifications/GoogleAuthenticatedContext.cs @@ -6,11 +6,11 @@ using System.Globalization; using System.Net.Http; using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.OAuth; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { /// /// Contains information about the login session as well as the user . diff --git a/src/Microsoft.AspNet.Security.Google/Notifications/GoogleAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Google/Notifications/GoogleAuthenticationNotifications.cs similarity index 94% rename from src/Microsoft.AspNet.Security.Google/Notifications/GoogleAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Google/Notifications/GoogleAuthenticationNotifications.cs index ef2e5d3cec..27d24e3cd4 100644 --- a/src/Microsoft.AspNet.Security.Google/Notifications/GoogleAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Google/Notifications/GoogleAuthenticationNotifications.cs @@ -3,9 +3,9 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { /// /// The default implementation. diff --git a/src/Microsoft.AspNet.Security.Google/Notifications/IGoogleAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Google/Notifications/IGoogleAuthenticationNotifications.cs similarity index 91% rename from src/Microsoft.AspNet.Security.Google/Notifications/IGoogleAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Google/Notifications/IGoogleAuthenticationNotifications.cs index 9cf9d2dd53..e9f7c492e5 100644 --- a/src/Microsoft.AspNet.Security.Google/Notifications/IGoogleAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Google/Notifications/IGoogleAuthenticationNotifications.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. diff --git a/src/Microsoft.AspNet.Security.Google/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.Google/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Google/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.Google/Resources.Designer.cs index 235dcbeef7..efa7d64ed4 100644 --- a/src/Microsoft.AspNet.Security.Google/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.Google/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.Google { +namespace Microsoft.AspNet.Authentication.Google { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.Google { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.Google.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.Google.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.Google/Resources.resx b/src/Microsoft.AspNet.Authentication.Google/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.Google/Resources.resx rename to src/Microsoft.AspNet.Authentication.Google/Resources.resx diff --git a/src/Microsoft.AspNet.Security.Google/project.json b/src/Microsoft.AspNet.Authentication.Google/project.json similarity index 81% rename from src/Microsoft.AspNet.Security.Google/project.json rename to src/Microsoft.AspNet.Authentication.Google/project.json index a4815b1815..cdaa628825 100644 --- a/src/Microsoft.AspNet.Security.Google/project.json +++ b/src/Microsoft.AspNet.Authentication.Google/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 contains middlewares to support Google's OpenId and OAuth 2.0 authentication workflows.", "dependencies": { - "Microsoft.AspNet.Security.OAuth": "1.0.0-*" + "Microsoft.AspNet.Authentication.OAuth": "1.0.0-*" }, "frameworks": { "aspnet50": { }, diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/Microsoft.AspNet.Security.MicrosoftAccount.kproj b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Microsoft.AspNet.Authentication.MicrosoftAccount.kproj similarity index 100% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/Microsoft.AspNet.Security.MicrosoftAccount.kproj rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/Microsoft.AspNet.Authentication.MicrosoftAccount.kproj diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs similarity index 81% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs index 825ab41216..22ca51751b 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { public static class MicrosoftAccountAuthenticationDefaults { - public const string AuthenticationType = "Microsoft"; + public const string AuthenticationScheme = "Microsoft"; public const string AuthorizationEndpoint = "https://login.live.com/oauth20_authorize.srf"; diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs similarity index 95% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs index 912271da61..397a1b32b5 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security.MicrosoftAccount; +using Microsoft.AspNet.Authentication.MicrosoftAccount; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; using System; diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs similarity index 73% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs index 502eaec13d..bb953cc135 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs @@ -8,12 +8,12 @@ using System.Net.Http.Headers; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.Framework.Logging; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { internal class MicrosoftAccountAuthenticationHandler : OAuthAuthenticationHandler { @@ -33,26 +33,27 @@ namespace Microsoft.AspNet.Security.MicrosoftAccount var context = new MicrosoftAccountAuthenticatedContext(Context, Options, accountInformation, tokens); context.Properties = properties; - context.Identity = new ClaimsIdentity( + var identity = new ClaimsIdentity( new[] { - new Claim(ClaimTypes.NameIdentifier, context.Id, ClaimValueTypes.String, Options.AuthenticationType), - new Claim(ClaimTypes.Name, context.Name, ClaimValueTypes.String, Options.AuthenticationType), - new Claim("urn:microsoftaccount:id", context.Id, ClaimValueTypes.String, Options.AuthenticationType), - new Claim("urn:microsoftaccount:name", context.Name, ClaimValueTypes.String, Options.AuthenticationType) + new Claim(ClaimTypes.NameIdentifier, context.Id, ClaimValueTypes.String, Options.AuthenticationScheme), + new Claim(ClaimTypes.Name, context.Name, ClaimValueTypes.String, Options.AuthenticationScheme), + new Claim("urn:microsoftaccount:id", context.Id, ClaimValueTypes.String, Options.AuthenticationScheme), + new Claim("urn:microsoftaccount:name", context.Name, ClaimValueTypes.String, Options.AuthenticationScheme) }, - Options.AuthenticationType, + Options.AuthenticationScheme, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); if (!string.IsNullOrWhiteSpace(context.Email)) { - context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, Options.AuthenticationType)); + identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, Options.AuthenticationScheme)); } + context.Principal = new ClaimsPrincipal(identity); await Options.Notifications.Authenticated(context); - return new AuthenticationTicket(context.Identity, context.Properties); + return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme); } } } diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs similarity index 95% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs index 5d0afe1f35..ac2ebc1848 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs @@ -3,14 +3,14 @@ using System; using System.Globalization; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.OAuth; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { /// /// An ASP.NET middleware for authenticating users using the Microsoft Account service. diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs similarity index 80% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs index 8755de63ba..f97f84b943 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { /// /// Configuration options for . @@ -16,8 +16,8 @@ namespace Microsoft.AspNet.Security.MicrosoftAccount /// public MicrosoftAccountAuthenticationOptions() { - AuthenticationType = MicrosoftAccountAuthenticationDefaults.AuthenticationType; - Caption = AuthenticationType; + AuthenticationScheme = MicrosoftAccountAuthenticationDefaults.AuthenticationScheme; + Caption = AuthenticationScheme; CallbackPath = new PathString("/signin-microsoft"); AuthorizationEndpoint = MicrosoftAccountAuthenticationDefaults.AuthorizationEndpoint; TokenEndpoint = MicrosoftAccountAuthenticationDefaults.TokenEndpoint; diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/NotNullAttribute.cs new file mode 100644 index 0000000000..f2afa991fc --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/NotNullAttribute.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Authentication.MicrosoftAccount +{ + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + internal sealed class NotNullAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/IMicrosoftAccountAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/IMicrosoftAccountAuthenticationNotifications.cs similarity index 90% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/IMicrosoftAccountAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/IMicrosoftAccountAuthenticationNotifications.cs index d6eb0f642b..f96040925b 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/IMicrosoftAccountAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/IMicrosoftAccountAuthenticationNotifications.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticatedContext.cs similarity index 96% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticatedContext.cs index 8b1a533123..50aea11a93 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticatedContext.cs @@ -6,10 +6,10 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { /// /// Contains information about the login session as well as the user . diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticationNotifications.cs similarity index 93% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticationNotifications.cs index 26db09d15f..70dc8faa51 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Notifications/MicrosoftAccountAuthenticationNotifications.cs @@ -3,9 +3,9 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.OAuth; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { /// /// Default implementation. diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/Resources.Designer.cs index 62f1707efb..080d4bc077 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.MicrosoftAccount { +namespace Microsoft.AspNet.Authentication.MicrosoftAccount { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.MicrosoftAccount { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.MicrosoftAccount.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.MicrosoftAccount.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/Resources.resx b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/Resources.resx rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/Resources.resx diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/project.json b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/project.json similarity index 87% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/project.json rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/project.json index 82c106b746..5aa85f9266 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/project.json +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 middleware that enables an application to support the Microsoft Account authentication workflow.", "dependencies": { - "Microsoft.AspNet.Security.OAuth": "1.0.0-*" + "Microsoft.AspNet.Authentication.OAuth": "1.0.0-*" }, "frameworks": { "aspnet50": { }, diff --git a/src/Microsoft.AspNet.Security.OAuth/Microsoft.AspNet.Security.OAuth.kproj b/src/Microsoft.AspNet.Authentication.OAuth/Microsoft.AspNet.Authentication.OAuth.kproj similarity index 95% rename from src/Microsoft.AspNet.Security.OAuth/Microsoft.AspNet.Security.OAuth.kproj rename to src/Microsoft.AspNet.Authentication.OAuth/Microsoft.AspNet.Authentication.OAuth.kproj index abcb5afdeb..868328f6de 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Microsoft.AspNet.Security.OAuth.kproj +++ b/src/Microsoft.AspNet.Authentication.OAuth/Microsoft.AspNet.Authentication.OAuth.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,4 @@ 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.Google/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.OAuth/NotNullAttribute.cs similarity index 87% rename from src/Microsoft.AspNet.Security.Google/NotNullAttribute.cs rename to src/Microsoft.AspNet.Authentication.OAuth/NotNullAttribute.cs index e87e361e4d..49f587eb50 100644 --- a/src/Microsoft.AspNet.Security.Google/NotNullAttribute.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/NotNullAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.OAuth { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] internal sealed class NotNullAttribute : Attribute diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/BaseValidatingContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingContext.cs similarity index 97% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/BaseValidatingContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingContext.cs index 0957d9fd61..84e8c0df45 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/BaseValidatingContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Base class used for certain event contexts diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/BaseValidatingTicketContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingTicketContext.cs similarity index 87% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/BaseValidatingTicketContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingTicketContext.cs index c6528619bc..f44af93283 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/BaseValidatingTicketContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingTicketContext.cs @@ -3,9 +3,9 @@ using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Base class used for certain event contexts @@ -49,10 +49,11 @@ namespace Microsoft.AspNet.Security.OAuth /// /// Assigned to the Ticket.Identity property /// True if the validation has taken effect. - public bool Validated(ClaimsIdentity identity) + public bool Validated(ClaimsPrincipal principal) { AuthenticationProperties properties = Ticket != null ? Ticket.Properties : new AuthenticationProperties(); - return Validated(new AuthenticationTicket(identity, properties)); + // TODO: Ticket can be null, need to revisit + return Validated(new AuthenticationTicket(principal, properties, Ticket.AuthenticationScheme)); } } } diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/IOAuthAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/IOAuthAuthenticationNotifications.cs similarity index 97% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/IOAuthAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/IOAuthAuthenticationNotifications.cs index b00b0175ea..2161d70fd9 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/IOAuthAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/IOAuthAuthenticationNotifications.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthApplyRedirectContext.cs similarity index 90% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthApplyRedirectContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthApplyRedirectContext.cs index df1f6a424b..070e1994eb 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthApplyRedirectContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthApplyRedirectContext.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Context passed when a Challenge causes a redirect to authorize endpoint in the Microsoft account middleware. diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticatedContext.cs similarity index 92% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticatedContext.cs index 5817071536..7283a80c6d 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticatedContext.cs @@ -5,11 +5,11 @@ using System; using System.Globalization; using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Contains information about the login session as well as the user . @@ -66,11 +66,11 @@ namespace Microsoft.AspNet.Security.OAuth /// /// Gets the representing the user. /// - public ClaimsIdentity Identity { get; set; } + public ClaimsPrincipal Principal { get; set; } /// /// Gets or sets a property bag for common authentication properties. /// public AuthenticationProperties Properties { get; set; } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticationNotifications.cs similarity index 98% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticationNotifications.cs index a91f8f0b0c..a20821889f 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticationNotifications.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Default implementation. diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthChallengeContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthChallengeContext.cs similarity index 90% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthChallengeContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthChallengeContext.cs index 6f50169143..55dd720085 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthChallengeContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthChallengeContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Specifies the HTTP response header for the bearer authentication scheme. diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthGetUserInformationContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthGetUserInformationContext.cs similarity index 90% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthGetUserInformationContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthGetUserInformationContext.cs index 15d76c6eb3..8d2405ebfc 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthGetUserInformationContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthGetUserInformationContext.cs @@ -6,10 +6,10 @@ using System.Globalization; using System.Net.Http; using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Contains information about the login session as well as the user . @@ -63,9 +63,9 @@ namespace Microsoft.AspNet.Security.OAuth public HttpClient Backchannel { get; protected set; } /// - /// Gets the representing the user. + /// Gets the representing the user. /// - public ClaimsIdentity Identity { get; set; } + public ClaimsPrincipal Principal { get; set; } /// /// Gets or sets a property bag for common authentication properties. diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthRequestTokenContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthRequestTokenContext.cs similarity index 90% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthRequestTokenContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthRequestTokenContext.cs index 785fa175d8..cd9294a420 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthRequestTokenContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthRequestTokenContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Specifies the HTTP request header for the bearer authentication scheme. diff --git a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthReturnEndpointContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthReturnEndpointContext.cs similarity index 89% rename from src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthReturnEndpointContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthReturnEndpointContext.cs index 6f465ef3d2..ce9ffd4eaa 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Notifications/OAuthReturnEndpointContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthReturnEndpointContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Provides context information to middleware providers. diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationDefaults.cs similarity index 87% rename from src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationDefaults.cs index 758417ecfd..90dc2b6166 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationDefaults.cs @@ -6,7 +6,7 @@ using System.Globalization; using System.Security.Claims; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { public static class OAuthAuthenticationDefaults { @@ -14,25 +14,25 @@ namespace Microsoft.AspNet.Security.OAuth { // If the developer doesn't specify a user-info callback, just give them the tokens. var identity = new ClaimsIdentity( - context.Options.AuthenticationType, + context.Options.AuthenticationScheme, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); - identity.AddClaim(new Claim("access_token", context.AccessToken, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim("access_token", context.AccessToken, ClaimValueTypes.String, context.Options.AuthenticationScheme)); if (!string.IsNullOrEmpty(context.RefreshToken)) { - identity.AddClaim(new Claim("refresh_token", context.RefreshToken, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim("refresh_token", context.RefreshToken, ClaimValueTypes.String, context.Options.AuthenticationScheme)); } if (!string.IsNullOrEmpty(context.TokenType)) { - identity.AddClaim(new Claim("token_type", context.TokenType, ClaimValueTypes.String, context.Options.AuthenticationType)); + identity.AddClaim(new Claim("token_type", context.TokenType, ClaimValueTypes.String, context.Options.AuthenticationScheme)); } if (context.ExpiresIn.HasValue) { identity.AddClaim(new Claim("expires_in", context.ExpiresIn.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture), - ClaimValueTypes.String, context.Options.AuthenticationType)); + ClaimValueTypes.String, context.Options.AuthenticationScheme)); } - context.Identity = identity; + context.Principal = new ClaimsPrincipal(identity); return Task.FromResult(0); }; } diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs similarity index 81% rename from src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs index 3e4947de2b..903f823e1f 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs @@ -3,8 +3,8 @@ using System; using System.Globalization; -using Microsoft.AspNet.Security.OAuth; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Authentication.OAuth; +using Microsoft.AspNet.Authentication; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder @@ -20,13 +20,13 @@ namespace Microsoft.AspNet.Builder /// The passed to the configure method. /// The middleware configuration options. /// The updated . - public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] string authenticationType, Action> configureOptions = null) + public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] string authenticationScheme, Action> configureOptions = null) { return app.UseMiddleware, IOAuthAuthenticationNotifications>>( new ConfigureOptions>(options => { - options.AuthenticationType = authenticationType; - options.Caption = authenticationType; + options.AuthenticationScheme = authenticationScheme; + options.Caption = authenticationScheme; if (configureOptions != null) { configureOptions(options); @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Builder } }) { - Name = authenticationType, + Name = authenticationScheme, }); } } diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs similarity index 85% rename from src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs index b165ca41c0..8e193befee 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs @@ -9,13 +9,13 @@ using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Extensions; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; using Microsoft.AspNet.WebUtilities; using Microsoft.Framework.Logging; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { public class OAuthAuthenticationHandler : AuthenticationHandler where TOptions : OAuthAuthenticationOptions @@ -52,26 +52,21 @@ namespace Microsoft.AspNet.Security.OAuth var context = new OAuthReturnEndpointContext(Context, ticket) { - SignInAsAuthenticationType = Options.SignInAsAuthenticationType, + SignInScheme = Options.SignInScheme, RedirectUri = ticket.Properties.RedirectUri, }; ticket.Properties.RedirectUri = null; await Options.Notifications.ReturnEndpoint(context); - if (context.SignInAsAuthenticationType != null && context.Identity != null) + if (context.SignInScheme != null && context.Principal != null) { - ClaimsIdentity signInIdentity = context.Identity; - if (!string.Equals(signInIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal)) - { - signInIdentity = new ClaimsIdentity(signInIdentity.Claims, context.SignInAsAuthenticationType, signInIdentity.NameClaimType, signInIdentity.RoleClaimType); - } - Context.Response.SignIn(context.Properties, signInIdentity); + Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties); } if (!context.IsRequestCompleted && context.RedirectUri != null) { - if (context.Identity == null) + if (context.Principal == null) { // add a redirect hint that sign-in failed in some way context.RedirectUri = QueryHelpers.AddQueryString(context.RedirectUri, "error", "access_denied"); @@ -116,13 +111,13 @@ namespace Microsoft.AspNet.Security.OAuth // OAuth2 10.12 CSRF if (!ValidateCorrelationId(properties, Logger)) { - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } if (string.IsNullOrEmpty(code)) { // Null if the remote server returns an error. - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } string requestPrefix = Request.Scheme + "://" + Request.Host; @@ -133,7 +128,7 @@ namespace Microsoft.AspNet.Security.OAuth if (string.IsNullOrWhiteSpace(tokens.AccessToken)) { Logger.WriteWarning("Access token was not found"); - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } return await GetUserInformationAsync(properties, tokens); @@ -141,7 +136,7 @@ namespace Microsoft.AspNet.Security.OAuth catch (Exception ex) { Logger.WriteError("Authentication failed", ex); - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } } @@ -176,7 +171,7 @@ namespace Microsoft.AspNet.Security.OAuth Properties = properties, }; await Options.Notifications.GetUserInformationAsync(context); - return new AuthenticationTicket(context.Identity, context.Properties); + return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme); } protected override void ApplyResponseChallenge() @@ -186,8 +181,8 @@ namespace Microsoft.AspNet.Security.OAuth return; } - // Active middleware should redirect on 401 even if there wasn't an explicit challenge. - if (ChallengeContext == null && Options.AuthenticationMode == AuthenticationMode.Passive) + // Only redirect on challenges + if (ChallengeContext == null) { return; } diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs similarity index 92% rename from src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs index c525af881b..b8e10ff996 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs @@ -5,14 +5,14 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net.Http; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.DataHandler; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.Infrastructure; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// An ASP.NET middleware for authenticating users using OAuth services. @@ -41,9 +41,9 @@ namespace Microsoft.AspNet.Security.OAuth : base(next, services, options, configureOptions) { // todo: review error handling - if (string.IsNullOrWhiteSpace(Options.AuthenticationType)) + if (string.IsNullOrWhiteSpace(Options.AuthenticationScheme)) { - throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "AuthenticationType")); + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "AuthenticationScheme")); } if (string.IsNullOrWhiteSpace(Options.ClientId)) @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Security.OAuth if (Options.StateDataFormat == null) { IDataProtector dataProtector = dataProtectionProvider.CreateProtector( - this.GetType().FullName, Options.AuthenticationType, "v1"); + this.GetType().FullName, Options.AuthenticationScheme, "v1"); Options.StateDataFormat = new PropertiesDataFormat(dataProtector); } @@ -80,13 +80,13 @@ namespace Microsoft.AspNet.Security.OAuth Backchannel.Timeout = Options.BackchannelTimeout; Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB - if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) + if (string.IsNullOrEmpty(Options.SignInScheme)) { - Options.SignInAsAuthenticationType = externalOptions.Options.SignInAsAuthenticationType; + Options.SignInScheme = externalOptions.Options.SignInScheme; } - if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) + if (string.IsNullOrEmpty(Options.SignInScheme)) { - throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "SignInAsAuthenticationType")); + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "SignInScheme")); } } diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs similarity index 92% rename from src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs index cee784185d..7a910e059b 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Configuration options for . @@ -20,7 +20,6 @@ namespace Microsoft.AspNet.Security.OAuth /// public OAuthAuthenticationOptions() { - AuthenticationMode = AuthenticationMode.Passive; Scope = new List(); BackchannelTimeout = TimeSpan.FromSeconds(60); } @@ -102,7 +101,12 @@ namespace Microsoft.AspNet.Security.OAuth /// /// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user . /// - public string SignInAsAuthenticationType { get; set; } + public string SignInScheme { get; set; } + + /// + /// Gets or sets the issuer that should be used for any claims that are created + /// + public string ClaimsIssuer { get; set; } /// /// Gets or sets the type used to secure data handled by the middleware. diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationOptions`1.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions`1.cs similarity index 93% rename from src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationOptions`1.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions`1.cs index 2eb1bfb89a..2a37062d3e 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationOptions`1.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions`1.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { /// /// Configuration options for . diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.OAuth/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.OAuthBearer/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Resources.Designer.cs index 37abb160e5..6358382740 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.OAuthBearer { +namespace Microsoft.AspNet.Authentication.OAuth { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.OAuth.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.OAuth.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.OAuth/Resources.resx b/src/Microsoft.AspNet.Authentication.OAuth/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.OAuth/Resources.resx rename to src/Microsoft.AspNet.Authentication.OAuth/Resources.resx diff --git a/src/Microsoft.AspNet.Security.OAuth/TokenResponse.cs b/src/Microsoft.AspNet.Authentication.OAuth/TokenResponse.cs similarity index 94% rename from src/Microsoft.AspNet.Security.OAuth/TokenResponse.cs rename to src/Microsoft.AspNet.Authentication.OAuth/TokenResponse.cs index 84c3e95aa6..4acc2d6e06 100644 --- a/src/Microsoft.AspNet.Security.OAuth/TokenResponse.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/TokenResponse.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication.OAuth { public class TokenResponse { diff --git a/src/Microsoft.AspNet.Security.OAuth/project.json b/src/Microsoft.AspNet.Authentication.OAuth/project.json similarity index 91% rename from src/Microsoft.AspNet.Security.OAuth/project.json rename to src/Microsoft.AspNet.Authentication.OAuth/project.json index d29f6d9144..ea68b78fa2 100644 --- a/src/Microsoft.AspNet.Security.OAuth/project.json +++ b/src/Microsoft.AspNet.Authentication.OAuth/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 middleware that enables an application to support any standard OAuth 2.0 authentication workflow.", "dependencies": { "Microsoft.AspNet.DataProtection": "1.0.0-*", - "Microsoft.AspNet.Security": "1.0.0-*" + "Microsoft.AspNet.Authentication": "1.0.0-*" }, "frameworks": { "aspnet50": { diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/Microsoft.AspNet.Security.OAuthBearer.kproj b/src/Microsoft.AspNet.Authentication.OAuthBearer/Microsoft.AspNet.Authentication.OAuthBearer.kproj similarity index 100% rename from src/Microsoft.AspNet.Security.OAuthBearer/Microsoft.AspNet.Security.OAuthBearer.kproj rename to src/Microsoft.AspNet.Authentication.OAuthBearer/Microsoft.AspNet.Authentication.OAuthBearer.kproj diff --git a/src/Microsoft.AspNet.Security.MicrosoftAccount/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/NotNullAttribute.cs similarity index 86% rename from src/Microsoft.AspNet.Security.MicrosoftAccount/NotNullAttribute.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/NotNullAttribute.cs index f3900accc6..73b3e6c56b 100644 --- a/src/Microsoft.AspNet.Security.MicrosoftAccount/NotNullAttribute.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/NotNullAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.OAuthBearer { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] internal sealed class NotNullAttribute : Attribute diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/Notifications/AuthenticationChallengeNotification.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/AuthenticationChallengeNotification.cs similarity index 81% rename from src/Microsoft.AspNet.Security.OAuthBearer/Notifications/AuthenticationChallengeNotification.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/AuthenticationChallengeNotification.cs index f2685af0c5..53e02673c1 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/Notifications/AuthenticationChallengeNotification.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/AuthenticationChallengeNotification.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { public class AuthenticationChallengeNotification : BaseNotification { diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs similarity index 96% rename from src/Microsoft.AspNet.Security.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs index 808615e1d4..3c87d520a9 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs @@ -4,12 +4,12 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; /// /// Specifies events which the invokes to enable developer control over the authentication process. /> /// -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { /// /// OAuth bearer token middleware provider diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationDefaults.cs similarity index 68% rename from src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationDefaults.cs index 5b62827cc7..e16483ef00 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationDefaults.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { /// /// Default values used by authorization server and bearer authentication. @@ -9,9 +9,9 @@ namespace Microsoft.AspNet.Security.OAuthBearer public static class OAuthBearerAuthenticationDefaults { /// - /// Default value for AuthenticationType property in the OAuthBearerAuthenticationOptions and + /// Default value for AuthenticationScheme property in the OAuthBearerAuthenticationOptions and /// OAuthAuthorizationServerOptions. /// - public const string AuthenticationType = "Bearer"; + public const string AuthenticationScheme = "Bearer"; } } diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationExtensions.cs similarity index 97% rename from src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationExtensions.cs index 0f31dfaf8a..b1a6293341 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Security.OAuthBearer; +using Microsoft.AspNet.Authentication.OAuthBearer; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationHandler.cs similarity index 94% rename from src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationHandler.cs index a4555790dc..56d3d1025d 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationHandler.cs @@ -8,15 +8,15 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Notifications; using Microsoft.Framework.Logging; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { - public class OAuthBearerAuthenticationHandler : AuthenticationHandler + public class OAuthBearerAuthenticationHandler : AutomaticAuthenticationHandler { private readonly ILogger _logger; private OpenIdConnectConfiguration _configuration; @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer if (validator.CanReadToken(token)) { ClaimsPrincipal principal = validator.ValidateToken(token, validationParameters, out validatedToken); - AuthenticationTicket ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationType); + AuthenticationTicket ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme); var securityTokenValidatedNotification = new SecurityTokenValidatedNotification(Context, Options) { ProtocolMessage = Context, @@ -192,6 +192,11 @@ namespace Microsoft.AspNet.Security.OAuthBearer protected override async Task ApplyResponseChallengeAsync() { + if (ShouldConvertChallengeToForbidden()) + { + Response.StatusCode = 403; + } + if ((Response.StatusCode != 401) || (ChallengeContext == null)) { return; diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs similarity index 98% rename from src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs index d1ae0ad1a8..824405e0e4 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs @@ -6,13 +6,13 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IdentityModel.Tokens; using System.Net.Http; +using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Security.Infrastructure; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { /// /// Bearer authentication middleware component which is added to an HTTP pipeline. This class is not diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationOptions.cs similarity index 95% rename from src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationOptions.cs index 08acf5bf45..64935c3848 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/OAuthBearerAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationOptions.cs @@ -5,15 +5,15 @@ using System; using System.Collections.Generic; using System.IdentityModel.Tokens; using System.Net.Http; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Authentication; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { /// /// Options class provides information needed to control Bearer Authentication middleware behavior /// - public class OAuthBearerAuthenticationOptions : AuthenticationOptions + public class OAuthBearerAuthenticationOptions : AutomaticAuthenticationOptions { private ICollection _securityTokenValidators; private TokenValidationParameters _tokenValidationParameters; @@ -23,9 +23,9 @@ namespace Microsoft.AspNet.Security.OAuthBearer /// public OAuthBearerAuthenticationOptions() : base() { - AuthenticationType = OAuthBearerAuthenticationDefaults.AuthenticationType; + AuthenticationScheme = OAuthBearerAuthenticationDefaults.AuthenticationScheme; BackchannelTimeout = TimeSpan.FromMinutes(1); - Challenge = OAuthBearerAuthenticationDefaults.AuthenticationType; + Challenge = OAuthBearerAuthenticationDefaults.AuthenticationScheme; Notifications = new OAuthBearerAuthenticationNotifications(); RefreshOnIssuerKeyNotFound = true; SystemClock = new SystemClock(); diff --git a/src/Microsoft.AspNet.Security.OAuth/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.OAuth/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/Resources.Designer.cs index 892b42b5fc..27298f47d8 100644 --- a/src/Microsoft.AspNet.Security.OAuth/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.OAuth { +namespace Microsoft.AspNet.Authentication.OAuthBearer { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.OAuth { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.OAuth.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.OAuth.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/Resources.resx b/src/Microsoft.AspNet.Authentication.OAuthBearer/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.OAuthBearer/Resources.resx rename to src/Microsoft.AspNet.Authentication.OAuthBearer/Resources.resx diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/project.json b/src/Microsoft.AspNet.Authentication.OAuthBearer/project.json similarity index 92% rename from src/Microsoft.AspNet.Security.OAuthBearer/project.json rename to src/Microsoft.AspNet.Authentication.OAuthBearer/project.json index affb7e5b11..a6143df77d 100644 --- a/src/Microsoft.AspNet.Security.OAuthBearer/project.json +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 middleware that enables an application to receive a OAuth bearer token.", "dependencies": { - "Microsoft.AspNet.Security": "1.0.0-*", + "Microsoft.AspNet.Authentication": "1.0.0-*", "Microsoft.IdentityModel.Protocol.Extensions": "2.0.0-beta1-*", "System.IdentityModel.Tokens": "5.0.0-beta1-*" }, diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/INonceCache.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/INonceCache.cs similarity index 86% rename from src/Microsoft.AspNet.Security.OpenIdConnect/INonceCache.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/INonceCache.cs index 3f5255f56d..a1f2d35437 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/INonceCache.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/INonceCache.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.OpenIdConnect +namespace Microsoft.AspNet.Authentication.OpenIdConnect { public interface INonceCache { diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/Microsoft.AspNet.Security.OpenIdConnect.kproj b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Microsoft.AspNet.Authentication.OpenIdConnect.kproj similarity index 100% rename from src/Microsoft.AspNet.Security.OpenIdConnect/Microsoft.AspNet.Security.OpenIdConnect.kproj rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Microsoft.AspNet.Authentication.OpenIdConnect.kproj diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs similarity index 94% rename from src/Microsoft.AspNet.Security.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs index 9c7694e560..167f7f8dd9 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.OpenIdConnect; +using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.IdentityModel.Protocols; using System.Diagnostics.CodeAnalysis; using System.IdentityModel.Tokens; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { /// /// This Notification can be used to be informed when an 'AuthorizationCode' is received over the OpenIdConnect protocol. diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs similarity index 90% rename from src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs index 5942efb4dc..21dc57f482 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.OpenIdConnect +namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// /// Default values related to OpenIdConnect authentication middleware @@ -9,9 +9,9 @@ namespace Microsoft.AspNet.Security.OpenIdConnect public static class OpenIdConnectAuthenticationDefaults { /// - /// The default value used for OpenIdConnectAuthenticationOptions.AuthenticationType + /// The default value used for OpenIdConnectAuthenticationOptions.AuthenticationScheme /// - public const string AuthenticationType = "OpenIdConnect"; + public const string AuthenticationScheme = "OpenIdConnect"; /// /// The prefix used to provide a default OpenIdConnectAuthenticationOptions.CookieName diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs similarity index 96% rename from src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs index 5d4a72b217..989aac48e1 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Security.OpenIdConnect; +using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs similarity index 94% rename from src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs index 9e6baf45d9..543e8eeeb6 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs @@ -10,15 +10,15 @@ using System.Text; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.DataHandler.Encoder; -using Microsoft.AspNet.Security.DataHandler.Serializer; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.DataHandler; +using Microsoft.AspNet.Authentication.DataHandler.Encoder; +using Microsoft.AspNet.Authentication.DataHandler.Serializer; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OpenIdConnect +namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// /// ASP.NET middleware for obtaining identities using OpenIdConnect protocol. @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect if (string.IsNullOrWhiteSpace(Options.TokenValidationParameters.AuthenticationType)) { - Options.TokenValidationParameters.AuthenticationType = externalOptions.Options.SignInAsAuthenticationType; + Options.TokenValidationParameters.AuthenticationType = externalOptions.Options.SignInScheme; } if (Options.StateDataFormat == null) @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect var dataProtector = dataProtectionProvider.CreateProtector( typeof(OpenIdConnectAuthenticationMiddleware).FullName, typeof(string).FullName, - Options.AuthenticationType, + Options.AuthenticationScheme, "v1"); Options.StateDataFormat = new PropertiesDataFormat(dataProtector); @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect var dataProtector = dataProtectionProvider.CreateProtector( typeof(OpenIdConnectAuthenticationMiddleware).FullName, typeof(string).FullName, - Options.AuthenticationType, + Options.AuthenticationScheme, "v1"); Options.StringDataFormat = new SecureDataFormat(new StringSerializer(), dataProtector, TextEncodings.Base64Url); diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationNotifications.cs similarity index 96% rename from src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationNotifications.cs index 327bbfa599..a4f15d6e9f 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationNotifications.cs @@ -3,10 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OpenIdConnect +namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// /// Specifies events which the invokes to enable developer control over the authentication process. diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs similarity index 94% rename from src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs index a5f1bcd303..d885010864 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs @@ -7,10 +7,10 @@ using System.Diagnostics.CodeAnalysis; using System.IdentityModel.Tokens; using System.Net.Http; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OpenIdConnect +namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// /// Configuration options for @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect /// Initializes a new /// public OpenIdConnectAuthenticationOptions() - : this(OpenIdConnectAuthenticationDefaults.AuthenticationType) + : this(OpenIdConnectAuthenticationDefaults.AuthenticationScheme) { } @@ -45,15 +45,16 @@ namespace Microsoft.AspNet.Security.OpenIdConnect /// RefreshOnIssuerKeyNotFound: true /// ResponseType: /// Scope: . - /// TokenValidationParameters: new with AuthenticationType = authenticationType. + /// TokenValidationParameters: new with AuthenticationScheme = authenticationScheme. /// UseTokenLifetime: true. /// - /// will be used to when creating the for the AuthenticationType property. + /// will be used to when creating the for the AuthenticationScheme property. [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions.set_Caption(System.String)", Justification = "Not a LOC field")] - public OpenIdConnectAuthenticationOptions(string authenticationType) + public OpenIdConnectAuthenticationOptions(string authenticationScheme) { - AuthenticationMode = AuthenticationMode.Active; - AuthenticationType = authenticationType; + // REVIEW: why was this active by default?? + //AuthenticationMode = AuthenticationMode.Active; + AuthenticationScheme = authenticationScheme; BackchannelTimeout = TimeSpan.FromMinutes(1); Caption = OpenIdConnectAuthenticationDefaults.Caption; ProtocolValidator = new OpenIdConnectProtocolValidator(); @@ -232,9 +233,9 @@ namespace Microsoft.AspNet.Security.OpenIdConnect public string Scope { get; set; } /// - /// Gets or sets the AuthenticationType used when creating the . + /// Gets or sets the AuthenticationScheme used when creating the . /// - public string SignInAsAuthenticationType + public string SignInScheme { get { return TokenValidationParameters.AuthenticationType; } set { TokenValidationParameters.AuthenticationType = value; } diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenidConnectAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenidConnectAuthenticationHandler.cs similarity index 97% rename from src/Microsoft.AspNet.Security.OpenIdConnect/OpenidConnectAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenidConnectAuthenticationHandler.cs index b51eb59034..67711ac5ef 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/OpenidConnectAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenidConnectAuthenticationHandler.cs @@ -9,13 +9,13 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Notifications; using Microsoft.Framework.Logging; using Microsoft.IdentityModel.Protocols; -namespace Microsoft.AspNet.Security.OpenIdConnect +namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// /// A per-request authentication handler for the OpenIdConnectAuthenticationMiddleware. @@ -123,8 +123,8 @@ namespace Microsoft.AspNet.Security.OpenIdConnect return; } - // Active middleware should redirect on 401 even if there wasn't an explicit challenge. - if (ChallengeContext == null && Options.AuthenticationMode == AuthenticationMode.Passive) + // Only redirect on challenges + if (ChallengeContext == null) { return; } @@ -343,7 +343,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect throw new InvalidOperationException("No SecurityTokenValidator found for token: " + openIdConnectMessage.IdToken); } - ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationType); + ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme); if (!string.IsNullOrWhiteSpace(openIdConnectMessage.SessionState)) { ticket.Properties.Dictionary[OpenIdConnectSessionProperties.SessionState] = openIdConnectMessage.SessionState; @@ -566,7 +566,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect { if (ticket.Principal != null) { - Request.HttpContext.Response.SignIn(ticket.Properties, ticket.Principal.Identities); + Request.HttpContext.Response.SignIn(ticket.AuthenticationScheme, ticket.Principal, ticket.Properties); } // Redirect back to the original secured resource, if any. diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Resources.Designer.cs similarity index 98% rename from src/Microsoft.AspNet.Security.OpenIdConnect/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Resources.Designer.cs index f5bfc6044a..ee19db0116 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.OpenIdConnect { +namespace Microsoft.AspNet.Authentication.OpenIdConnect { using System; using System.Reflection; diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/Resources.resx b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.OpenIdConnect/Resources.resx rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Resources.resx diff --git a/src/Microsoft.AspNet.Security.OpenIdConnect/project.json b/src/Microsoft.AspNet.Authentication.OpenIdConnect/project.json similarity index 90% rename from src/Microsoft.AspNet.Security.OpenIdConnect/project.json rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/project.json index a02c8145f9..c25baafc3e 100644 --- a/src/Microsoft.AspNet.Security.OpenIdConnect/project.json +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Security": "1.0.0-*", + "Microsoft.AspNet.Authentication": "1.0.0-*", "Microsoft.IdentityModel.Protocol.Extensions": "2.0.0-beta1-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Security.Twitter/Messages/AccessToken.cs b/src/Microsoft.AspNet.Authentication.Twitter/Messages/AccessToken.cs similarity index 91% rename from src/Microsoft.AspNet.Security.Twitter/Messages/AccessToken.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Messages/AccessToken.cs index f935da72a7..2c3351453a 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Messages/AccessToken.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Messages/AccessToken.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Twitter.Messages +namespace Microsoft.AspNet.Authentication.Twitter.Messages { /// /// The Twitter access token retrieved from the access token endpoint. diff --git a/src/Microsoft.AspNet.Security.Twitter/Messages/RequestToken.cs b/src/Microsoft.AspNet.Authentication.Twitter/Messages/RequestToken.cs similarity index 89% rename from src/Microsoft.AspNet.Security.Twitter/Messages/RequestToken.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Messages/RequestToken.cs index f801e555f7..51c5c08e4c 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Messages/RequestToken.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Messages/RequestToken.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.Twitter.Messages +namespace Microsoft.AspNet.Authentication.Twitter.Messages { /// /// The Twitter request token obtained from the request token endpoint. diff --git a/src/Microsoft.AspNet.Security.Twitter/Messages/RequestTokenSerializer.cs b/src/Microsoft.AspNet.Authentication.Twitter/Messages/RequestTokenSerializer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Twitter/Messages/RequestTokenSerializer.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Messages/RequestTokenSerializer.cs index 725dcc341f..b575c70ee1 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Messages/RequestTokenSerializer.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Messages/RequestTokenSerializer.cs @@ -4,10 +4,10 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.DataHandler.Serializer; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.DataHandler.Serializer; -namespace Microsoft.AspNet.Security.Twitter.Messages +namespace Microsoft.AspNet.Authentication.Twitter.Messages { /// /// Serializes and deserializes Twitter request and access tokens so that they can be used by other application components. diff --git a/src/Microsoft.AspNet.Security.Twitter/Messages/Serializers.cs b/src/Microsoft.AspNet.Authentication.Twitter/Messages/Serializers.cs similarity index 85% rename from src/Microsoft.AspNet.Security.Twitter/Messages/Serializers.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Messages/Serializers.cs index 3d2e1a458d..749abaa3fd 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Messages/Serializers.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Messages/Serializers.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security.DataHandler.Serializer; +using Microsoft.AspNet.Authentication.DataHandler.Serializer; -namespace Microsoft.AspNet.Security.Twitter.Messages +namespace Microsoft.AspNet.Authentication.Twitter.Messages { /// /// Provides access to a request token serializer. diff --git a/src/Microsoft.AspNet.Security.Twitter/Microsoft.AspNet.Security.Twitter.kproj b/src/Microsoft.AspNet.Authentication.Twitter/Microsoft.AspNet.Authentication.Twitter.kproj similarity index 95% rename from src/Microsoft.AspNet.Security.Twitter/Microsoft.AspNet.Security.Twitter.kproj rename to src/Microsoft.AspNet.Authentication.Twitter/Microsoft.AspNet.Authentication.Twitter.kproj index e073a505c9..fb70dba2a4 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Microsoft.AspNet.Security.Twitter.kproj +++ b/src/Microsoft.AspNet.Authentication.Twitter/Microsoft.AspNet.Authentication.Twitter.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,4 @@ 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Twitter/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication.Twitter/NotNullAttribute.cs new file mode 100644 index 0000000000..c961a0c8f0 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.Twitter/NotNullAttribute.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Authentication.Twitter +{ + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + internal sealed class NotNullAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.Twitter/Notifications/ITwitterAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/ITwitterAuthenticationNotifications.cs similarity index 97% rename from src/Microsoft.AspNet.Security.Twitter/Notifications/ITwitterAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Notifications/ITwitterAuthenticationNotifications.cs index 55fd548926..3bf685ec33 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Notifications/ITwitterAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/ITwitterAuthenticationNotifications.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> diff --git a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterApplyRedirectContext.cs similarity index 91% rename from src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterApplyRedirectContext.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterApplyRedirectContext.cs index a328730ded..ffac976805 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterApplyRedirectContext.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterApplyRedirectContext.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// The Context passed when a Challenge causes a redirect to authorize endpoint in the Twitter middleware. diff --git a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticatedContext.cs similarity index 88% rename from src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticatedContext.cs index 0c050d9e8d..9055c809d0 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticatedContext.cs @@ -3,10 +3,10 @@ using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// Contains information about the login session as well as the user . @@ -56,9 +56,9 @@ namespace Microsoft.AspNet.Security.Twitter public string AccessTokenSecret { get; private set; } /// - /// Gets the representing the user + /// Gets the representing the user /// - public ClaimsIdentity Identity { get; set; } + public ClaimsPrincipal Principal { get; set; } /// /// Gets or sets a property bag for common authentication properties diff --git a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticationNotifications.cs similarity index 98% rename from src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticationNotifications.cs index 2c6ff19d5e..492dbb7f63 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticationNotifications.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// Default implementation. diff --git a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterReturnEndpointContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterReturnEndpointContext.cs similarity index 88% rename from src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterReturnEndpointContext.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterReturnEndpointContext.cs index e420b5d1fb..a4eb87eede 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Notifications/TwitterReturnEndpointContext.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterReturnEndpointContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// Provides context information to middleware providers. diff --git a/src/Microsoft.AspNet.Security.Twitter/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication.Twitter/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security.Twitter/Resources.Designer.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Resources.Designer.cs index deda3cc773..5e6c599ae4 100644 --- a/src/Microsoft.AspNet.Security.Twitter/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.AspNet.Security.Twitter { +namespace Microsoft.AspNet.Authentication.Twitter { using System; @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Security.Twitter { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Security.Twitter.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Authentication.Twitter.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.AspNet.Security.Twitter/Resources.resx b/src/Microsoft.AspNet.Authentication.Twitter/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security.Twitter/Resources.resx rename to src/Microsoft.AspNet.Authentication.Twitter/Resources.resx diff --git a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationDefaults.cs similarity index 69% rename from src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationDefaults.cs index 1f29a04b1a..aa1faa20fb 100644 --- a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationDefaults.cs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { public static class TwitterAuthenticationDefaults { - public const string AuthenticationType = "Twitter"; + public const string AuthenticationScheme = "Twitter"; } } diff --git a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationExtensions.cs similarity index 93% rename from src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationExtensions.cs index 5e97d82245..bff1897923 100644 --- a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationExtensions.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.Twitter; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Twitter; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; using System; diff --git a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs similarity index 86% rename from src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs index b16c4a2184..c6361295b0 100644 --- a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs @@ -11,13 +11,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core.Collections; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.Twitter.Messages; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Twitter.Messages; using Microsoft.AspNet.WebUtilities; using Microsoft.Framework.Logging; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { internal class TwitterAuthenticationHandler : AuthenticationHandler { @@ -72,37 +72,38 @@ namespace Microsoft.AspNet.Security.Twitter if (string.IsNullOrWhiteSpace(returnedToken)) { _logger.WriteWarning("Missing oauth_token"); - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } if (returnedToken != requestToken.Token) { _logger.WriteWarning("Unmatched token"); - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } string oauthVerifier = query.Get("oauth_verifier"); if (string.IsNullOrWhiteSpace(oauthVerifier)) { _logger.WriteWarning("Missing or blank oauth_verifier"); - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } AccessToken accessToken = await ObtainAccessTokenAsync(Options.ConsumerKey, Options.ConsumerSecret, requestToken, oauthVerifier); var context = new TwitterAuthenticatedContext(Context, accessToken.UserId, accessToken.ScreenName, accessToken.Token, accessToken.TokenSecret); - context.Identity = new ClaimsIdentity( - new[] - { - new Claim(ClaimTypes.NameIdentifier, accessToken.UserId, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType), - new Claim(ClaimTypes.Name, accessToken.ScreenName, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType), - new Claim("urn:twitter:userid", accessToken.UserId, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType), - new Claim("urn:twitter:screenname", accessToken.ScreenName, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType) - }, - Options.AuthenticationType, - ClaimsIdentity.DefaultNameClaimType, - ClaimsIdentity.DefaultRoleClaimType); + context.Principal = new ClaimsPrincipal( + new ClaimsIdentity( + new[] + { + new Claim(ClaimTypes.NameIdentifier, accessToken.UserId, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationScheme), + new Claim(ClaimTypes.Name, accessToken.ScreenName, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationScheme), + new Claim("urn:twitter:userid", accessToken.UserId, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationScheme), + new Claim("urn:twitter:screenname", accessToken.ScreenName, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationScheme) + }, + Options.AuthenticationScheme, + ClaimsIdentity.DefaultNameClaimType, + ClaimsIdentity.DefaultRoleClaimType)); context.Properties = requestToken.Properties; var cookieOptions = new CookieOptions @@ -115,12 +116,12 @@ namespace Microsoft.AspNet.Security.Twitter await Options.Notifications.Authenticated(context); - return new AuthenticationTicket(context.Identity, context.Properties); + return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme); } catch (Exception ex) { _logger.WriteError("Authentication failed", ex); - return new AuthenticationTicket(null, properties); + return new AuthenticationTicket(properties, Options.AuthenticationScheme); } } protected override void ApplyResponseChallenge() @@ -135,8 +136,8 @@ namespace Microsoft.AspNet.Security.Twitter return; } - // Active middleware should redirect on 401 even if there wasn't an explicit challenge. - if (ChallengeContext == null && Options.AuthenticationMode == AuthenticationMode.Passive) + // Only redirect on challenges + if (ChallengeContext == null) { return; } @@ -195,26 +196,21 @@ namespace Microsoft.AspNet.Security.Twitter var context = new TwitterReturnEndpointContext(Context, model) { - SignInAsAuthenticationType = Options.SignInAsAuthenticationType, + SignInScheme = Options.SignInScheme, RedirectUri = model.Properties.RedirectUri }; model.Properties.RedirectUri = null; await Options.Notifications.ReturnEndpoint(context); - if (context.SignInAsAuthenticationType != null && context.Identity != null) + if (context.SignInScheme != null && context.Principal != null) { - ClaimsIdentity signInIdentity = context.Identity; - if (!string.Equals(signInIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal)) - { - signInIdentity = new ClaimsIdentity(signInIdentity.Claims, context.SignInAsAuthenticationType, signInIdentity.NameClaimType, signInIdentity.RoleClaimType); - } - Context.Response.SignIn(context.Properties, signInIdentity); + Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties); } if (!context.IsRequestCompleted && context.RedirectUri != null) { - if (context.Identity == null) + if (context.Principal == null) { // add a redirect hint that sign-in failed in some way context.RedirectUri = QueryHelpers.AddQueryString(context.RedirectUri, "error", "access_denied"); diff --git a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs similarity index 90% rename from src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs index 98cdbdf377..6869080921 100644 --- a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs @@ -5,16 +5,15 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net.Http; +using Microsoft.AspNet.Authentication.DataHandler; +using Microsoft.AspNet.Authentication.DataHandler.Encoder; +using Microsoft.AspNet.Authentication.Twitter.Messages; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.DataHandler.Encoder; -using Microsoft.AspNet.Security.Infrastructure; -using Microsoft.AspNet.Security.Twitter.Messages; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// ASP.NET middleware for authenticating users using Twitter @@ -61,20 +60,20 @@ namespace Microsoft.AspNet.Security.Twitter if (Options.StateDataFormat == null) { IDataProtector dataProtector = dataProtectionProvider.CreateProtector( - typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1"); + typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v1"); Options.StateDataFormat = new SecureDataFormat( Serializers.RequestToken, dataProtector, TextEncodings.Base64Url); } - if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) + if (string.IsNullOrEmpty(Options.SignInScheme)) { - Options.SignInAsAuthenticationType = externalOptions.Options.SignInAsAuthenticationType; + Options.SignInScheme = externalOptions.Options.SignInScheme; } - if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) + if (string.IsNullOrEmpty(Options.SignInScheme)) { - throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "SignInAsAuthenticationType")); + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "SignInScheme")); } _httpClient = new HttpClient(ResolveHttpMessageHandler(Options)); diff --git a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs similarity index 92% rename from src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs index 91207863d5..30e78f2765 100644 --- a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs @@ -4,9 +4,9 @@ using System; using System.Net.Http; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Twitter.Messages; +using Microsoft.AspNet.Authentication.Twitter.Messages; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { /// /// Options for the Twitter authentication middleware. @@ -18,10 +18,9 @@ namespace Microsoft.AspNet.Security.Twitter /// public TwitterAuthenticationOptions() { - AuthenticationType = TwitterAuthenticationDefaults.AuthenticationType; - Caption = AuthenticationType; + AuthenticationScheme = TwitterAuthenticationDefaults.AuthenticationScheme; + Caption = AuthenticationScheme; CallbackPath = new PathString("/signin-twitter"); - AuthenticationMode = AuthenticationMode.Passive; BackchannelTimeout = TimeSpan.FromSeconds(60); #if ASPNET50 // Twitter lists its valid Subject Key Identifiers at https://dev.twitter.com/docs/security/using-ssl @@ -92,7 +91,7 @@ namespace Microsoft.AspNet.Security.Twitter /// /// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user . /// - public string SignInAsAuthenticationType { get; set; } + public string SignInScheme { get; set; } /// /// Gets or sets the type used to secure data handled by the middleware. diff --git a/src/Microsoft.AspNet.Security.Twitter/project.json b/src/Microsoft.AspNet.Authentication.Twitter/project.json similarity index 90% rename from src/Microsoft.AspNet.Security.Twitter/project.json rename to src/Microsoft.AspNet.Authentication.Twitter/project.json index b9eba0a305..059a8d2574 100644 --- a/src/Microsoft.AspNet.Security.Twitter/project.json +++ b/src/Microsoft.AspNet.Authentication.Twitter/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 middleware that enables an application to support Twitter's OAuth 2.0 authentication workflow.", "dependencies": { - "Microsoft.AspNet.Security": "1.0.0-*" + "Microsoft.AspNet.Authentication": "1.0.0-*" }, "frameworks": { "aspnet50": { diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs similarity index 83% rename from src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs index 92b7889d58..f3d13d33fe 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs @@ -1,22 +1,19 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Security.Claims; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Authentication.DataHandler.Encoder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Http.Interfaces.Security; -using Microsoft.AspNet.Security.DataHandler.Encoder; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Http.Interfaces.Authentication; using Microsoft.Framework.Logging; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { /// /// Base class for the per-request work performed by most authentication middleware. @@ -36,7 +33,7 @@ namespace Microsoft.AspNet.Security.Infrastructure private AuthenticationOptions _baseOptions; protected IChallengeContext ChallengeContext { get; set; } - protected SignInIdentityContext SignInIdentityContext { get; set; } + protected SignInContext SignInContext { get; set; } protected ISignOutContext SignOutContext { get; set; } protected HttpContext Context { get; private set; } @@ -58,6 +55,8 @@ namespace Microsoft.AspNet.Security.Infrastructure get { return _baseOptions; } } + internal bool AuthenticateCalled { get; set; } + public IAuthenticationHandler PriorHandler { get; set; } public bool Faulted { get; set; } @@ -73,18 +72,6 @@ namespace Microsoft.AspNet.Security.Infrastructure Response.OnSendingHeaders(OnSendingHeaderCallback, this); await InitializeCoreAsync(); - - if (BaseOptions.AuthenticationMode == AuthenticationMode.Active) - { - AuthenticationTicket ticket = await AuthenticateAsync(); - if (ticket != null) - { - if ( ticket.Identity != null) - SecurityHelper.AddUserIdentity(Context, ticket.Identity); - else if (ticket.Principal != null) - SecurityHelper.AddUserIdentity(Context, ticket.Principal.Identity); - } - } } private static void OnSendingHeaderCallback(object state) @@ -144,28 +131,29 @@ namespace Microsoft.AspNet.Security.Infrastructure return Task.FromResult(false); } - public virtual void GetDescriptions(IAuthTypeContext authTypeContext) + public virtual void GetDescriptions(IDescribeSchemesContext describeContext) { - authTypeContext.Accept(BaseOptions.Description.Dictionary); + describeContext.Accept(BaseOptions.Description.Dictionary); if (PriorHandler != null) { - PriorHandler.GetDescriptions(authTypeContext); + PriorHandler.GetDescriptions(describeContext); } } public virtual void Authenticate(IAuthenticateContext context) { - if (context.AuthenticationTypes.Contains(BaseOptions.AuthenticationType, StringComparer.Ordinal)) + if (context.AuthenticationSchemes.Contains(BaseOptions.AuthenticationScheme, StringComparer.Ordinal)) { AuthenticationTicket ticket = Authenticate(); - if (ticket != null && ticket.Identity != null) + if (ticket != null && ticket.Principal != null) { - context.Authenticated(ticket.Identity, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); + AuthenticateCalled = true; + context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); } else { - context.NotAuthenticated(BaseOptions.AuthenticationType, properties: null, description: BaseOptions.Description.Dictionary); + context.NotAuthenticated(BaseOptions.AuthenticationScheme, properties: null, description: BaseOptions.Description.Dictionary); } } @@ -177,16 +165,17 @@ namespace Microsoft.AspNet.Security.Infrastructure public virtual async Task AuthenticateAsync(IAuthenticateContext context) { - if (context.AuthenticationTypes.Contains(BaseOptions.AuthenticationType, StringComparer.Ordinal)) + if (context.AuthenticationSchemes.Contains(BaseOptions.AuthenticationScheme, StringComparer.Ordinal)) { AuthenticationTicket ticket = await AuthenticateAsync(); - if (ticket != null && ticket.Identity != null) + if (ticket != null && ticket.Principal != null) { - context.Authenticated(ticket.Identity, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); + AuthenticateCalled = true; + context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); } else { - context.NotAuthenticated(BaseOptions.AuthenticationType, properties: null, description: BaseOptions.Description.Dictionary); + context.NotAuthenticated(BaseOptions.AuthenticationScheme, properties: null, description: BaseOptions.Description.Dictionary); } } @@ -325,12 +314,11 @@ namespace Microsoft.AspNet.Security.Infrastructure public virtual void SignIn(ISignInContext context) { - ClaimsIdentity identity; - if (SecurityHelper.LookupSignIn(context.Identities, BaseOptions.AuthenticationType, out identity)) + if (ShouldHandleScheme(context.AuthenticationScheme)) { - SignInIdentityContext = new SignInIdentityContext(identity, new AuthenticationProperties(context.Properties)); + SignInContext = new SignInContext(context.Principal, new AuthenticationProperties(context.Properties)); SignOutContext = null; - context.Accept(BaseOptions.AuthenticationType, BaseOptions.Description.Dictionary); + context.Accept(BaseOptions.Description.Dictionary); } if (PriorHandler != null) @@ -341,11 +329,11 @@ namespace Microsoft.AspNet.Security.Infrastructure public virtual void SignOut(ISignOutContext context) { - if (SecurityHelper.LookupSignOut(context.AuthenticationTypes, BaseOptions.AuthenticationType, BaseOptions.AuthenticationMode)) + if (ShouldHandleScheme(context.AuthenticationScheme)) { - SignInIdentityContext = null; + SignInContext = null; SignOutContext = context; - context.Accept(BaseOptions.AuthenticationType, BaseOptions.Description.Dictionary); + context.Accept(); } if (PriorHandler != null) @@ -356,10 +344,10 @@ namespace Microsoft.AspNet.Security.Infrastructure public virtual void Challenge(IChallengeContext context) { - if (SecurityHelper.LookupChallenge(context.AuthenticationTypes, BaseOptions.AuthenticationType, BaseOptions.AuthenticationMode)) + if (ShouldHandleScheme(context.AuthenticationSchemes)) { ChallengeContext = context; - context.Accept(BaseOptions.AuthenticationType, BaseOptions.Description.Dictionary); + context.Accept(BaseOptions.AuthenticationScheme, BaseOptions.Description.Dictionary); } if (PriorHandler != null) @@ -370,6 +358,18 @@ namespace Microsoft.AspNet.Security.Infrastructure protected abstract void ApplyResponseChallenge(); + public virtual bool ShouldHandleScheme(IEnumerable authenticationSchemes) + { + return authenticationSchemes != null && + authenticationSchemes.Any() && + authenticationSchemes.Contains(BaseOptions.AuthenticationScheme, StringComparer.Ordinal); + } + + public virtual bool ShouldHandleScheme(string authenticationScheme) + { + return string.Equals(BaseOptions.AuthenticationScheme, authenticationScheme, StringComparison.Ordinal); + } + /// /// Override this method to deal with 401 challenge concerns, if an authentication scheme in question /// deals an authentication interaction as part of it's request flow. (like adding a response header, or @@ -384,7 +384,7 @@ namespace Microsoft.AspNet.Security.Infrastructure protected void GenerateCorrelationId([NotNull] AuthenticationProperties properties) { - string correlationKey = Constants.CorrelationPrefix + BaseOptions.AuthenticationType; + string correlationKey = Constants.CorrelationPrefix + BaseOptions.AuthenticationScheme; var nonceBytes = new byte[32]; CryptoRandom.GetBytes(nonceBytes); @@ -403,7 +403,7 @@ namespace Microsoft.AspNet.Security.Infrastructure protected bool ValidateCorrelationId([NotNull] AuthenticationProperties properties, [NotNull] ILogger logger) { - string correlationKey = Constants.CorrelationPrefix + BaseOptions.AuthenticationType; + string correlationKey = Constants.CorrelationPrefix + BaseOptions.AuthenticationScheme; string correlationCookie = Request.Cookies[correlationKey]; if (string.IsNullOrWhiteSpace(correlationCookie)) diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler`1.cs b/src/Microsoft.AspNet.Authentication/AuthenticationHandler`1.cs similarity index 90% rename from src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler`1.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationHandler`1.cs index 7d8fb07262..a70b11c60a 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler`1.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationHandler`1.cs @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System.Threading.Tasks; using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { /// /// Base class for the per-request work performed by most authentication middleware. @@ -21,7 +20,7 @@ namespace Microsoft.AspNet.Security.Infrastructure /// The original options passed by the application control behavior /// The utility object to observe the current request and response /// async completion - internal Task Initialize(TOptions options, HttpContext context) + public Task Initialize(TOptions options, HttpContext context) { Options = options; return BaseInitializeAsync(options, context); diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs similarity index 95% rename from src/Microsoft.AspNet.Security/Infrastructure/AuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs index a703619de6..400a6e74ad 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; @@ -9,7 +8,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { public abstract class AuthenticationMiddleware where TOptions : AuthenticationOptions, new() { @@ -31,7 +30,7 @@ namespace Microsoft.AspNet.Security.Infrastructure _services = services; } - public string AuthenticationType { get; set; } + public string AuthenticationScheme { get; set; } public TOptions Options { get; set; } diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication/AuthenticationOptions.cs new file mode 100644 index 0000000000..09df9e5da1 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication/AuthenticationOptions.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Http.Authentication; + +namespace Microsoft.AspNet.Authentication +{ + /// + /// Base Options for all authentication middleware + /// + public abstract class AuthenticationOptions + { + private string _authenticationScheme; + + /// + /// The AuthenticationScheme in the options corresponds to the logical name for a particular authentication scheme. A different + /// value may be assigned in order to use the same authentication middleware type more than once in a pipeline. + /// + public string AuthenticationScheme + { + get { return _authenticationScheme; } + set + { + _authenticationScheme = value; + Description.AuthenticationScheme = value; + } + } + + /// + /// Additional information about the authentication type which is made available to the application. + /// + public AuthenticationDescription Description { get; set; } = new AuthenticationDescription(); + } +} diff --git a/src/Microsoft.AspNet.Security/AuthenticationTicket.cs b/src/Microsoft.AspNet.Authentication/AuthenticationTicket.cs similarity index 59% rename from src/Microsoft.AspNet.Security/AuthenticationTicket.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationTicket.cs index 82128f10cd..c7fb43f9a9 100644 --- a/src/Microsoft.AspNet.Security/AuthenticationTicket.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationTicket.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Security.Claims; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { /// /// Contains user identity information as well as additional authentication state. @@ -14,23 +14,19 @@ namespace Microsoft.AspNet.Security /// /// Initializes a new instance of the class /// - /// - /// - public AuthenticationTicket(ClaimsIdentity identity, AuthenticationProperties properties) - { - Identity = identity; - Properties = properties ?? new AuthenticationProperties(); - } + /// additional properties that can be consumed by the user or runtime. + /// the authentication middleware that was responsible for this ticket. + public AuthenticationTicket(AuthenticationProperties properties, string authenticationScheme) : this(null, properties, authenticationScheme) { } /// /// Initializes a new instance of the class /// - /// the that represents the authenticated user. + /// the that represents the authenticated user. /// additional properties that can be consumed by the user or runtime. - /// the authentication middleware that was responsible for this ticket. - public AuthenticationTicket(ClaimsPrincipal principal, AuthenticationProperties properties, string authenticationType) + /// the authentication middleware that was responsible for this ticket. + public AuthenticationTicket(ClaimsPrincipal principal, AuthenticationProperties properties, string authenticationScheme) { - AuthenticationType = authenticationType; + AuthenticationScheme = authenticationScheme; Principal = principal; Properties = properties ?? new AuthenticationProperties(); } @@ -38,12 +34,7 @@ namespace Microsoft.AspNet.Security /// /// Gets the authentication type. /// - public string AuthenticationType { get; private set; } - - /// - /// Gets the authenticated user identity. - /// - public ClaimsIdentity Identity { get; private set; } + public string AuthenticationScheme { get; private set; } /// /// Gets the claims-principal with authenticated user identities. diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenCreateContext.cs b/src/Microsoft.AspNet.Authentication/AuthenticationTokenCreateContext.cs similarity index 91% rename from src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenCreateContext.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationTokenCreateContext.cs index 47815bbcde..eed3ac761a 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenCreateContext.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationTokenCreateContext.cs @@ -4,9 +4,9 @@ using System; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { public class AuthenticationTokenCreateContext : BaseContext { diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenProvider.cs b/src/Microsoft.AspNet.Authentication/AuthenticationTokenProvider.cs similarity index 98% rename from src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenProvider.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationTokenProvider.cs index 7fb4fb4984..7d090346fc 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenProvider.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationTokenProvider.cs @@ -5,7 +5,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { public class AuthenticationTokenProvider : IAuthenticationTokenProvider { diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenReceiveContext.cs b/src/Microsoft.AspNet.Authentication/AuthenticationTokenReceiveContext.cs similarity index 88% rename from src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenReceiveContext.cs rename to src/Microsoft.AspNet.Authentication/AuthenticationTokenReceiveContext.cs index 2e68dc3080..ea8e854ef2 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationTokenReceiveContext.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationTokenReceiveContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { public class AuthenticationTokenReceiveContext : BaseContext { diff --git a/src/Microsoft.AspNet.Authentication/AutomaticAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication/AutomaticAuthenticationHandler.cs new file mode 100644 index 0000000000..5032e47fae --- /dev/null +++ b/src/Microsoft.AspNet.Authentication/AutomaticAuthenticationHandler.cs @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNet.Http.Interfaces.Authentication; + +namespace Microsoft.AspNet.Authentication +{ + /// + /// Base class for the per-request work performed by automatic authentication middleware. + /// + /// Specifies which type for of AutomaticAuthenticationOptions property + public abstract class AutomaticAuthenticationHandler : AuthenticationHandler where TOptions : AutomaticAuthenticationOptions + { + public virtual bool ShouldConvertChallengeToForbidden() + { + // Return 403 iff 401 and this handler's authenticate was called + // and the challenge is for the authentication type + return Response.StatusCode == 401 && + AuthenticateCalled && + ChallengeContext != null && + ShouldHandleScheme(ChallengeContext.AuthenticationSchemes); + } + + protected async override Task InitializeCoreAsync() + { + if (Options.AutomaticAuthentication) + { + AuthenticationTicket ticket = await AuthenticateAsync(); + if (ticket != null && ticket.Principal != null) + { + SecurityHelper.AddUserPrincipal(Context, ticket.Principal); + } + } + } + + public override void SignOut(ISignOutContext context) + { + // Empty or null auth scheme is allowed for automatic Authentication + if (Options.AutomaticAuthentication && string.IsNullOrWhiteSpace(context.AuthenticationScheme)) + { + SignInContext = null; + SignOutContext = context; + context.Accept(); + } + + base.SignOut(context); + } + + public override void Challenge(IChallengeContext context) + { + // Null or Empty scheme allowed for automatic authentication + if (Options.AutomaticAuthentication && + (context.AuthenticationSchemes == null || !context.AuthenticationSchemes.Any())) + { + ChallengeContext = context; + context.Accept(BaseOptions.AuthenticationScheme, BaseOptions.Description.Dictionary); + } + + base.Challenge(context); + } + + /// + /// Automatic Authentication Handlers can handle empty authentication schemes + /// + /// + public override bool ShouldHandleScheme(IEnumerable authenticationSchemes) + { + if (base.ShouldHandleScheme(authenticationSchemes)) + { + return true; + } + + return Options.AutomaticAuthentication && + (authenticationSchemes == null || !authenticationSchemes.Any()); + } + + /// + /// Automatic Authentication Handlers can handle empty authentication schemes + /// + /// + public override bool ShouldHandleScheme(string authenticationScheme) + { + if (base.ShouldHandleScheme(authenticationScheme)) + { + return true; + } + + return Options.AutomaticAuthentication && string.IsNullOrWhiteSpace(authenticationScheme); + } + + /// + /// Override this method to deal with 401 challenge concerns, if an authentication scheme in question + /// deals an authentication interaction as part of it's request flow. (like adding a response header, or + /// changing the 401 result to 302 of a login page or external sign-in location.) + /// + /// + protected override Task ApplyResponseChallengeAsync() + { + // If authenticate was called and the the status is still 401, authZ failed so set 403 and stop + if (ShouldConvertChallengeToForbidden()) + { + Response.StatusCode = 403; + return Task.FromResult(0); + } + return base.ApplyResponseChallengeAsync(); + } + + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication/AutomaticAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication/AutomaticAuthenticationOptions.cs new file mode 100644 index 0000000000..53af209846 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication/AutomaticAuthenticationOptions.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Http.Authentication; + +namespace Microsoft.AspNet.Authentication +{ + /// + /// Base Options for all automatic authentication middleware + /// + public abstract class AutomaticAuthenticationOptions : AuthenticationOptions + { + /// + /// If true the authentication middleware alter the request user coming in and + /// alter 401 Unauthorized responses going out. If false the authentication middleware will only provide + /// identity and alter responses when explicitly indicated by the AuthenticationScheme. + /// + public bool AutomaticAuthentication { get; set; } + } +} diff --git a/src/Microsoft.AspNet.Security/CertificateSubjectKeyIdentifierValidator.cs b/src/Microsoft.AspNet.Authentication/CertificateSubjectKeyIdentifierValidator.cs similarity index 98% rename from src/Microsoft.AspNet.Security/CertificateSubjectKeyIdentifierValidator.cs rename to src/Microsoft.AspNet.Authentication/CertificateSubjectKeyIdentifierValidator.cs index 68cf5abd28..ca729b68f9 100644 --- a/src/Microsoft.AspNet.Security/CertificateSubjectKeyIdentifierValidator.cs +++ b/src/Microsoft.AspNet.Authentication/CertificateSubjectKeyIdentifierValidator.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Net.Security; using System.Security.Cryptography.X509Certificates; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { /// /// Provides pinned certificate validation based on the subject key identifier of the certificate. diff --git a/src/Microsoft.AspNet.Security/CertificateSubjectPublicKeyInfoValidator.cs b/src/Microsoft.AspNet.Authentication/CertificateSubjectPublicKeyInfoValidator.cs similarity index 99% rename from src/Microsoft.AspNet.Security/CertificateSubjectPublicKeyInfoValidator.cs rename to src/Microsoft.AspNet.Authentication/CertificateSubjectPublicKeyInfoValidator.cs index 4ad5ee81c6..f2e5e9554c 100644 --- a/src/Microsoft.AspNet.Security/CertificateSubjectPublicKeyInfoValidator.cs +++ b/src/Microsoft.AspNet.Authentication/CertificateSubjectPublicKeyInfoValidator.cs @@ -12,7 +12,7 @@ using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using Microsoft.Win32; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { /// /// Implements a cert pinning validator passed on diff --git a/src/Microsoft.AspNet.Security/CertificateThumbprintValidator.cs b/src/Microsoft.AspNet.Authentication/CertificateThumbprintValidator.cs similarity index 98% rename from src/Microsoft.AspNet.Security/CertificateThumbprintValidator.cs rename to src/Microsoft.AspNet.Authentication/CertificateThumbprintValidator.cs index a276536a70..822b420140 100644 --- a/src/Microsoft.AspNet.Security/CertificateThumbprintValidator.cs +++ b/src/Microsoft.AspNet.Authentication/CertificateThumbprintValidator.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Net.Security; using System.Security.Cryptography.X509Certificates; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { /// /// Provides pinned certificate validation based on the certificate thumbprint. diff --git a/src/Microsoft.AspNet.Security/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Authentication/Constants.cs similarity index 88% rename from src/Microsoft.AspNet.Security/Infrastructure/Constants.cs rename to src/Microsoft.AspNet.Authentication/Constants.cs index 26cfa103ce..da3a23daab 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNet.Authentication/Constants.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { internal static class Constants { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Encoder/Base64TextEncoder.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/Base64TextEncoder.cs similarity index 88% rename from src/Microsoft.AspNet.Security/DataHandler/Encoder/Base64TextEncoder.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Encoder/Base64TextEncoder.cs index 9a208979d9..0a40564502 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Encoder/Base64TextEncoder.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/Base64TextEncoder.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.AspNet.Security.DataHandler.Encoder +namespace Microsoft.AspNet.Authentication.DataHandler.Encoder { public class Base64TextEncoder : ITextEncoder { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Encoder/Base64UrlTextEncoder.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/Base64UrlTextEncoder.cs similarity index 93% rename from src/Microsoft.AspNet.Security/DataHandler/Encoder/Base64UrlTextEncoder.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Encoder/Base64UrlTextEncoder.cs index b57fb51d9a..93dd1a057c 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Encoder/Base64UrlTextEncoder.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/Base64UrlTextEncoder.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.AspNet.Security.DataHandler.Encoder +namespace Microsoft.AspNet.Authentication.DataHandler.Encoder { public class Base64UrlTextEncoder : ITextEncoder { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Encoder/ITextEncoder.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/ITextEncoder.cs similarity index 83% rename from src/Microsoft.AspNet.Security/DataHandler/Encoder/ITextEncoder.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Encoder/ITextEncoder.cs index 6ee681475c..aeb577ec06 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Encoder/ITextEncoder.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/ITextEncoder.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.DataHandler.Encoder +namespace Microsoft.AspNet.Authentication.DataHandler.Encoder { public interface ITextEncoder { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Encoder/TextEncodings.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/TextEncodings.cs similarity index 91% rename from src/Microsoft.AspNet.Security/DataHandler/Encoder/TextEncodings.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Encoder/TextEncodings.cs index 67b2333769..1b59cec5ce 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Encoder/TextEncodings.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Encoder/TextEncodings.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.DataHandler.Encoder +namespace Microsoft.AspNet.Authentication.DataHandler.Encoder { public static class TextEncodings { diff --git a/src/Microsoft.AspNet.Security/DataHandler/ISecureDataFormat.cs b/src/Microsoft.AspNet.Authentication/DataHandler/ISecureDataFormat.cs similarity index 88% rename from src/Microsoft.AspNet.Security/DataHandler/ISecureDataFormat.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/ISecureDataFormat.cs index eae66197fc..2e3f24e841 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/ISecureDataFormat.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/ISecureDataFormat.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { public interface ISecureDataFormat { diff --git a/src/Microsoft.AspNet.Security/DataHandler/PropertiesDataFormat.cs b/src/Microsoft.AspNet.Authentication/DataHandler/PropertiesDataFormat.cs similarity index 69% rename from src/Microsoft.AspNet.Security/DataHandler/PropertiesDataFormat.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/PropertiesDataFormat.cs index 19a11a2522..1472dd427b 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/PropertiesDataFormat.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/PropertiesDataFormat.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.DataHandler.Encoder; -using Microsoft.AspNet.Security.DataHandler.Serializer; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.DataHandler.Encoder; +using Microsoft.AspNet.Authentication.DataHandler.Serializer; -namespace Microsoft.AspNet.Security.DataHandler +namespace Microsoft.AspNet.Authentication.DataHandler { public class PropertiesDataFormat : SecureDataFormat { diff --git a/src/Microsoft.AspNet.Security/DataHandler/SecureDataFormat.cs b/src/Microsoft.AspNet.Authentication/DataHandler/SecureDataFormat.cs similarity index 92% rename from src/Microsoft.AspNet.Security/DataHandler/SecureDataFormat.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/SecureDataFormat.cs index 0c314fbf2c..b7e240768b 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/SecureDataFormat.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/SecureDataFormat.cs @@ -4,10 +4,10 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.DataHandler.Encoder; -using Microsoft.AspNet.Security.DataHandler.Serializer; +using Microsoft.AspNet.Authentication.DataHandler.Encoder; +using Microsoft.AspNet.Authentication.DataHandler.Serializer; -namespace Microsoft.AspNet.Security.DataHandler +namespace Microsoft.AspNet.Authentication.DataHandler { public class SecureDataFormat : ISecureDataFormat { @@ -62,4 +62,4 @@ namespace Microsoft.AspNet.Security.DataHandler } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security/DataHandler/Serializer/DataSerializers.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/DataSerializers.cs similarity index 84% rename from src/Microsoft.AspNet.Security/DataHandler/Serializer/DataSerializers.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Serializer/DataSerializers.cs index a1864b44d0..fd8e45fc8f 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Serializer/DataSerializers.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/DataSerializers.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.DataHandler.Serializer +namespace Microsoft.AspNet.Authentication.DataHandler.Serializer { public static class DataSerializers { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Serializer/IDataSerializer.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/IDataSerializer.cs similarity index 83% rename from src/Microsoft.AspNet.Security/DataHandler/Serializer/IDataSerializer.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Serializer/IDataSerializer.cs index 60bd25bdab..dc78d8c467 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Serializer/IDataSerializer.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/IDataSerializer.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security.DataHandler.Serializer +namespace Microsoft.AspNet.Authentication.DataHandler.Serializer { public interface IDataSerializer { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Serializer/PropertiesSerializer.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs similarity index 95% rename from src/Microsoft.AspNet.Security/DataHandler/Serializer/PropertiesSerializer.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs index 66dcdfe3a9..836828cdaa 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Serializer/PropertiesSerializer.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs @@ -6,9 +6,9 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.DataHandler.Serializer +namespace Microsoft.AspNet.Authentication.DataHandler.Serializer { public class PropertiesSerializer : IDataSerializer { diff --git a/src/Microsoft.AspNet.Security/DataHandler/Serializer/TicketSerializer.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/TicketSerializer.cs similarity index 52% rename from src/Microsoft.AspNet.Security/DataHandler/Serializer/TicketSerializer.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/Serializer/TicketSerializer.cs index 9fe982ee82..9833dad54a 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/Serializer/TicketSerializer.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/TicketSerializer.cs @@ -6,7 +6,7 @@ using System.IO; using System.Linq; using System.Security.Claims; -namespace Microsoft.AspNet.Security.DataHandler.Serializer +namespace Microsoft.AspNet.Authentication.DataHandler.Serializer { public class TicketSerializer : IDataSerializer { @@ -38,18 +38,24 @@ namespace Microsoft.AspNet.Security.DataHandler.Serializer public static void Write([NotNull] BinaryWriter writer, [NotNull] AuthenticationTicket model) { writer.Write(FormatVersion); - ClaimsIdentity identity = model.Identity; - writer.Write(identity.AuthenticationType); - WriteWithDefault(writer, identity.NameClaimType, DefaultValues.NameClaimType); - WriteWithDefault(writer, identity.RoleClaimType, DefaultValues.RoleClaimType); - writer.Write(identity.Claims.Count()); - foreach (var claim in identity.Claims) + writer.Write(model.AuthenticationScheme); + var principal = model.Principal; + writer.Write(principal.Identities.Count()); + foreach (var identity in principal.Identities) { - WriteWithDefault(writer, claim.Type, identity.NameClaimType); - writer.Write(claim.Value); - WriteWithDefault(writer, claim.ValueType, DefaultValues.StringValueType); - WriteWithDefault(writer, claim.Issuer, DefaultValues.LocalAuthority); - WriteWithDefault(writer, claim.OriginalIssuer, claim.Issuer); + var authenticationType = string.IsNullOrWhiteSpace(identity.AuthenticationType) ? string.Empty : identity.AuthenticationType; + writer.Write(authenticationType); + WriteWithDefault(writer, identity.NameClaimType, DefaultValues.NameClaimType); + WriteWithDefault(writer, identity.RoleClaimType, DefaultValues.RoleClaimType); + writer.Write(identity.Claims.Count()); + foreach (var claim in identity.Claims) + { + WriteWithDefault(writer, claim.Type, identity.NameClaimType); + writer.Write(claim.Value); + WriteWithDefault(writer, claim.ValueType, DefaultValues.StringValueType); + WriteWithDefault(writer, claim.Issuer, DefaultValues.LocalAuthority); + WriteWithDefault(writer, claim.OriginalIssuer, claim.Issuer); + } } PropertiesSerializer.Write(writer, model.Properties); } @@ -60,24 +66,29 @@ namespace Microsoft.AspNet.Security.DataHandler.Serializer { return null; } - - string authenticationType = reader.ReadString(); - string nameClaimType = ReadWithDefault(reader, DefaultValues.NameClaimType); - string roleClaimType = ReadWithDefault(reader, DefaultValues.RoleClaimType); - int count = reader.ReadInt32(); - var claims = new Claim[count]; - for (int index = 0; index != count; ++index) + string authenticationScheme = reader.ReadString(); + int identityCount = reader.ReadInt32(); + var identities = new ClaimsIdentity[identityCount]; + for (int i = 0; i != identityCount; ++i) { - string type = ReadWithDefault(reader, nameClaimType); - string value = reader.ReadString(); - string valueType = ReadWithDefault(reader, DefaultValues.StringValueType); - string issuer = ReadWithDefault(reader, DefaultValues.LocalAuthority); - string originalIssuer = ReadWithDefault(reader, issuer); - claims[index] = new Claim(type, value, valueType, issuer, originalIssuer); + string authenticationType = reader.ReadString(); + string nameClaimType = ReadWithDefault(reader, DefaultValues.NameClaimType); + string roleClaimType = ReadWithDefault(reader, DefaultValues.RoleClaimType); + int count = reader.ReadInt32(); + var claims = new Claim[count]; + for (int index = 0; index != count; ++index) + { + string type = ReadWithDefault(reader, nameClaimType); + string value = reader.ReadString(); + string valueType = ReadWithDefault(reader, DefaultValues.StringValueType); + string issuer = ReadWithDefault(reader, DefaultValues.LocalAuthority); + string originalIssuer = ReadWithDefault(reader, issuer); + claims[index] = new Claim(type, value, valueType, issuer, originalIssuer); + } + identities[i] = new ClaimsIdentity(claims, authenticationType, nameClaimType, roleClaimType); } - var identity = new ClaimsIdentity(claims, authenticationType, nameClaimType, roleClaimType); var properties = PropertiesSerializer.Read(reader); - return new AuthenticationTicket(identity, properties); + return new AuthenticationTicket(new ClaimsPrincipal(identities), properties, authenticationScheme); } private static void WriteWithDefault(BinaryWriter writer, string value, string defaultValue) diff --git a/src/Microsoft.AspNet.Security/DataHandler/TicketDataFormat.cs b/src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs similarity index 72% rename from src/Microsoft.AspNet.Security/DataHandler/TicketDataFormat.cs rename to src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs index b54f166662..922f5c8c08 100644 --- a/src/Microsoft.AspNet.Security/DataHandler/TicketDataFormat.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs @@ -1,12 +1,11 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using Microsoft.AspNet.DataProtection; -using Microsoft.AspNet.Security.DataHandler.Encoder; -using Microsoft.AspNet.Security.DataHandler.Serializer; +using Microsoft.AspNet.Authentication.DataHandler.Encoder; +using Microsoft.AspNet.Authentication.DataHandler.Serializer; -namespace Microsoft.AspNet.Security.DataHandler +namespace Microsoft.AspNet.Authentication.DataHandler { public class TicketDataFormat : SecureDataFormat { diff --git a/src/Microsoft.AspNet.Security/ExternalAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication/ExternalAuthenticationOptions.cs similarity index 72% rename from src/Microsoft.AspNet.Security/ExternalAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication/ExternalAuthenticationOptions.cs index 671020b2b6..966e2cfe14 100644 --- a/src/Microsoft.AspNet.Security/ExternalAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication/ExternalAuthenticationOptions.cs @@ -4,10 +4,10 @@ using System; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { public class ExternalAuthenticationOptions { - public string SignInAsAuthenticationType { get; set; } + public string SignInScheme { get; set; } } } diff --git a/src/Microsoft.AspNet.Security/Infrastructure/HttpContextExtensions.cs b/src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs similarity index 82% rename from src/Microsoft.AspNet.Security/Infrastructure/HttpContextExtensions.cs rename to src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs index 5ba7a9ce4f..2f6b0e4d34 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/HttpContextExtensions.cs +++ b/src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Core.Security; -using Microsoft.AspNet.Http.Interfaces.Security; +using Microsoft.AspNet.Http.Core.Authentication; +using Microsoft.AspNet.Http.Interfaces.Authentication; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { internal static class HttpContextExtensions { diff --git a/src/Microsoft.AspNet.Security/Infrastructure/IAuthenticationTokenProvider.cs b/src/Microsoft.AspNet.Authentication/IAuthenticationTokenProvider.cs similarity index 91% rename from src/Microsoft.AspNet.Security/Infrastructure/IAuthenticationTokenProvider.cs rename to src/Microsoft.AspNet.Authentication/IAuthenticationTokenProvider.cs index 2edcb42b22..d0c2bf34cc 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/IAuthenticationTokenProvider.cs +++ b/src/Microsoft.AspNet.Authentication/IAuthenticationTokenProvider.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { public interface IAuthenticationTokenProvider { diff --git a/src/Microsoft.AspNet.Security/ICertificateValidator.cs b/src/Microsoft.AspNet.Authentication/ICertificateValidator.cs similarity index 97% rename from src/Microsoft.AspNet.Security/ICertificateValidator.cs rename to src/Microsoft.AspNet.Authentication/ICertificateValidator.cs index 26756324ff..fd20f70b3a 100644 --- a/src/Microsoft.AspNet.Security/ICertificateValidator.cs +++ b/src/Microsoft.AspNet.Authentication/ICertificateValidator.cs @@ -6,7 +6,7 @@ using System; using System.Net.Security; using System.Security.Cryptography.X509Certificates; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { /// /// Interface for providing pinned certificate validation, which checks HTTPS diff --git a/src/Microsoft.AspNet.Security/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNet.Authentication/ISystemClock.cs similarity index 90% rename from src/Microsoft.AspNet.Security/Infrastructure/ISystemClock.cs rename to src/Microsoft.AspNet.Authentication/ISystemClock.cs index 4f799dc98b..4748fb63ea 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNet.Authentication/ISystemClock.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { /// /// Abstracts the system clock to facilitate testing. diff --git a/src/Microsoft.AspNet.Security/Microsoft.AspNet.Security.kproj b/src/Microsoft.AspNet.Authentication/Microsoft.AspNet.Authentication.kproj similarity index 95% rename from src/Microsoft.AspNet.Security/Microsoft.AspNet.Security.kproj rename to src/Microsoft.AspNet.Authentication/Microsoft.AspNet.Authentication.kproj index 6262851a78..b1e2359004 100644 --- a/src/Microsoft.AspNet.Security/Microsoft.AspNet.Security.kproj +++ b/src/Microsoft.AspNet.Authentication/Microsoft.AspNet.Authentication.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,4 @@ 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.OAuth/NotNullAttribute.cs b/src/Microsoft.AspNet.Authentication/NotNullAttribute.cs similarity index 88% rename from src/Microsoft.AspNet.Security.OAuth/NotNullAttribute.cs rename to src/Microsoft.AspNet.Authentication/NotNullAttribute.cs index 3f56c41518..a307633176 100644 --- a/src/Microsoft.AspNet.Security.OAuth/NotNullAttribute.cs +++ b/src/Microsoft.AspNet.Authentication/NotNullAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security.OAuth +namespace Microsoft.AspNet.Authentication { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] internal sealed class NotNullAttribute : Attribute diff --git a/src/Microsoft.AspNet.Security/Notifications/AuthenticationFailedNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/AuthenticationFailedNotification.cs similarity index 91% rename from src/Microsoft.AspNet.Security/Notifications/AuthenticationFailedNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/AuthenticationFailedNotification.cs index 5d232426f6..16aa157517 100644 --- a/src/Microsoft.AspNet.Security/Notifications/AuthenticationFailedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/AuthenticationFailedNotification.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class AuthenticationFailedNotification : BaseNotification { diff --git a/src/Microsoft.AspNet.Security/Notifications/BaseContext.cs b/src/Microsoft.AspNet.Authentication/Notifications/BaseContext.cs similarity index 92% rename from src/Microsoft.AspNet.Security/Notifications/BaseContext.cs rename to src/Microsoft.AspNet.Authentication/Notifications/BaseContext.cs index 3ae13a76dc..11f65199cb 100644 --- a/src/Microsoft.AspNet.Security/Notifications/BaseContext.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/BaseContext.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public abstract class BaseContext { diff --git a/src/Microsoft.AspNet.Security/Notifications/BaseContext`1.cs b/src/Microsoft.AspNet.Authentication/Notifications/BaseContext`1.cs similarity index 93% rename from src/Microsoft.AspNet.Security/Notifications/BaseContext`1.cs rename to src/Microsoft.AspNet.Authentication/Notifications/BaseContext`1.cs index e0ad306265..184adfb3b0 100644 --- a/src/Microsoft.AspNet.Security/Notifications/BaseContext`1.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/BaseContext`1.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { /// /// Base class used for certain event contexts diff --git a/src/Microsoft.AspNet.Security/Notifications/BaseNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/BaseNotification.cs similarity index 96% rename from src/Microsoft.AspNet.Security/Notifications/BaseNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/BaseNotification.cs index d1ea6fef75..1563dbb07e 100644 --- a/src/Microsoft.AspNet.Security/Notifications/BaseNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/BaseNotification.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class BaseNotification : BaseContext { diff --git a/src/Microsoft.AspNet.Security/Notifications/EndpointContext.cs b/src/Microsoft.AspNet.Authentication/Notifications/EndpointContext.cs similarity index 90% rename from src/Microsoft.AspNet.Security/Notifications/EndpointContext.cs rename to src/Microsoft.AspNet.Authentication/Notifications/EndpointContext.cs index fd8251e139..1671316d11 100644 --- a/src/Microsoft.AspNet.Security/Notifications/EndpointContext.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/EndpointContext.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public abstract class EndpointContext : BaseContext { diff --git a/src/Microsoft.AspNet.Security/Notifications/EndpointContext`1.cs b/src/Microsoft.AspNet.Authentication/Notifications/EndpointContext`1.cs similarity index 95% rename from src/Microsoft.AspNet.Security/Notifications/EndpointContext`1.cs rename to src/Microsoft.AspNet.Authentication/Notifications/EndpointContext`1.cs index 7b0b415e85..dde3a4fbb4 100644 --- a/src/Microsoft.AspNet.Security/Notifications/EndpointContext`1.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/EndpointContext`1.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { /// /// Base class used for certain event contexts diff --git a/src/Microsoft.AspNet.Security/Notifications/MessageReceivedNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/MessageReceivedNotification.cs similarity index 92% rename from src/Microsoft.AspNet.Security/Notifications/MessageReceivedNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/MessageReceivedNotification.cs index f583746c3c..08f6521c07 100644 --- a/src/Microsoft.AspNet.Security/Notifications/MessageReceivedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/MessageReceivedNotification.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class MessageReceivedNotification : BaseNotification { diff --git a/src/Microsoft.AspNet.Security/Notifications/NotificationResultState.cs b/src/Microsoft.AspNet.Authentication/Notifications/NotificationResultState.cs similarity index 92% rename from src/Microsoft.AspNet.Security/Notifications/NotificationResultState.cs rename to src/Microsoft.AspNet.Authentication/Notifications/NotificationResultState.cs index 78d6c85caa..993aa76186 100644 --- a/src/Microsoft.AspNet.Security/Notifications/NotificationResultState.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/NotificationResultState.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public enum NotificationResultState { diff --git a/src/Microsoft.AspNet.Security/Notifications/RedirectFromIdentityProviderNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/RedirectFromIdentityProviderNotification.cs similarity index 84% rename from src/Microsoft.AspNet.Security/Notifications/RedirectFromIdentityProviderNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/RedirectFromIdentityProviderNotification.cs index 768b384a9d..f883baf7da 100644 --- a/src/Microsoft.AspNet.Security/Notifications/RedirectFromIdentityProviderNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/RedirectFromIdentityProviderNotification.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class RedirectFromIdentityProviderNotification : BaseNotification { @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Security.Notifications { } - public string SignInAsAuthenticationType { get; set; } + public string SignInScheme { get; set; } public bool IsRequestCompleted { get; set; } diff --git a/src/Microsoft.AspNet.Security/Notifications/RedirectToIdentityProviderNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs similarity index 90% rename from src/Microsoft.AspNet.Security/Notifications/RedirectToIdentityProviderNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs index 524664d7ed..1c069b4e22 100644 --- a/src/Microsoft.AspNet.Security/Notifications/RedirectToIdentityProviderNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class RedirectToIdentityProviderNotification : BaseNotification { diff --git a/src/Microsoft.AspNet.Security/Notifications/ReturnEndpointContext.cs b/src/Microsoft.AspNet.Authentication/Notifications/ReturnEndpointContext.cs similarity index 77% rename from src/Microsoft.AspNet.Security/Notifications/ReturnEndpointContext.cs rename to src/Microsoft.AspNet.Authentication/Notifications/ReturnEndpointContext.cs index 6d15d02fa2..344c56cccb 100644 --- a/src/Microsoft.AspNet.Security/Notifications/ReturnEndpointContext.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/ReturnEndpointContext.cs @@ -5,9 +5,9 @@ using System.Diagnostics.CodeAnalysis; using System.Security.Claims; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public abstract class ReturnEndpointContext : EndpointContext { @@ -18,15 +18,15 @@ namespace Microsoft.AspNet.Security.Notifications { if (ticket != null) { - Identity = ticket.Identity; + Principal = ticket.Principal; Properties = ticket.Properties; } } - public ClaimsIdentity Identity { get; set; } + public ClaimsPrincipal Principal { get; set; } public AuthenticationProperties Properties { get; set; } - public string SignInAsAuthenticationType { get; set; } + public string SignInScheme { get; set; } [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "By design")] public string RedirectUri { get; set; } diff --git a/src/Microsoft.AspNet.Security/Notifications/SecurityTokenReceivedNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenReceivedNotification.cs similarity index 91% rename from src/Microsoft.AspNet.Security/Notifications/SecurityTokenReceivedNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenReceivedNotification.cs index 7db29788a2..f7a0424447 100644 --- a/src/Microsoft.AspNet.Security/Notifications/SecurityTokenReceivedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenReceivedNotification.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class SecurityTokenReceivedNotification : BaseNotification { diff --git a/src/Microsoft.AspNet.Security/Notifications/SecurityTokenValidatedNotification.cs b/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenValidatedNotification.cs similarity index 90% rename from src/Microsoft.AspNet.Security/Notifications/SecurityTokenValidatedNotification.cs rename to src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenValidatedNotification.cs index bdef232a71..aad6d7e3a1 100644 --- a/src/Microsoft.AspNet.Security/Notifications/SecurityTokenValidatedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenValidatedNotification.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.Security.Notifications +namespace Microsoft.AspNet.Authentication.Notifications { public class SecurityTokenValidatedNotification : BaseNotification { diff --git a/src/Microsoft.AspNet.Authentication/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Authentication/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..b1dc46b068 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication/Properties/Resources.Designer.cs @@ -0,0 +1,78 @@ +// +namespace Microsoft.AspNet.Authentication +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class Resources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNet.Authentication.Resources", typeof(Resources).GetTypeInfo().Assembly); + + /// + /// The default data protection provider may only be used when the IApplicationBuilder.Properties contains an appropriate 'host.AppName' key. + /// + internal static string Exception_DefaultDpapiRequiresAppNameKey + { + get { return GetString("Exception_DefaultDpapiRequiresAppNameKey"); } + } + + /// + /// The default data protection provider may only be used when the IApplicationBuilder.Properties contains an appropriate 'host.AppName' key. + /// + internal static string FormatException_DefaultDpapiRequiresAppNameKey() + { + return GetString("Exception_DefaultDpapiRequiresAppNameKey"); + } + + /// + /// The state passed to UnhookAuthentication may only be the return value from HookAuthentication. + /// + internal static string Exception_UnhookAuthenticationStateType + { + get { return GetString("Exception_UnhookAuthenticationStateType"); } + } + + /// + /// The state passed to UnhookAuthentication may only be the return value from HookAuthentication. + /// + internal static string FormatException_UnhookAuthenticationStateType() + { + return GetString("Exception_UnhookAuthenticationStateType"); + } + + /// + /// The AuthenticationTokenProvider's required synchronous events have not been registered. + /// + internal static string Exception_AuthenticationTokenDoesNotProvideSyncMethods + { + get { return GetString("Exception_AuthenticationTokenDoesNotProvideSyncMethods"); } + } + + /// + /// The AuthenticationTokenProvider's required synchronous events have not been registered. + /// + internal static string FormatException_AuthenticationTokenDoesNotProvideSyncMethods() + { + return GetString("Exception_AuthenticationTokenDoesNotProvideSyncMethods"); + } + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNet.Authentication/Resources.resx b/src/Microsoft.AspNet.Authentication/Resources.resx new file mode 100644 index 0000000000..77060045e0 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication/Resources.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The default data protection provider may only be used when the IApplicationBuilder.Properties contains an appropriate 'host.AppName' key. + + + The state passed to UnhookAuthentication may only be the return value from HookAuthentication. + + + The AuthenticationTokenProvider's required synchronous events have not been registered. + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication/SecurityHelper.cs b/src/Microsoft.AspNet.Authentication/SecurityHelper.cs new file mode 100644 index 0000000000..1e73888c6a --- /dev/null +++ b/src/Microsoft.AspNet.Authentication/SecurityHelper.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNet.Http; + +namespace Microsoft.AspNet.Authentication +{ + /// + /// Helper code used when implementing authentication middleware + /// + public static class SecurityHelper + { + /// + /// Add all ClaimsIdenities from an additional ClaimPrincipal to the ClaimsPrincipal + /// + /// + public static void AddUserPrincipal([NotNull] HttpContext context, [NotNull] ClaimsPrincipal principal) + { + ClaimsPrincipal existingPrincipal = context.User; + if (existingPrincipal != null) + { + foreach (var existingClaimsIdentity in existingPrincipal.Identities) + { + // REVIEW: No longer use auth type for anything, so we could remove this check, except for the default one HttpContext.user creates + // REVIEW: Need to ignore any identities that did not come from an authentication scheme? + if (existingClaimsIdentity.IsAuthenticated) + { + principal.AddIdentity(existingClaimsIdentity); + } + } + } + context.User = principal; + } + } +} diff --git a/src/Microsoft.AspNet.Security/Infrastructure/SignInIdentityContext.cs b/src/Microsoft.AspNet.Authentication/SignInContext.cs similarity index 53% rename from src/Microsoft.AspNet.Security/Infrastructure/SignInIdentityContext.cs rename to src/Microsoft.AspNet.Authentication/SignInContext.cs index 309e04892a..efe055ba83 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/SignInIdentityContext.cs +++ b/src/Microsoft.AspNet.Authentication/SignInContext.cs @@ -2,19 +2,19 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Security.Claims; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { - public class SignInIdentityContext + public class SignInContext { - public SignInIdentityContext(ClaimsIdentity identity, AuthenticationProperties properties) + public SignInContext(ClaimsPrincipal principal, AuthenticationProperties properties) { - Identity = identity; + Principal = principal; Properties = properties; } - public ClaimsIdentity Identity { get; private set; } + public ClaimsPrincipal Principal { get; private set; } public AuthenticationProperties Properties { get; private set; } } } diff --git a/src/Microsoft.AspNet.Security/SubjectPublicKeyInfoAlgorithm.cs b/src/Microsoft.AspNet.Authentication/SubjectPublicKeyInfoAlgorithm.cs similarity index 94% rename from src/Microsoft.AspNet.Security/SubjectPublicKeyInfoAlgorithm.cs rename to src/Microsoft.AspNet.Authentication/SubjectPublicKeyInfoAlgorithm.cs index aefe5ef766..921abb9533 100644 --- a/src/Microsoft.AspNet.Security/SubjectPublicKeyInfoAlgorithm.cs +++ b/src/Microsoft.AspNet.Authentication/SubjectPublicKeyInfoAlgorithm.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { /// /// The algorithm used to generate the subject public key information blob hashes. diff --git a/src/Microsoft.AspNet.Security/Infrastructure/SystemClock.cs b/src/Microsoft.AspNet.Authentication/SystemClock.cs similarity index 94% rename from src/Microsoft.AspNet.Security/Infrastructure/SystemClock.cs rename to src/Microsoft.AspNet.Authentication/SystemClock.cs index 0c800d3fd5..11c30564f8 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/SystemClock.cs +++ b/src/Microsoft.AspNet.Authentication/SystemClock.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.AspNet.Security.Infrastructure +namespace Microsoft.AspNet.Authentication { /// /// Provides access to the normal system clock. diff --git a/src/Microsoft.AspNet.Security/Win32.cs b/src/Microsoft.AspNet.Authentication/Win32.cs similarity index 100% rename from src/Microsoft.AspNet.Security/Win32.cs rename to src/Microsoft.AspNet.Authentication/Win32.cs diff --git a/src/Microsoft.AspNet.Security/project.json b/src/Microsoft.AspNet.Authentication/project.json similarity index 100% rename from src/Microsoft.AspNet.Security/project.json rename to src/Microsoft.AspNet.Authentication/project.json diff --git a/src/Microsoft.AspNet.Security/AuthorizationContext.cs b/src/Microsoft.AspNet.Authorization/AuthorizationContext.cs similarity index 97% rename from src/Microsoft.AspNet.Security/AuthorizationContext.cs rename to src/Microsoft.AspNet.Authorization/AuthorizationContext.cs index 81d00bdc9d..4044b84f57 100644 --- a/src/Microsoft.AspNet.Security/AuthorizationContext.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizationContext.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { /// /// Contains authorization information used by . diff --git a/src/Microsoft.AspNet.Security/AuthorizationHandler.cs b/src/Microsoft.AspNet.Authorization/AuthorizationHandler.cs similarity index 98% rename from src/Microsoft.AspNet.Security/AuthorizationHandler.cs rename to src/Microsoft.AspNet.Authorization/AuthorizationHandler.cs index e1b27e8633..c05b55b9ce 100644 --- a/src/Microsoft.AspNet.Security/AuthorizationHandler.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizationHandler.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public abstract class AuthorizationHandler : IAuthorizationHandler where TRequirement : IAuthorizationRequirement diff --git a/src/Microsoft.AspNet.Security/AuthorizationOptions.cs b/src/Microsoft.AspNet.Authorization/AuthorizationOptions.cs similarity index 96% rename from src/Microsoft.AspNet.Security/AuthorizationOptions.cs rename to src/Microsoft.AspNet.Authorization/AuthorizationOptions.cs index 8a53e574d2..708ed1abc6 100644 --- a/src/Microsoft.AspNet.Security/AuthorizationOptions.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizationOptions.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class AuthorizationOptions { diff --git a/src/Microsoft.AspNet.Security/AuthorizationPolicy.cs b/src/Microsoft.AspNet.Authorization/AuthorizationPolicy.cs similarity index 87% rename from src/Microsoft.AspNet.Security/AuthorizationPolicy.cs rename to src/Microsoft.AspNet.Authorization/AuthorizationPolicy.cs index 924f9dbd2b..ca9fcc203a 100644 --- a/src/Microsoft.AspNet.Security/AuthorizationPolicy.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizationPolicy.cs @@ -5,18 +5,18 @@ using System; using System.Collections.Generic; using System.Linq; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class AuthorizationPolicy { - public AuthorizationPolicy(IEnumerable requirements, IEnumerable activeAuthenticationTypes) + public AuthorizationPolicy(IEnumerable requirements, IEnumerable activeAuthenticationSchemes) { Requirements = new List(requirements).AsReadOnly(); - ActiveAuthenticationTypes = new List(activeAuthenticationTypes).AsReadOnly(); + ActiveAuthenticationSchemes = new List(activeAuthenticationSchemes).AsReadOnly(); } public IReadOnlyList Requirements { get; private set; } - public IReadOnlyList ActiveAuthenticationTypes { get; private set; } + public IReadOnlyList ActiveAuthenticationSchemes { get; private set; } public static AuthorizationPolicy Combine([NotNull] params AuthorizationPolicy[] policies) { @@ -55,15 +55,15 @@ namespace Microsoft.AspNet.Security var rolesSplit = authorizeAttribute.Roles?.Split(','); if (rolesSplit != null && rolesSplit.Any()) { - policyBuilder.RequiresRole(rolesSplit); + policyBuilder.RequireRole(rolesSplit); requireAnyAuthenticated = false; } - string[] authTypesSplit = authorizeAttribute.ActiveAuthenticationTypes?.Split(','); + string[] authTypesSplit = authorizeAttribute.ActiveAuthenticationSchemes?.Split(','); if (authTypesSplit != null && authTypesSplit.Any()) { foreach (var authType in authTypesSplit) { - policyBuilder.ActiveAuthenticationTypes.Add(authType); + policyBuilder.ActiveAuthenticationSchemes.Add(authType); } } if (requireAnyAuthenticated) diff --git a/src/Microsoft.AspNet.Security/AuthorizationPolicyBuilder.cs b/src/Microsoft.AspNet.Authorization/AuthorizationPolicyBuilder.cs similarity index 60% rename from src/Microsoft.AspNet.Security/AuthorizationPolicyBuilder.cs rename to src/Microsoft.AspNet.Authorization/AuthorizationPolicyBuilder.cs index bf97fbae2c..f2f24746c6 100644 --- a/src/Microsoft.AspNet.Security/AuthorizationPolicyBuilder.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizationPolicyBuilder.cs @@ -5,13 +5,13 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class AuthorizationPolicyBuilder { - public AuthorizationPolicyBuilder(params string[] activeAuthenticationTypes) + public AuthorizationPolicyBuilder(params string[] activeAuthenticationSchemes) { - AddAuthenticationTypes(activeAuthenticationTypes); + AddAuthenticationSchemes(activeAuthenticationSchemes); } public AuthorizationPolicyBuilder(AuthorizationPolicy policy) @@ -20,13 +20,13 @@ namespace Microsoft.AspNet.Security } public IList Requirements { get; set; } = new List(); - public IList ActiveAuthenticationTypes { get; set; } = new List(); + public IList ActiveAuthenticationSchemes { get; set; } = new List(); - public AuthorizationPolicyBuilder AddAuthenticationTypes(params string[] activeAuthTypes) + public AuthorizationPolicyBuilder AddAuthenticationSchemes(params string[] activeAuthTypes) { foreach (var authType in activeAuthTypes) { - ActiveAuthenticationTypes.Add(authType); + ActiveAuthenticationSchemes.Add(authType); } return this; } @@ -42,17 +42,17 @@ namespace Microsoft.AspNet.Security public AuthorizationPolicyBuilder Combine([NotNull] AuthorizationPolicy policy) { - AddAuthenticationTypes(policy.ActiveAuthenticationTypes.ToArray()); + AddAuthenticationSchemes(policy.ActiveAuthenticationSchemes.ToArray()); AddRequirements(policy.Requirements.ToArray()); return this; } - public AuthorizationPolicyBuilder RequiresClaim([NotNull] string claimType, params string[] requiredValues) + public AuthorizationPolicyBuilder RequireClaim([NotNull] string claimType, params string[] requiredValues) { - return RequiresClaim(claimType, (IEnumerable)requiredValues); + return RequireClaim(claimType, (IEnumerable)requiredValues); } - public AuthorizationPolicyBuilder RequiresClaim([NotNull] string claimType, IEnumerable requiredValues) + public AuthorizationPolicyBuilder RequireClaim([NotNull] string claimType, IEnumerable requiredValues) { Requirements.Add(new ClaimsAuthorizationRequirement { @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Security return this; } - public AuthorizationPolicyBuilder RequiresClaim([NotNull] string claimType) + public AuthorizationPolicyBuilder RequireClaim([NotNull] string claimType) { Requirements.Add(new ClaimsAuthorizationRequirement { @@ -72,14 +72,20 @@ namespace Microsoft.AspNet.Security return this; } - public AuthorizationPolicyBuilder RequiresRole([NotNull] params string[] roles) + public AuthorizationPolicyBuilder RequireRole([NotNull] params string[] roles) { - return RequiresRole((IEnumerable)roles); + return RequireRole((IEnumerable)roles); } - public AuthorizationPolicyBuilder RequiresRole([NotNull] IEnumerable roles) + public AuthorizationPolicyBuilder RequireRole([NotNull] IEnumerable roles) { - RequiresClaim(ClaimTypes.Role, roles); + RequireClaim(ClaimTypes.Role, roles); + return this; + } + + public AuthorizationPolicyBuilder RequireUserName([NotNull] string userName) + { + RequireClaim(ClaimTypes.Name, userName); return this; } @@ -91,7 +97,7 @@ namespace Microsoft.AspNet.Security public AuthorizationPolicy Build() { - return new AuthorizationPolicy(Requirements, ActiveAuthenticationTypes.Distinct()); + return new AuthorizationPolicy(Requirements, ActiveAuthenticationSchemes.Distinct()); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security/AuthorizationServiceExtensions.cs b/src/Microsoft.AspNet.Authorization/AuthorizationServiceExtensions.cs similarity index 69% rename from src/Microsoft.AspNet.Security/AuthorizationServiceExtensions.cs rename to src/Microsoft.AspNet.Authorization/AuthorizationServiceExtensions.cs index e3e416c897..595d88077e 100644 --- a/src/Microsoft.AspNet.Security/AuthorizationServiceExtensions.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizationServiceExtensions.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public static class AuthorizationServiceExtensions { @@ -19,11 +19,12 @@ namespace Microsoft.AspNet.Security /// true when the user fulfills the policy, false otherwise. public static Task AuthorizeAsync([NotNull] this IAuthorizationService service, ClaimsPrincipal user, object resource, [NotNull] AuthorizationPolicy policy) { - if (policy.ActiveAuthenticationTypes != null && policy.ActiveAuthenticationTypes.Any() && user != null) - { - // Filter the user to only contain the active authentication types - user = new ClaimsPrincipal(user.Identities.Where(i => policy.ActiveAuthenticationTypes.Contains(i.AuthenticationType))); - } + // TODO RENABLE + //if (policy.ActiveAuthenticationSchemes != null && policy.ActiveAuthenticationSchemes.Any() && user != null) + //{ + // // Filter the user to only contain the active authentication types + // user = new ClaimsPrincipal(user.Identities.Where(i => policy.ActiveAuthenticationSchemes.Contains(i.AuthenticationScheme))); + //} return service.AuthorizeAsync(user, resource, policy.Requirements.ToArray()); } @@ -37,11 +38,12 @@ namespace Microsoft.AspNet.Security /// true when the user fulfills the policy, false otherwise. public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, object resource, [NotNull] AuthorizationPolicy policy) { - if (policy.ActiveAuthenticationTypes != null && policy.ActiveAuthenticationTypes.Any() && user != null) - { - // Filter the user to only contain the active authentication types - user = new ClaimsPrincipal(user.Identities.Where(i => policy.ActiveAuthenticationTypes.Contains(i.AuthenticationType))); - } + // TODO: REeanble + //if (policy.ActiveAuthenticationSchemes != null && policy.ActiveAuthenticationSchemes.Any() && user != null) + //{ + // // Filter the user to only contain the active authentication types + // user = new ClaimsPrincipal(user.Identities.Where(i => policy.ActiveAuthenticationSchemes.Contains(i.AuthenticationScheme))); + //} return service.Authorize(user, resource, policy.Requirements.ToArray()); } diff --git a/src/Microsoft.AspNet.Security/AuthorizeAttribute.cs b/src/Microsoft.AspNet.Authorization/AuthorizeAttribute.cs similarity index 86% rename from src/Microsoft.AspNet.Security/AuthorizeAttribute.cs rename to src/Microsoft.AspNet.Authorization/AuthorizeAttribute.cs index bdaefafbf1..15db20dbfd 100644 --- a/src/Microsoft.AspNet.Security/AuthorizeAttribute.cs +++ b/src/Microsoft.AspNet.Authorization/AuthorizeAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public class AuthorizeAttribute : Attribute @@ -20,6 +20,6 @@ namespace Microsoft.AspNet.Security // REVIEW: can we get rid of the , deliminated in Roles/AuthTypes public string Roles { get; set; } - public string ActiveAuthenticationTypes { get; set; } + public string ActiveAuthenticationSchemes { get; set; } } } diff --git a/src/Microsoft.AspNet.Security/ClaimsAuthorizationHandler.cs b/src/Microsoft.AspNet.Authorization/ClaimsAuthorizationHandler.cs similarity index 96% rename from src/Microsoft.AspNet.Security/ClaimsAuthorizationHandler.cs rename to src/Microsoft.AspNet.Authorization/ClaimsAuthorizationHandler.cs index 9aa95ef606..608b149363 100644 --- a/src/Microsoft.AspNet.Security/ClaimsAuthorizationHandler.cs +++ b/src/Microsoft.AspNet.Authorization/ClaimsAuthorizationHandler.cs @@ -4,7 +4,7 @@ using System; using System.Linq; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class ClaimsAuthorizationHandler : AuthorizationHandler { diff --git a/src/Microsoft.AspNet.Security/ClaimsAuthorizationRequirement.cs b/src/Microsoft.AspNet.Authorization/ClaimsAuthorizationRequirement.cs similarity index 93% rename from src/Microsoft.AspNet.Security/ClaimsAuthorizationRequirement.cs rename to src/Microsoft.AspNet.Authorization/ClaimsAuthorizationRequirement.cs index 8ec5e7c7e1..d13c9ecc95 100644 --- a/src/Microsoft.AspNet.Security/ClaimsAuthorizationRequirement.cs +++ b/src/Microsoft.AspNet.Authorization/ClaimsAuthorizationRequirement.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { // Must contain a claim with the specified name, and at least one of the required values // If AllowedValues is null or empty, that means any claim is valid diff --git a/src/Microsoft.AspNet.Security/ClaimsTransformationOptions.cs b/src/Microsoft.AspNet.Authorization/ClaimsTransformationOptions.cs similarity index 90% rename from src/Microsoft.AspNet.Security/ClaimsTransformationOptions.cs rename to src/Microsoft.AspNet.Authorization/ClaimsTransformationOptions.cs index 4684ad69d0..da3a4a7bda 100644 --- a/src/Microsoft.AspNet.Security/ClaimsTransformationOptions.cs +++ b/src/Microsoft.AspNet.Authorization/ClaimsTransformationOptions.cs @@ -6,7 +6,7 @@ using System; using System.Security.Claims; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class ClaimsTransformationOptions { diff --git a/src/Microsoft.AspNet.Security/DefaultAuthorizationService.cs b/src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs similarity index 98% rename from src/Microsoft.AspNet.Security/DefaultAuthorizationService.cs rename to src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs index 943fbce9fb..d99f778d94 100644 --- a/src/Microsoft.AspNet.Security/DefaultAuthorizationService.cs +++ b/src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs @@ -7,7 +7,7 @@ using System.Security.Claims; using System.Threading.Tasks; using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class DefaultAuthorizationService : IAuthorizationService { diff --git a/src/Microsoft.AspNet.Security/DenyAnonymousAuthorizationHandler.cs b/src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationHandler.cs similarity index 95% rename from src/Microsoft.AspNet.Security/DenyAnonymousAuthorizationHandler.cs rename to src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationHandler.cs index 952ed30b86..4ce5d43ed3 100644 --- a/src/Microsoft.AspNet.Security/DenyAnonymousAuthorizationHandler.cs +++ b/src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationHandler.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class DenyAnonymousAuthorizationHandler : AuthorizationHandler { diff --git a/src/Microsoft.AspNet.Security/DenyAnonymousAuthorizationRequirement.cs b/src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationRequirement.cs similarity index 77% rename from src/Microsoft.AspNet.Security/DenyAnonymousAuthorizationRequirement.cs rename to src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationRequirement.cs index 286d5fd69a..ecbee9b903 100644 --- a/src/Microsoft.AspNet.Security/DenyAnonymousAuthorizationRequirement.cs +++ b/src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationRequirement.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authorization; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class DenyAnonymousAuthorizationRequirement : IAuthorizationRequirement { } } diff --git a/src/Microsoft.AspNet.Security/IAuthorizationHandler.cs b/src/Microsoft.AspNet.Authorization/IAuthorizationHandler.cs similarity index 90% rename from src/Microsoft.AspNet.Security/IAuthorizationHandler.cs rename to src/Microsoft.AspNet.Authorization/IAuthorizationHandler.cs index 82eea9ff2f..bcd0cdc2ba 100644 --- a/src/Microsoft.AspNet.Security/IAuthorizationHandler.cs +++ b/src/Microsoft.AspNet.Authorization/IAuthorizationHandler.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public interface IAuthorizationHandler { diff --git a/src/Microsoft.AspNet.Security/IAuthorizationRequirement.cs b/src/Microsoft.AspNet.Authorization/IAuthorizationRequirement.cs similarity index 85% rename from src/Microsoft.AspNet.Security/IAuthorizationRequirement.cs rename to src/Microsoft.AspNet.Authorization/IAuthorizationRequirement.cs index bd25247df2..5aeef262e9 100644 --- a/src/Microsoft.AspNet.Security/IAuthorizationRequirement.cs +++ b/src/Microsoft.AspNet.Authorization/IAuthorizationRequirement.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public interface IAuthorizationRequirement { diff --git a/src/Microsoft.AspNet.Security/IAuthorizationService.cs b/src/Microsoft.AspNet.Authorization/IAuthorizationService.cs similarity index 98% rename from src/Microsoft.AspNet.Security/IAuthorizationService.cs rename to src/Microsoft.AspNet.Authorization/IAuthorizationService.cs index 317e1ae283..89215c7aaf 100644 --- a/src/Microsoft.AspNet.Security/IAuthorizationService.cs +++ b/src/Microsoft.AspNet.Authorization/IAuthorizationService.cs @@ -4,7 +4,7 @@ using System.Security.Claims; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { /// /// Checks policy based permissions for a user diff --git a/src/Microsoft.AspNet.Authorization/Microsoft.AspNet.Authorization.kproj b/src/Microsoft.AspNet.Authorization/Microsoft.AspNet.Authorization.kproj new file mode 100644 index 0000000000..43b0607698 --- /dev/null +++ b/src/Microsoft.AspNet.Authorization/Microsoft.AspNet.Authorization.kproj @@ -0,0 +1,17 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 6ab3e514-5894-4131-9399-dc7d5284addb + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security/Infrastructure/NotNullAttribute.cs b/src/Microsoft.AspNet.Authorization/NotNullAttribute.cs similarity index 89% rename from src/Microsoft.AspNet.Security/Infrastructure/NotNullAttribute.cs rename to src/Microsoft.AspNet.Authorization/NotNullAttribute.cs index 24f5509452..64ea6d5736 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/NotNullAttribute.cs +++ b/src/Microsoft.AspNet.Authorization/NotNullAttribute.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] internal sealed class NotNullAttribute : Attribute diff --git a/src/Microsoft.AspNet.Security/OperationAuthorizationRequirement.cs b/src/Microsoft.AspNet.Authorization/OperationAuthorizationRequirement.cs similarity index 88% rename from src/Microsoft.AspNet.Security/OperationAuthorizationRequirement.cs rename to src/Microsoft.AspNet.Authorization/OperationAuthorizationRequirement.cs index e7e08d1959..64cd198ebc 100644 --- a/src/Microsoft.AspNet.Security/OperationAuthorizationRequirement.cs +++ b/src/Microsoft.AspNet.Authorization/OperationAuthorizationRequirement.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class OperationAuthorizationRequirement : IAuthorizationRequirement { diff --git a/src/Microsoft.AspNet.Security/PassThroughAuthorizationHandler.cs b/src/Microsoft.AspNet.Authorization/PassThroughAuthorizationHandler.cs similarity index 95% rename from src/Microsoft.AspNet.Security/PassThroughAuthorizationHandler.cs rename to src/Microsoft.AspNet.Authorization/PassThroughAuthorizationHandler.cs index a2173f1e02..3ae506b2dc 100644 --- a/src/Microsoft.AspNet.Security/PassThroughAuthorizationHandler.cs +++ b/src/Microsoft.AspNet.Authorization/PassThroughAuthorizationHandler.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { public class PassThroughAuthorizationHandler : IAuthorizationHandler { diff --git a/src/Microsoft.AspNet.Security/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Authorization/Properties/Resources.Designer.cs similarity index 95% rename from src/Microsoft.AspNet.Security/Properties/Resources.Designer.cs rename to src/Microsoft.AspNet.Authorization/Properties/Resources.Designer.cs index 3490d3ea71..b8ab205960 100644 --- a/src/Microsoft.AspNet.Security/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Authorization/Properties/Resources.Designer.cs @@ -1,5 +1,5 @@ // -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authorization { using System.Globalization; using System.Reflection; @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Security internal static class Resources { private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.AspNet.Security.Resources", typeof(Resources).GetTypeInfo().Assembly); + = new ResourceManager("Microsoft.AspNet.Authorization.Resources", typeof(Resources).GetTypeInfo().Assembly); /// /// The default data protection provider may only be used when the IApplicationBuilder.Properties contains an appropriate 'host.AppName' key. diff --git a/src/Microsoft.AspNet.Security/Resources.resx b/src/Microsoft.AspNet.Authorization/Resources.resx similarity index 100% rename from src/Microsoft.AspNet.Security/Resources.resx rename to src/Microsoft.AspNet.Authorization/Resources.resx diff --git a/src/Microsoft.AspNet.Security/ServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs similarity index 97% rename from src/Microsoft.AspNet.Security/ServiceCollectionExtensions.cs rename to src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs index 2cb0f5aca5..9146c747b9 100644 --- a/src/Microsoft.AspNet.Security/ServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authorization; using Microsoft.Framework.ConfigurationModel; namespace Microsoft.Framework.DependencyInjection diff --git a/src/Microsoft.AspNet.Authorization/project.json b/src/Microsoft.AspNet.Authorization/project.json new file mode 100644 index 0000000000..978885f8e0 --- /dev/null +++ b/src/Microsoft.AspNet.Authorization/project.json @@ -0,0 +1,13 @@ +{ + "version": "1.0.0-*", + "description": "ASP.NET 5 authorization classes.", + "dependencies": { + "Microsoft.AspNet.Http.Interfaces": "1.0.0-*", + "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Framework.OptionsModel": "1.0.0-*" + }, + "frameworks": { + "aspnet50": { }, + "aspnetcore50": { } + } +} diff --git a/src/Microsoft.AspNet.Security.OAuthBearer/NotNullAttribute.cs b/src/Microsoft.AspNet.Security.OAuthBearer/NotNullAttribute.cs deleted file mode 100644 index 29f5827495..0000000000 --- a/src/Microsoft.AspNet.Security.OAuthBearer/NotNullAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.AspNet.Security.OAuthBearer -{ - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] - internal sealed class NotNullAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security.Twitter/NotNullAttribute.cs b/src/Microsoft.AspNet.Security.Twitter/NotNullAttribute.cs deleted file mode 100644 index 0d6e98224d..0000000000 --- a/src/Microsoft.AspNet.Security.Twitter/NotNullAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.AspNet.Security.Twitter -{ - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] - internal sealed class NotNullAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Security/AuthenticationMode.cs b/src/Microsoft.AspNet.Security/AuthenticationMode.cs deleted file mode 100644 index 2b36dc9734..0000000000 --- a/src/Microsoft.AspNet.Security/AuthenticationMode.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -namespace Microsoft.AspNet.Security -{ - /// - /// Controls the behavior of authentication middleware - /// - public enum AuthenticationMode - { - /// - /// In Active mode the authentication middleware will alter the user identity as the request arrives, and - /// will also alter a plain 401 as the response leaves. - /// - Active, - - /// - /// In Passive mode the authentication middleware will only provide user identity when asked, and will only - /// alter 401 responses where the authentication type named in the extra challenge data. - /// - Passive - } -} diff --git a/src/Microsoft.AspNet.Security/AuthenticationOptions.cs b/src/Microsoft.AspNet.Security/AuthenticationOptions.cs deleted file mode 100644 index 411e134819..0000000000 --- a/src/Microsoft.AspNet.Security/AuthenticationOptions.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNet.Http.Security; - -namespace Microsoft.AspNet.Security -{ - /// - /// Base Options for all authentication middleware - /// - public abstract class AuthenticationOptions - { - private string _authenticationType; - - /// - /// The AuthenticationType in the options corresponds to the IIdentity AuthenticationType property. A different - /// value may be assigned in order to use the same authentication middleware type more than once in a pipeline. - /// - public string AuthenticationType - { - get { return _authenticationType; } - set - { - _authenticationType = value; - Description.AuthenticationType = value; - } - } - - /// - /// If Active the authentication middleware alter the request user coming in and - /// alter 401 Unauthorized responses going out. If Passive the authentication middleware will only provide - /// identity and alter responses when explicitly indicated by the AuthenticationType. - /// - public AuthenticationMode AuthenticationMode { get; set; } = AuthenticationMode.Active; - - /// - /// Additional information about the authentication type which is made available to the application. - /// - public AuthenticationDescription Description { get; set; } = new AuthenticationDescription(); - } -} diff --git a/src/Microsoft.AspNet.Security/Infrastructure/SecurityHelper.cs b/src/Microsoft.AspNet.Security/Infrastructure/SecurityHelper.cs deleted file mode 100644 index 876d5342f7..0000000000 --- a/src/Microsoft.AspNet.Security/Infrastructure/SecurityHelper.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Security.Principal; -using Microsoft.AspNet.Http; - -namespace Microsoft.AspNet.Security.Infrastructure -{ - /// - /// Helper code used when implementing authentication middleware - /// - public static class SecurityHelper - { - /// - /// Add an additional ClaimsIdentity to the ClaimsPrincipal - /// - /// - public static void AddUserIdentity([NotNull] HttpContext context, [NotNull] IIdentity identity) - { - var newClaimsPrincipal = new ClaimsPrincipal(identity); - - ClaimsPrincipal existingPrincipal = context.User; - if (existingPrincipal != null) - { - foreach (var existingClaimsIdentity in existingPrincipal.Identities) - { - if (existingClaimsIdentity.IsAuthenticated) - { - newClaimsPrincipal.AddIdentity(existingClaimsIdentity); - } - } - } - context.User = newClaimsPrincipal; - } - - public static bool LookupChallenge(IEnumerable authenticationTypes, string authenticationType, AuthenticationMode authenticationMode) - { - bool challengeHasAuthenticationTypes = authenticationTypes != null && authenticationTypes.Any(); - if (!challengeHasAuthenticationTypes) - { - return authenticationMode == AuthenticationMode.Active; - } - return authenticationTypes.Contains(authenticationType, StringComparer.Ordinal); - } - - /// - /// Find response sign-in details for a specific authentication middleware - /// - /// The authentication type to look for - public static bool LookupSignIn(IEnumerable identities, string authenticationType, out ClaimsIdentity identity) - { - identity = null; - foreach (var claimsIdentity in identities) - { - if (string.Equals(authenticationType, claimsIdentity.AuthenticationType, StringComparison.Ordinal)) - { - identity = claimsIdentity; - return true; - } - } - return false; - } - - /// - /// Find response sign-out details for a specific authentication middleware - /// - /// The authentication type to look for - /// The authentication mode the middleware is running under - public static bool LookupSignOut(IEnumerable authenticationTypes, string authenticationType, AuthenticationMode authenticationMode) - { - bool singOutHasAuthenticationTypes = authenticationTypes != null && authenticationTypes.Any(); - if (!singOutHasAuthenticationTypes) - { - return authenticationMode == AuthenticationMode.Active; - } - return authenticationTypes.Contains(authenticationType, StringComparer.Ordinal); - } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs b/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs new file mode 100644 index 0000000000..6bd62b2b8b --- /dev/null +++ b/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Http.Core; +using Xunit; + +namespace Microsoft.AspNet.Authentication +{ + public class AuthenticationHandlerFacts + { + [Fact] + public void ShouldHandleSchemeAreDeterminedOnlyByMatchingAuthenticationScheme() + { + var handler = new TestHandler("Alpha"); + + bool passiveNoMatch = handler.ShouldHandleScheme(new[] { "Beta", "Gamma" }); + + handler = new TestHandler("Alpha"); + + bool passiveWithMatch = handler.ShouldHandleScheme(new[] { "Beta", "Alpha" }); + + Assert.False(passiveNoMatch); + Assert.True(passiveWithMatch); + } + + [Fact] + public void AutomaticHandlerInAutomaticModeHandlesEmptyChallenges() + { + var handler = new TestAutoHandler("ignored", true); + Assert.True(handler.ShouldHandleScheme(new string[0])); + } + + [Fact] + public void AutomaticHandlerShouldHandleSchemeWhenSchemeMatches() + { + var handler = new TestAutoHandler("Alpha", true); + Assert.True(handler.ShouldHandleScheme(new string[] { "Alpha" })); + } + + [Fact] + public void AutomaticHandlerShouldNotHandleChallengeWhenSchemeDoesNotMatches() + { + var handler = new TestAutoHandler("Dog", true); + Assert.False(handler.ShouldHandleScheme(new string[] { "Alpha" })); + } + + [Fact] + public void AutomaticHandlerShouldNotHandleChallengeWhenSchemesNotEmpty() + { + var handler = new TestAutoHandler(null, true); + Assert.False(handler.ShouldHandleScheme(new string[] { "Alpha" })); + } + + private class TestHandler : AuthenticationHandler + { + public TestHandler(string scheme) + { + Initialize(new TestOptions(), new DefaultHttpContext()); + Options.AuthenticationScheme = scheme; + } + + protected override void ApplyResponseChallenge() + { + throw new NotImplementedException(); + } + + protected override void ApplyResponseGrant() + { + throw new NotImplementedException(); + } + + protected override AuthenticationTicket AuthenticateCore() + { + throw new NotImplementedException(); + } + } + + private class TestOptions : AuthenticationOptions { } + + private class TestAutoOptions : AutomaticAuthenticationOptions { } + + private class TestAutoHandler : AutomaticAuthenticationHandler + { + public TestAutoHandler(string scheme, bool auto) + { + Initialize(new TestAutoOptions(), new DefaultHttpContext()); + Options.AuthenticationScheme = scheme; + Options.AutomaticAuthentication = auto; + } + + protected override void ApplyResponseChallenge() + { + throw new NotImplementedException(); + } + + protected override void ApplyResponseGrant() + { + throw new NotImplementedException(); + } + + protected override AuthenticationTicket AuthenticateCore() + { + throw new NotImplementedException(); + } + } + + } +} diff --git a/test/Microsoft.AspNet.Security.Test/CertificateSubjectKeyIdentifierValidatorTests.cs b/test/Microsoft.AspNet.Authentication.Test/CertificateSubjectKeyIdentifierValidatorTests.cs similarity index 99% rename from test/Microsoft.AspNet.Security.Test/CertificateSubjectKeyIdentifierValidatorTests.cs rename to test/Microsoft.AspNet.Authentication.Test/CertificateSubjectKeyIdentifierValidatorTests.cs index 4771b98308..f52e6f4aee 100644 --- a/test/Microsoft.AspNet.Security.Test/CertificateSubjectKeyIdentifierValidatorTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/CertificateSubjectKeyIdentifierValidatorTests.cs @@ -7,7 +7,7 @@ using System.Security.Cryptography.X509Certificates; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { public class CertificateSubjectKeyIdentifierValidatorTests { diff --git a/test/Microsoft.AspNet.Security.Test/CertificateSubjectPublicKeyInfoValidatorTests.cs b/test/Microsoft.AspNet.Authentication.Test/CertificateSubjectPublicKeyInfoValidatorTests.cs similarity index 99% rename from test/Microsoft.AspNet.Security.Test/CertificateSubjectPublicKeyInfoValidatorTests.cs rename to test/Microsoft.AspNet.Authentication.Test/CertificateSubjectPublicKeyInfoValidatorTests.cs index 28270cd480..13b9a900a0 100644 --- a/test/Microsoft.AspNet.Security.Test/CertificateSubjectPublicKeyInfoValidatorTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/CertificateSubjectPublicKeyInfoValidatorTests.cs @@ -7,7 +7,7 @@ using System.Security.Cryptography.X509Certificates; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { public class CertificateSubjectPublicKeyInfoValidatorTests { diff --git a/test/Microsoft.AspNet.Security.Test/CertificateThumbprintValidatorTests.cs b/test/Microsoft.AspNet.Authentication.Test/CertificateThumbprintValidatorTests.cs similarity index 99% rename from test/Microsoft.AspNet.Security.Test/CertificateThumbprintValidatorTests.cs rename to test/Microsoft.AspNet.Authentication.Test/CertificateThumbprintValidatorTests.cs index 82e4a3a3dc..145e883dc2 100644 --- a/test/Microsoft.AspNet.Security.Test/CertificateThumbprintValidatorTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/CertificateThumbprintValidatorTests.cs @@ -7,7 +7,7 @@ using System.Security.Cryptography.X509Certificates; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { public class CertificateThumbprintValidatorTests { diff --git a/test/Microsoft.AspNet.Security.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs similarity index 83% rename from test/Microsoft.AspNet.Security.Test/Cookies/CookieMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index c66d571b28..c1d5a0c329 100644 --- a/test/Microsoft.AspNet.Security.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -14,13 +14,13 @@ using System.Xml; using System.Xml.Linq; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.Cookies +namespace Microsoft.AspNet.Authentication.Cookies { public class CookieMiddlewareTests { @@ -69,9 +69,23 @@ namespace Microsoft.AspNet.Security.Cookies private Task SignInAsAlice(HttpContext context) { - context.Response.SignIn( - new AuthenticationProperties(), - new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))); + context.Response.SignIn("Cookies", + new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), + new AuthenticationProperties()); + return Task.FromResult(null); + } + + private Task SignInAsWrong(HttpContext context) + { + context.Response.SignIn("Oops", + new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), + new AuthenticationProperties()); + return Task.FromResult(null); + } + + private Task SignOutAsWrong(HttpContext context) + { + context.Response.SignOut("Oops"); return Task.FromResult(null); } @@ -95,6 +109,30 @@ namespace Microsoft.AspNet.Security.Cookies setCookie.ShouldNotContain("; secure"); } + [Fact] + public async Task SignInWrongAuthTypeThrows() + { + TestServer server = CreateServer(options => + { + options.LoginPath = new PathString("/login"); + options.CookieName = "TestCookie"; + }, SignInAsWrong); + + await Assert.ThrowsAsync(async () => await SendAsync(server, "http://example.com/testpath")); + } + + [Fact] + public async Task SignOutWrongAuthTypeThrows() + { + TestServer server = CreateServer(options => + { + options.LoginPath = new PathString("/login"); + options.CookieName = "TestCookie"; + }, SignOutAsWrong); + + await Assert.ThrowsAsync(async () => await SendAsync(server, "http://example.com/testpath")); + } + [Theory] [InlineData(CookieSecureOption.Always, "http://example.com/testpath", true)] [InlineData(CookieSecureOption.Always, "https://example.com/testpath", true)] @@ -226,10 +264,10 @@ namespace Microsoft.AspNet.Security.Cookies }, context => { - context.Response.SignIn( - new AuthenticationProperties() { ExpiresUtc = clock.UtcNow.Add(TimeSpan.FromMinutes(5)) }, - new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))); - return Task.FromResult(null); + context.Response.SignIn("Cookies", + new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), + new AuthenticationProperties() { ExpiresUtc = clock.UtcNow.Add(TimeSpan.FromMinutes(5)) }); + return Task.FromResult(null); }); Transaction transaction1 = await SendAsync(server, "http://example.com/testpath"); @@ -355,7 +393,8 @@ namespace Microsoft.AspNet.Security.Cookies context => { Assert.Equal(new PathString("/base"), context.Request.PathBase); - context.Response.SignIn(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))); + context.Response.SignIn("Cookies", + new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies")))); return Task.FromResult(null); }, new Uri("http://example.com/base")); @@ -364,6 +403,39 @@ namespace Microsoft.AspNet.Security.Cookies Assert.True(transaction1.SetCookie.Contains("path=/base")); } + [Fact] + public async Task CookieTurns401To403IfAuthenticated() + { + var clock = new TestClock(); + TestServer server = CreateServer(options => + { + options.SystemClock = clock; + }, + SignInAsAlice); + + Transaction transaction1 = await SendAsync(server, "http://example.com/testpath"); + + Transaction transaction2 = await SendAsync(server, "http://example.com/unauthorized", transaction1.CookieNameValue); + + transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.Forbidden); + } + + [Fact] + public async Task CookieDoesNothingTo401IfNotAuthenticated() + { + var clock = new TestClock(); + TestServer server = CreateServer(options => + { + options.SystemClock = clock; + }); + + Transaction transaction1 = await SendAsync(server, "http://example.com/testpath"); + + Transaction transaction2 = await SendAsync(server, "http://example.com/unauthorized", transaction1.CookieNameValue); + + transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.Unauthorized); + } + private static string FindClaimValue(Transaction transaction, string claimType) { XElement claim = transaction.ResponseElement.Elements("claim").SingleOrDefault(elt => elt.Attribute("type").Value == claimType); @@ -404,13 +476,19 @@ namespace Microsoft.AspNet.Security.Cookies { res.StatusCode = 401; } + else if (req.Path == new PathString("/unauthorized")) + { + // Simulate Authorization failure + var result = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); + res.Challenge(CookieAuthenticationDefaults.AuthenticationScheme); + } else if (req.Path == new PathString("/protected/CustomRedirect")) { context.Response.Challenge(new AuthenticationProperties() { RedirectUri = "/CustomRedirect" }); } else if (req.Path == new PathString("/me")) { - Describe(res, new AuthenticationResult(context.User.Identity, new AuthenticationProperties(), new AuthenticationDescription())); + Describe(res, new AuthenticationResult(context.User, new AuthenticationProperties(), new AuthenticationDescription())); } else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder)) { @@ -436,9 +514,9 @@ namespace Microsoft.AspNet.Security.Cookies res.StatusCode = 200; res.ContentType = "text/xml"; var xml = new XElement("xml"); - if (result != null && result.Identity != null) + if (result != null && result.Principal != null) { - xml.Add(result.Identity.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value)))); + xml.Add(result.Principal.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value)))); } if (result != null && result.Properties != null) { diff --git a/test/Microsoft.AspNet.Security.Test/Cookies/Infrastructure/CookieChunkingTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs similarity index 99% rename from test/Microsoft.AspNet.Security.Test/Cookies/Infrastructure/CookieChunkingTests.cs rename to test/Microsoft.AspNet.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs index 04bbadf68a..c4014ad77e 100644 --- a/test/Microsoft.AspNet.Security.Test/Cookies/Infrastructure/CookieChunkingTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs @@ -7,7 +7,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core; using Xunit; -namespace Microsoft.AspNet.Security.Cookies.Infrastructure +namespace Microsoft.AspNet.Authentication.Cookies.Infrastructure { public class CookieChunkingTests { diff --git a/test/Microsoft.AspNet.Security.Test/DataHandler/Encoder/Base64UrlTextEncoderTests.cs b/test/Microsoft.AspNet.Authentication.Test/DataHandler/Encoder/Base64UrlTextEncoderTests.cs similarity index 94% rename from test/Microsoft.AspNet.Security.Test/DataHandler/Encoder/Base64UrlTextEncoderTests.cs rename to test/Microsoft.AspNet.Authentication.Test/DataHandler/Encoder/Base64UrlTextEncoderTests.cs index be97f2f12c..8183f38798 100644 --- a/test/Microsoft.AspNet.Security.Test/DataHandler/Encoder/Base64UrlTextEncoderTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/DataHandler/Encoder/Base64UrlTextEncoderTests.cs @@ -4,7 +4,7 @@ using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.DataHandler.Encoder +namespace Microsoft.AspNet.Authentication.DataHandler.Encoder { public class Base64UrlTextEncoderTests { diff --git a/test/Microsoft.AspNet.Security.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs similarity index 94% rename from test/Microsoft.AspNet.Security.Test/Facebook/FacebookMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index 42137b1426..a0a5558e81 100644 --- a/test/Microsoft.AspNet.Security.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -14,7 +14,7 @@ using Microsoft.Framework.DependencyInjection; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.Facebook +namespace Microsoft.AspNet.Authentication.Facebook { public class FacebookMiddlewareTests { @@ -41,11 +41,11 @@ namespace Microsoft.AspNet.Security.Facebook }); services.ConfigureCookieAuthentication(options => { - options.AuthenticationType = "External"; + options.AuthenticationScheme = "External"; }); services.Configure(options => { - options.SignInAsAuthenticationType = "External"; + options.SignInScheme = "External"; }); }); app.UseFacebookAuthentication(); @@ -78,11 +78,11 @@ namespace Microsoft.AspNet.Security.Facebook }); services.ConfigureCookieAuthentication(options => { - options.AuthenticationType = "External"; + options.AuthenticationScheme = "External"; }); services.Configure(options => { - options.SignInAsAuthenticationType = "External"; + options.SignInScheme = "External"; }); }); app.UseFacebookAuthentication(); diff --git a/test/Microsoft.AspNet.Security.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs similarity index 88% rename from test/Microsoft.AspNet.Security.Test/Google/GoogleMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index e019512f7f..13876a0aed 100644 --- a/test/Microsoft.AspNet.Security.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -11,24 +11,22 @@ using System.Text; using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; +using Microsoft.AspNet.Authentication.DataHandler; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.AspNet.Security.DataHandler; +using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; using Newtonsoft.Json; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.Google +namespace Microsoft.AspNet.Authentication.Google { public class GoogleMiddlewareTests { - private const string CookieAuthenticationType = "Cookie"; + private const string CookieAuthenticationScheme = "Cookie"; [Fact] public async Task ChallengeWillTriggerRedirection() @@ -52,25 +50,6 @@ namespace Microsoft.AspNet.Security.Google location.ShouldNotContain("login_hint="); } - [Fact] - public async Task Challenge401WillTriggerRedirection() - { - var server = CreateServer(options => - { - options.ClientId = "Test Id"; - options.ClientSecret = "Test Secret"; - options.AuthenticationMode = AuthenticationMode.Active; - }); - var transaction = await SendAsync(server, "https://example.com/401"); - transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect); - var location = transaction.Response.Headers.Location.ToString(); - location.ShouldContain("https://accounts.google.com/o/oauth2/auth?response_type=code"); - location.ShouldContain("&client_id="); - location.ShouldContain("&redirect_uri="); - location.ShouldContain("&scope="); - location.ShouldContain("&state="); - } - [Fact] public async Task ChallengeWillSetCorrelationCookie() { @@ -84,20 +63,6 @@ namespace Microsoft.AspNet.Security.Google transaction.SetCookie.Single().ShouldContain(".AspNet.Correlation.Google="); } - [Fact] - public async Task Challenge401WillSetCorrelationCookie() - { - var server = CreateServer(options => - { - options.ClientId = "Test Id"; - options.ClientSecret = "Test Secret"; - options.AuthenticationMode = AuthenticationMode.Active; - }); - var transaction = await SendAsync(server, "https://example.com/401"); - Console.WriteLine(transaction.SetCookie); - transaction.SetCookie.Single().ShouldContain(".AspNet.Correlation.Google="); - } - [Fact] public async Task ChallengeWillSetDefaultScope() { @@ -105,7 +70,6 @@ namespace Microsoft.AspNet.Security.Google { options.ClientId = "Test Id"; options.ClientSecret = "Test Secret"; - options.AuthenticationMode = AuthenticationMode.Active; }); var transaction = await SendAsync(server, "https://example.com/challenge"); transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect); @@ -113,21 +77,6 @@ namespace Microsoft.AspNet.Security.Google query.ShouldContain("&scope=" + Uri.EscapeDataString("openid profile email")); } - [Fact] - public async Task Challenge401WillSetDefaultScope() - { - var server = CreateServer(options => - { - options.ClientId = "Test Id"; - options.ClientSecret = "Test Secret"; - options.AuthenticationMode = AuthenticationMode.Active; - }); - var transaction = await SendAsync(server, "https://example.com/401"); - transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect); - var query = transaction.Response.Headers.Location.Query; - query.ShouldContain("&scope=" + Uri.EscapeDataString("openid profile email")); - } - [Fact] public async Task ChallengeWillUseOptionsScope() { @@ -400,7 +349,7 @@ namespace Microsoft.AspNet.Security.Google OnAuthenticated = context => { var refreshToken = context.RefreshToken; - context.Identity.AddClaim(new Claim("RefreshToken", refreshToken)); + context.Principal.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim("RefreshToken", refreshToken) }, "Google")); return Task.FromResult(null); } }; @@ -470,10 +419,10 @@ namespace Microsoft.AspNet.Security.Google services.AddDataProtection(); services.Configure(options => { - options.SignInAsAuthenticationType = CookieAuthenticationType; + options.SignInScheme = CookieAuthenticationScheme; }); }); - app.UseCookieAuthentication(options => options.AuthenticationType = CookieAuthenticationType); + app.UseCookieAuthentication(options => options.AuthenticationScheme = CookieAuthenticationScheme); app.UseGoogleAuthentication(configureOptions); app.Use(async (context, next) => { @@ -486,7 +435,7 @@ namespace Microsoft.AspNet.Security.Google } else if (req.Path == new PathString("/me")) { - Describe(res, (ClaimsIdentity)context.User.Identity); + Describe(res, context.User); } else if (req.Path == new PathString("/401")) { @@ -504,14 +453,17 @@ namespace Microsoft.AspNet.Security.Google }); } - private static void Describe(HttpResponse res, ClaimsIdentity identity) + private static void Describe(HttpResponse res, ClaimsPrincipal user) { res.StatusCode = 200; res.ContentType = "text/xml"; var xml = new XElement("xml"); - if (identity != null) + if (user != null) { - xml.Add(identity.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value)))); + foreach (var identity in user.Identities) + { + xml.Add(identity.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value)))); + } } using (var memory = new MemoryStream()) { diff --git a/test/Microsoft.AspNet.Security.Test/Microsoft.AspNet.Security.Tests.kproj b/test/Microsoft.AspNet.Authentication.Test/Microsoft.AspNet.Authentication.Tests.kproj similarity index 100% rename from test/Microsoft.AspNet.Security.Test/Microsoft.AspNet.Security.Tests.kproj rename to test/Microsoft.AspNet.Authentication.Test/Microsoft.AspNet.Authentication.Tests.kproj diff --git a/test/Microsoft.AspNet.Security.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs similarity index 92% rename from test/Microsoft.AspNet.Security.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index 0f3a9355c2..e7a8fccd3b 100644 --- a/test/Microsoft.AspNet.Security.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -11,21 +11,19 @@ using System.Text; using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; +using Microsoft.AspNet.Authentication.DataHandler; +using Microsoft.AspNet.Authentication.MicrosoftAccount; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.MicrosoftAccount; +using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; using Newtonsoft.Json; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.Tests.MicrosoftAccount +namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount { public class MicrosoftAccountMiddlewareTests { @@ -128,14 +126,14 @@ namespace Microsoft.AspNet.Security.Tests.MicrosoftAccount OnAuthenticated = context => { var refreshToken = context.RefreshToken; - context.Identity.AddClaim(new Claim("RefreshToken", refreshToken)); + context.Principal.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim("RefreshToken", refreshToken) })); return Task.FromResult(null); } }; }, context => { - Describe(context.Response, (ClaimsIdentity)context.User.Identity); + Describe(context.Response, context.User); return true; }); var properties = new AuthenticationProperties(); @@ -168,10 +166,10 @@ namespace Microsoft.AspNet.Security.Tests.MicrosoftAccount services.AddDataProtection(); services.Configure(options => { - options.SignInAsAuthenticationType = "External"; + options.SignInScheme = "External"; }); }); - app.UseCookieAuthentication(options => options.AuthenticationType = "External"); + app.UseCookieAuthentication(options => options.AuthenticationScheme = "External"); app.UseMicrosoftAccountAuthentication(configureOptions); app.Use(async (context, next) => { @@ -218,14 +216,17 @@ namespace Microsoft.AspNet.Security.Tests.MicrosoftAccount return res; } - private static void Describe(HttpResponse res, ClaimsIdentity identity) + private static void Describe(HttpResponse res, ClaimsPrincipal principal) { res.StatusCode = 200; res.ContentType = "text/xml"; var xml = new XElement("xml"); - if (identity != null) + if (principal != null) { - xml.Add(identity.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value)))); + foreach (var identity in principal.Identities) + { + xml.Add(identity.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value)))); + } } using (var memory = new MemoryStream()) { diff --git a/test/Microsoft.AspNet.Security.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs similarity index 82% rename from test/Microsoft.AspNet.Security.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs index 26f202e08e..ffbc1a0a4b 100644 --- a/test/Microsoft.AspNet.Security.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs @@ -12,13 +12,13 @@ using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; +using Microsoft.AspNet.Authentication.Notifications; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.OAuthBearer +namespace Microsoft.AspNet.Authentication.OAuthBearer { public class OAuthBearerMiddlewareTests { @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob"), }; - notification.AuthenticationTicket = new AuthenticationTicket(new ClaimsIdentity(claims, notification.Options.AuthenticationType), new Http.Security.AuthenticationProperties()); + notification.AuthenticationTicket = new AuthenticationTicket(new ClaimsPrincipal(new ClaimsIdentity(claims)), new Http.Authentication.AuthenticationProperties(), notification.Options.AuthenticationScheme); notification.HandleResponse(); return Task.FromResult(null); @@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob"), }; - notification.AuthenticationTicket = new AuthenticationTicket(new ClaimsIdentity(claims, notification.Options.AuthenticationType), new Http.Security.AuthenticationProperties()); + notification.AuthenticationTicket = new AuthenticationTicket(new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), new Http.Authentication.AuthenticationProperties(), notification.Options.AuthenticationScheme); notification.HandleResponse(); return Task.FromResult(null); @@ -115,7 +115,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer var server = CreateServer(options => { options.Notifications.SecurityTokenValidated = SecurityTokenValidated; - options.SecurityTokenValidators = new List{new BlobTokenValidator(options.AuthenticationType)}; + options.SecurityTokenValidators = new List{new BlobTokenValidator(options.AuthenticationScheme)}; }); var response = await SendAsync(server, "http://example.com/oauth", "Bearer someblob"); @@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob"), }; - notification.AuthenticationTicket = new AuthenticationTicket(new ClaimsIdentity(claims, notification.Options.AuthenticationType), new Http.Security.AuthenticationProperties()); + notification.AuthenticationTicket = new AuthenticationTicket(new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), new Http.Authentication.AuthenticationProperties(), notification.Options.AuthenticationScheme); notification.HandleResponse(); return Task.FromResult(null); @@ -154,15 +154,40 @@ namespace Microsoft.AspNet.Security.OAuthBearer return Task.FromResult(null); } + [Fact] + public async Task BearerTurns401To403IfAuthenticated() + { + var server = CreateServer(options => + { + options.Notifications.SecurityTokenReceived = SecurityTokenReceived; + }); + + var response = await SendAsync(server, "http://example.com/unauthorized", "Bearer Token"); + response.Response.StatusCode.ShouldBe(HttpStatusCode.Forbidden); + } + + + [Fact] + public async Task BearerDoesNothingTo401IfNotAuthenticated() + { + var server = CreateServer(options => + { + options.Notifications.SecurityTokenReceived = SecurityTokenReceived; + }); + + var response = await SendAsync(server, "http://example.com/unauthorized"); + response.Response.StatusCode.ShouldBe(HttpStatusCode.Unauthorized); + } + class BlobTokenValidator : ISecurityTokenValidator { - public BlobTokenValidator(string authenticationType) + public BlobTokenValidator(string authenticationScheme) { - AuthenticationType = authenticationType; + AuthenticationScheme = authenticationScheme; } - public string AuthenticationType { get; set; } + public string AuthenticationScheme { get; set; } public bool CanValidateToken { @@ -200,7 +225,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob"), }; - return new ClaimsPrincipal(new ClaimsIdentity(claims, AuthenticationType)); + return new ClaimsPrincipal(new ClaimsIdentity(claims, AuthenticationScheme)); } } @@ -224,6 +249,12 @@ namespace Microsoft.AspNet.Security.OAuthBearer if (req.Path == new PathString("/oauth")) { } + else if (req.Path == new PathString("/unauthorized")) + { + // Simulate Authorization failure + var result = await context.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme); + res.Challenge(OAuthBearerAuthenticationDefaults.AuthenticationScheme); + } else { await next(); diff --git a/test/Microsoft.AspNet.Security.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs similarity index 94% rename from test/Microsoft.AspNet.Security.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index d2d22a342c..725c2a0735 100644 --- a/test/Microsoft.AspNet.Security.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -16,17 +16,17 @@ using System.Xml.Linq; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.AspNet.Security.DataHandler; -using Microsoft.AspNet.Security.OpenIdConnect; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication.Cookies; +using Microsoft.AspNet.Authentication.DataHandler; +using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using Newtonsoft.Json; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.Tests.OpenIdConnect +namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { public class OpenIdConnectMiddlewareTests { @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Security.Tests.OpenIdConnect { options.Authority = "https://login.windows.net/common"; options.ClientId = "Test Id"; - options.SignInAsAuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType; + options.SignInScheme = OpenIdConnectAuthenticationDefaults.AuthenticationScheme; }); var transaction = await SendAsync(server, "https://example.com/challenge"); transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect); @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Security.Tests.OpenIdConnect { options.Authority = "https://login.windows.net/common"; options.ClientId = "Test Id"; - options.SignInAsAuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType; + options.SignInScheme = OpenIdConnectAuthenticationDefaults.AuthenticationScheme; options.Scope = "https://www.googleapis.com/auth/plus.login"; options.ResponseType = "id_token"; }); @@ -185,13 +185,13 @@ namespace Microsoft.AspNet.Security.Tests.OpenIdConnect services.AddDataProtection(); services.Configure(options => { - options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType; + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); }); app.UseCookieAuthentication(options => { - options.AuthenticationType = "OpenIdConnect"; + options.AuthenticationScheme = "OpenIdConnect"; }); app.UseOpenIdConnectAuthentication(configureOptions); app.Use(async (context, next) => @@ -205,11 +205,12 @@ namespace Microsoft.AspNet.Security.Tests.OpenIdConnect } else if (req.Path == new PathString("/signin")) { - res.SignIn(); + // REVIEW: this used to just be res.SignIn() + res.SignIn("OpenIdConnect", new ClaimsPrincipal()); } else if (req.Path == new PathString("/signout")) { - res.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType); + res.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationScheme); } else if (handler != null) { diff --git a/test/Microsoft.AspNet.Authentication.Test/SecurityHelperTests.cs b/test/Microsoft.AspNet.Authentication.Test/SecurityHelperTests.cs new file mode 100644 index 0000000000..3d75bd0a12 --- /dev/null +++ b/test/Microsoft.AspNet.Authentication.Test/SecurityHelperTests.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Security.Principal; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Core; +using Microsoft.AspNet.Authentication; +using Shouldly; +using Xunit; + +namespace Microsoft.AspNet.Authentication +{ + public class SecurityHelperTests + { + [Fact] + public void AddingToAnonymousIdentityDoesNotKeepAnonymousIdentity() + { + HttpContext context = new DefaultHttpContext(); + context.User.ShouldNotBe(null); + context.User.Identity.IsAuthenticated.ShouldBe(false); + + SecurityHelper.AddUserPrincipal(context, new GenericPrincipal(new GenericIdentity("Test1", "Alpha"), new string[0])); + + context.User.ShouldNotBe(null); + context.User.Identity.AuthenticationType.ShouldBe("Alpha"); + context.User.Identity.Name.ShouldBe("Test1"); + + context.User.ShouldBeTypeOf(); + context.User.Identity.ShouldBeTypeOf(); + + ((ClaimsPrincipal)context.User).Identities.Count().ShouldBe(1); + } + + [Fact] + public void AddingExistingIdentityChangesDefaultButPreservesPrior() + { + HttpContext context = new DefaultHttpContext(); + context.User = new GenericPrincipal(new GenericIdentity("Test1", "Alpha"), null); + + context.User.Identity.AuthenticationType.ShouldBe("Alpha"); + context.User.Identity.Name.ShouldBe("Test1"); + + SecurityHelper.AddUserPrincipal(context, new GenericPrincipal(new GenericIdentity("Test2", "Beta"), new string[0])); + + context.User.Identity.AuthenticationType.ShouldBe("Beta"); + context.User.Identity.Name.ShouldBe("Test2"); + + SecurityHelper.AddUserPrincipal(context, new GenericPrincipal(new GenericIdentity("Test3", "Gamma"), new string[0])); + + context.User.Identity.AuthenticationType.ShouldBe("Gamma"); + context.User.Identity.Name.ShouldBe("Test3"); + + var principal = context.User; + principal.Identities.Count().ShouldBe(3); + principal.Identities.Skip(0).First().Name.ShouldBe("Test3"); + principal.Identities.Skip(1).First().Name.ShouldBe("Test2"); + principal.Identities.Skip(2).First().Name.ShouldBe("Test1"); + } + } +} diff --git a/test/Microsoft.AspNet.Security.Test/TestClock.cs b/test/Microsoft.AspNet.Authentication.Test/TestClock.cs similarity index 86% rename from test/Microsoft.AspNet.Security.Test/TestClock.cs rename to test/Microsoft.AspNet.Authentication.Test/TestClock.cs index cd8f998397..1b7dd1be85 100644 --- a/test/Microsoft.AspNet.Security.Test/TestClock.cs +++ b/test/Microsoft.AspNet.Authentication.Test/TestClock.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Security.Infrastructure; +using Microsoft.AspNet.Authentication; -namespace Microsoft.AspNet.Security +namespace Microsoft.AspNet.Authentication { public class TestClock : ISystemClock { diff --git a/test/Microsoft.AspNet.Security.Test/Twitter/TwitterMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs similarity index 96% rename from test/Microsoft.AspNet.Security.Test/Twitter/TwitterMiddlewareTests.cs rename to test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs index cb98aef0ce..6b54b6cd94 100644 --- a/test/Microsoft.AspNet.Security.Test/Twitter/TwitterMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs @@ -10,8 +10,8 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Cookies; -using Microsoft.AspNet.Security.Twitter; +using Microsoft.AspNet.Authentication.Cookies; +using Microsoft.AspNet.Authentication.Twitter; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; @@ -19,7 +19,7 @@ using Newtonsoft.Json; using Shouldly; using Xunit; -namespace Microsoft.AspNet.Security.Twitter +namespace Microsoft.AspNet.Authentication.Twitter { public class TwitterMiddlewareTests { @@ -115,12 +115,12 @@ namespace Microsoft.AspNet.Security.Twitter services.AddDataProtection(); services.Configure(options => { - options.SignInAsAuthenticationType = "External"; + options.SignInScheme = "External"; }); }); app.UseCookieAuthentication(options => { - options.AuthenticationType = "External"; + options.AuthenticationScheme = "External"; }); if (configure != null) { diff --git a/test/Microsoft.AspNet.Security.Test/katanatest.redmond.corp.microsoft.com.cer b/test/Microsoft.AspNet.Authentication.Test/katanatest.redmond.corp.microsoft.com.cer similarity index 100% rename from test/Microsoft.AspNet.Security.Test/katanatest.redmond.corp.microsoft.com.cer rename to test/Microsoft.AspNet.Authentication.Test/katanatest.redmond.corp.microsoft.com.cer diff --git a/test/Microsoft.AspNet.Authentication.Test/project.json b/test/Microsoft.AspNet.Authentication.Test/project.json new file mode 100644 index 0000000000..7d2a50c88e --- /dev/null +++ b/test/Microsoft.AspNet.Authentication.Test/project.json @@ -0,0 +1,27 @@ +{ + "compilationOptions": { + "warningsAsErrors": true + }, + "dependencies": { + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", + "Microsoft.AspNet.Authentication.Facebook": "1.0.0-*", + "Microsoft.AspNet.Authentication.Google": "1.0.0-*", + "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*", + "Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-*", + "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*", + "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", + "Microsoft.AspNet.TestHost": "1.0.0-*", + "Moq": "4.2.1312.1622", + "xunit.runner.kre": "1.0.0-*" + }, + "commands": { + "test": "xunit.runner.kre" + }, + "frameworks": { + "aspnet50": { + "dependencies": { + "Shouldly": "1.1.1.1" + } + } + } +} diff --git a/test/Microsoft.AspNet.Security.Test/selfSigned.cer b/test/Microsoft.AspNet.Authentication.Test/selfSigned.cer similarity index 100% rename from test/Microsoft.AspNet.Security.Test/selfSigned.cer rename to test/Microsoft.AspNet.Authentication.Test/selfSigned.cer diff --git a/test/Microsoft.AspNet.Security.Test/AuthorizationPolicyFacts.cs b/test/Microsoft.AspNet.Authorization.Test/AuthorizationPolicyFacts.cs similarity index 67% rename from test/Microsoft.AspNet.Security.Test/AuthorizationPolicyFacts.cs rename to test/Microsoft.AspNet.Authorization.Test/AuthorizationPolicyFacts.cs index 57c71dde40..eae8502ae5 100644 --- a/test/Microsoft.AspNet.Security.Test/AuthorizationPolicyFacts.cs +++ b/test/Microsoft.AspNet.Authorization.Test/AuthorizationPolicyFacts.cs @@ -2,9 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; +using Microsoft.AspNet.Authorization; using Xunit; -namespace Microsoft.AspNet.Security.Test +namespace Microsoft.AspNet.Authroization.Test { public class AuthorizationPolicyFacts { @@ -14,21 +15,21 @@ namespace Microsoft.AspNet.Security.Test // Arrange var attributes = new AuthorizeAttribute[] { new AuthorizeAttribute(), - new AuthorizeAttribute("1") { ActiveAuthenticationTypes = "dupe" }, - new AuthorizeAttribute("2") { ActiveAuthenticationTypes = "dupe" }, - new AuthorizeAttribute { Roles = "r1,r2", ActiveAuthenticationTypes = "roles" }, + new AuthorizeAttribute("1") { ActiveAuthenticationSchemes = "dupe" }, + new AuthorizeAttribute("2") { ActiveAuthenticationSchemes = "dupe" }, + new AuthorizeAttribute { Roles = "r1,r2", ActiveAuthenticationSchemes = "roles" }, }; var options = new AuthorizationOptions(); - options.AddPolicy("1", policy => policy.RequiresClaim("1")); - options.AddPolicy("2", policy => policy.RequiresClaim("2")); + options.AddPolicy("1", policy => policy.RequireClaim("1")); + options.AddPolicy("2", policy => policy.RequireClaim("2")); // Act var combined = AuthorizationPolicy.Combine(options, attributes); // Assert - Assert.Equal(2, combined.ActiveAuthenticationTypes.Count()); - Assert.True(combined.ActiveAuthenticationTypes.Contains("dupe")); - Assert.True(combined.ActiveAuthenticationTypes.Contains("roles")); + Assert.Equal(2, combined.ActiveAuthenticationSchemes.Count()); + Assert.True(combined.ActiveAuthenticationSchemes.Contains("dupe")); + Assert.True(combined.ActiveAuthenticationSchemes.Contains("roles")); Assert.Equal(4, combined.Requirements.Count()); Assert.True(combined.Requirements.Any(r => r is DenyAnonymousAuthorizationRequirement)); Assert.Equal(3, combined.Requirements.OfType().Count()); diff --git a/test/Microsoft.AspNet.Security.Test/DefaultAuthorizationServiceTests.cs b/test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs similarity index 89% rename from test/Microsoft.AspNet.Security.Test/DefaultAuthorizationServiceTests.cs rename to test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs index 9beae1c6d6..54a4e1a7c8 100644 --- a/test/Microsoft.AspNet.Security.Test/DefaultAuthorizationServiceTests.cs +++ b/test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs @@ -10,7 +10,7 @@ using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Xunit; -namespace Microsoft.AspNet.Security.Test +namespace Microsoft.AspNet.Authorization.Test { public class DefaultAuthorizationServiceTests { @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("Permission", "CanViewPage") }, "Basic")); @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("Permission", "CanViewPage") }, "Basic")); @@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage", "CanViewAnything")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage", "CanViewAnything")); }); }); var user = new ClaimsPrincipal( @@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage", "CanViewAnything")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage", "CanViewAnything")); }); }); var user = new ClaimsPrincipal( @@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage", "CanViewAnything")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage", "CanViewAnything")); }); }); var user = new ClaimsPrincipal( @@ -160,7 +160,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); var user = new ClaimsPrincipal( @@ -186,7 +186,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); var user = new ClaimsPrincipal( @@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); @@ -229,7 +229,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); var user = new ClaimsPrincipal(new ClaimsIdentity()); @@ -249,7 +249,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresClaim("Permission", "CanViewPage")); + options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); }); var user = new ClaimsPrincipal( @@ -291,8 +291,8 @@ namespace Microsoft.AspNet.Security.Test public async Task Authorize_CustomRolePolicy() { // Arrange - var policy = new AuthorizationPolicyBuilder().RequiresRole("Administrator") - .RequiresClaim(ClaimTypes.Role, "User"); + var policy = new AuthorizationPolicyBuilder().RequireRole("Administrator") + .RequireClaim(ClaimTypes.Role, "User"); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity( @@ -314,7 +314,7 @@ namespace Microsoft.AspNet.Security.Test public async Task Authorize_HasAnyClaimOfTypePolicy() { // Arrange - var policy = new AuthorizationPolicyBuilder().RequiresClaim(ClaimTypes.Role); + var policy = new AuthorizationPolicyBuilder().RequireClaim(ClaimTypes.Role); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity( @@ -332,10 +332,10 @@ namespace Microsoft.AspNet.Security.Test } [Fact] - public async Task Authorize_PolicyCanAuthenticationTypeWithNameClaim() + public async Task Authorize_PolicyCanAuthenticationSchemeWithNameClaim() { // Arrange - var policy = new AuthorizationPolicyBuilder("AuthType").RequiresClaim(ClaimTypes.Name); + var policy = new AuthorizationPolicyBuilder("AuthType").RequireClaim(ClaimTypes.Name); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "Name") }, "AuthType") @@ -348,11 +348,11 @@ namespace Microsoft.AspNet.Security.Test Assert.True(allowed); } - [Fact] - public async Task Authorize_PolicyWillFilterAuthenticationType() + [Fact(Skip = "Filtering TBD")] + public async Task Authorize_PolicyWillFilterAuthenticationScheme() { // Arrange - var policy = new AuthorizationPolicyBuilder("Bogus").RequiresClaim(ClaimTypes.Name); + var policy = new AuthorizationPolicyBuilder("Bogus").RequireClaim(ClaimTypes.Name); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "Name") }, "AuthType") @@ -365,11 +365,11 @@ namespace Microsoft.AspNet.Security.Test Assert.False(allowed); } - [Fact] - public async Task Authorize_PolicyCanFilterMultipleAuthenticationType() + [Fact(Skip = "Filtering TBD")] + public async Task Authorize_PolicyCanFilterMultipleAuthenticationScheme() { // Arrange - var policy = new AuthorizationPolicyBuilder("One", "Two").RequiresClaim(ClaimTypes.Name, "one").RequiresClaim(ClaimTypes.Name, "two"); + var policy = new AuthorizationPolicyBuilder("One", "Two").RequireClaim(ClaimTypes.Name, "one").RequireClaim(ClaimTypes.Name, "two"); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal(); user.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "one") }, "One")); @@ -386,7 +386,7 @@ namespace Microsoft.AspNet.Security.Test public async Task RolePolicyCanRequireSingleRole() { // Arrange - var policy = new AuthorizationPolicyBuilder("AuthType").RequiresRole("Admin"); + var policy = new AuthorizationPolicyBuilder("AuthType").RequireRole("Admin"); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "Admin") }, "AuthType") @@ -403,7 +403,7 @@ namespace Microsoft.AspNet.Security.Test public async Task RolePolicyCanRequireOneOfManyRoles() { // Arrange - var policy = new AuthorizationPolicyBuilder("AuthType").RequiresRole("Admin", "Users"); + var policy = new AuthorizationPolicyBuilder("AuthType").RequireRole("Admin", "Users"); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "Users") }, "AuthType")); @@ -419,7 +419,7 @@ namespace Microsoft.AspNet.Security.Test public async Task RolePolicyCanBlockWrongRole() { // Arrange - var policy = new AuthorizationPolicyBuilder().RequiresClaim("Permission", "CanViewPage"); + var policy = new AuthorizationPolicyBuilder().RequireClaim("Permission", "CanViewPage"); var authorizationService = BuildAuthorizationService(); var user = new ClaimsPrincipal( new ClaimsIdentity( @@ -444,7 +444,7 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - options.AddPolicy("Basic", policy => policy.RequiresRole("Admin", "Users")); + options.AddPolicy("Basic", policy => policy.RequireRole("Admin", "Users")); }); }); var user = new ClaimsPrincipal( @@ -487,6 +487,58 @@ namespace Microsoft.AspNet.Security.Test Assert.False(allowed); } + [Fact] + public async Task RequireUserNameFailsForWrongUserName() + { + // Arrange + var authorizationService = BuildAuthorizationService(services => + { + services.ConfigureAuthorization(options => + { + options.AddPolicy("Hao", policy => policy.RequireUserName("Hao")); + }); + }); + var user = new ClaimsPrincipal( + new ClaimsIdentity( + new Claim[] { + new Claim(ClaimTypes.Name, "Tek"), + }, + "AuthType") + ); + + // Act + var allowed = await authorizationService.AuthorizeAsync(user, null, "Any"); + + // Assert + Assert.False(allowed); + } + + [Fact] + public async Task CanRequireUserName() + { + // Arrange + var authorizationService = BuildAuthorizationService(services => + { + services.ConfigureAuthorization(options => + { + options.AddPolicy("Hao", policy => policy.RequireUserName("Hao")); + }); + }); + var user = new ClaimsPrincipal( + new ClaimsIdentity( + new Claim[] { + new Claim(ClaimTypes.Name, "Hao"), + }, + "AuthType") + ); + + // Act + var allowed = await authorizationService.AuthorizeAsync(user, null, "Hao"); + + // Assert + Assert.True(allowed); + } + [Fact] public async Task CanApproveAnyAuthenticatedUser() { @@ -629,8 +681,8 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - var basePolicy = new AuthorizationPolicyBuilder().RequiresClaim("Base", "Value").Build(); - options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequiresClaim("Claim", "Exists")); + var basePolicy = new AuthorizationPolicyBuilder().RequireClaim("Base", "Value").Build(); + options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequireClaim("Claim", "Exists")); }); }); var user = new ClaimsPrincipal( @@ -656,8 +708,8 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - var basePolicy = new AuthorizationPolicyBuilder().RequiresClaim("Base", "Value").Build(); - options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequiresClaim("Claim", "Exists")); + var basePolicy = new AuthorizationPolicyBuilder().RequireClaim("Base", "Value").Build(); + options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequireClaim("Claim", "Exists")); }); }); var user = new ClaimsPrincipal( @@ -682,8 +734,8 @@ namespace Microsoft.AspNet.Security.Test { services.ConfigureAuthorization(options => { - var basePolicy = new AuthorizationPolicyBuilder().RequiresClaim("Base", "Value").Build(); - options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequiresClaim("Claim", "Exists")); + var basePolicy = new AuthorizationPolicyBuilder().RequireClaim("Base", "Value").Build(); + options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequireClaim("Claim", "Exists")); }); }); var user = new ClaimsPrincipal( diff --git a/test/Microsoft.AspNet.Authorization.Test/Microsoft.AspNet.Authorization.Tests.kproj b/test/Microsoft.AspNet.Authorization.Test/Microsoft.AspNet.Authorization.Tests.kproj new file mode 100644 index 0000000000..316cc51775 --- /dev/null +++ b/test/Microsoft.AspNet.Authorization.Test/Microsoft.AspNet.Authorization.Tests.kproj @@ -0,0 +1,17 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 7af5ad96-eb6e-4d0e-8abe-c0b543c0f4c2 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Authorization.Test/project.json b/test/Microsoft.AspNet.Authorization.Test/project.json new file mode 100644 index 0000000000..68f39fe36e --- /dev/null +++ b/test/Microsoft.AspNet.Authorization.Test/project.json @@ -0,0 +1,20 @@ +{ + "compilationOptions": { + "warningsAsErrors": true + }, + "dependencies": { + "Microsoft.AspNet.Authorization": "1.0.0-*", + "Moq": "4.2.1312.1622", + "xunit.runner.kre": "1.0.0-*" + }, + "commands": { + "test": "xunit.runner.kre" + }, + "frameworks": { + "aspnet50": { + "dependencies": { + "Shouldly": "1.1.1.1" + } + } + } +} diff --git a/test/Microsoft.AspNet.Security.Test/SecurityHelperTests.cs b/test/Microsoft.AspNet.Security.Test/SecurityHelperTests.cs deleted file mode 100644 index dae0aed318..0000000000 --- a/test/Microsoft.AspNet.Security.Test/SecurityHelperTests.cs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Security.Principal; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.Security.Infrastructure; -using Shouldly; -using Xunit; - -namespace Microsoft.AspNet.Security -{ - public class SecurityHelperTests - { - [Fact] - public void AddingToAnonymousIdentityDoesNotKeepAnonymousIdentity() - { - HttpContext context = new DefaultHttpContext(); - context.User.ShouldNotBe(null); - context.User.Identity.IsAuthenticated.ShouldBe(false); - - SecurityHelper.AddUserIdentity(context, new GenericIdentity("Test1", "Alpha")); - - context.User.ShouldNotBe(null); - context.User.Identity.AuthenticationType.ShouldBe("Alpha"); - context.User.Identity.Name.ShouldBe("Test1"); - - context.User.ShouldBeTypeOf(); - context.User.Identity.ShouldBeTypeOf(); - - ((ClaimsPrincipal)context.User).Identities.Count().ShouldBe(1); - } - - [Fact] - public void AddingExistingIdentityChangesDefaultButPreservesPrior() - { - HttpContext context = new DefaultHttpContext(); - context.User = new GenericPrincipal(new GenericIdentity("Test1", "Alpha"), null); - - context.User.Identity.AuthenticationType.ShouldBe("Alpha"); - context.User.Identity.Name.ShouldBe("Test1"); - - SecurityHelper.AddUserIdentity(context, new GenericIdentity("Test2", "Beta")); - - context.User.Identity.AuthenticationType.ShouldBe("Beta"); - context.User.Identity.Name.ShouldBe("Test2"); - - SecurityHelper.AddUserIdentity(context, new GenericIdentity("Test3", "Gamma")); - - context.User.Identity.AuthenticationType.ShouldBe("Gamma"); - context.User.Identity.Name.ShouldBe("Test3"); - - var principal = context.User; - principal.Identities.Count().ShouldBe(3); - principal.Identities.Skip(0).First().Name.ShouldBe("Test3"); - principal.Identities.Skip(1).First().Name.ShouldBe("Test2"); - principal.Identities.Skip(2).First().Name.ShouldBe("Test1"); - } - - [Fact] - public void NoChallengesMeansLookupsAreDeterminedOnlyByActiveOrPassiveMode() - { - HttpContext context = new DefaultHttpContext(); - - bool activeNoChallenge = SecurityHelper.LookupChallenge(new string[0], "Alpha", AuthenticationMode.Active); - bool passiveNoChallenge = SecurityHelper.LookupChallenge(new string[0], "Alpha", AuthenticationMode.Passive); - - context.Response.StatusCode = 401; - - bool activeEmptyChallenge = SecurityHelper.LookupChallenge(new string[0], "Alpha", AuthenticationMode.Active); - bool passiveEmptyChallenge = SecurityHelper.LookupChallenge(new string[0], "Alpha", AuthenticationMode.Passive); - - Assert.True(activeNoChallenge); - Assert.False(passiveNoChallenge); - Assert.True(activeEmptyChallenge); - Assert.False(passiveEmptyChallenge); - } - - [Fact] - public void WithChallengesMeansLookupsAreDeterminedOnlyByMatchingAuthenticationType() - { - HttpContext context = new DefaultHttpContext(); - - IEnumerable challengeTypes = new[] { "Beta", "Gamma" }; - - bool activeNoMatch = SecurityHelper.LookupChallenge(challengeTypes, "Alpha", AuthenticationMode.Active); - bool passiveNoMatch = SecurityHelper.LookupChallenge(challengeTypes, "Alpha", AuthenticationMode.Passive); - - challengeTypes = new[] { "Beta", "Alpha" }; - - bool activeWithMatch = SecurityHelper.LookupChallenge(challengeTypes, "Alpha", AuthenticationMode.Active); - bool passiveWithMatch = SecurityHelper.LookupChallenge(challengeTypes, "Alpha", AuthenticationMode.Passive); - - Assert.False(activeNoMatch); - Assert.False(passiveNoMatch); - Assert.True(activeWithMatch); - Assert.True(passiveWithMatch); - } - } -} diff --git a/test/Microsoft.AspNet.Security.Test/project.json b/test/Microsoft.AspNet.Security.Test/project.json deleted file mode 100644 index 1ab85d5840..0000000000 --- a/test/Microsoft.AspNet.Security.Test/project.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilationOptions": { - "warningsAsErrors": true - }, - "dependencies": { - "Microsoft.AspNet.Security.Cookies": "1.0.0-*", - "Microsoft.AspNet.Security.Facebook": "1.0.0-*", - "Microsoft.AspNet.Security.Google": "1.0.0-*", - "Microsoft.AspNet.Security.MicrosoftAccount": "1.0.0-*", - "Microsoft.AspNet.Security.OAuthBearer": "1.0.0-*", - "Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-*", - "Microsoft.AspNet.Security.Twitter": "1.0.0-*", - "Microsoft.AspNet.TestHost": "1.0.0-*", - "Moq": "4.2.1312.1622", - "xunit.runner.kre": "1.0.0-*" - }, - "commands": { - "test": "xunit.runner.kre" - }, - "frameworks": { - "aspnet50": { - "dependencies": { - "Shouldly": "1.1.1.1" - } - } - } -}