diff --git a/src/MusicStore.Spa/Controllers/AccountController.cs b/src/MusicStore.Spa/Controllers/AccountController.cs index 5a024281c8..51d5881092 100644 --- a/src/MusicStore.Spa/Controllers/AccountController.cs +++ b/src/MusicStore.Spa/Controllers/AccountController.cs @@ -142,7 +142,7 @@ namespace MusicStore.Controllers private async Task GetCurrentUserAsync() { - return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId()); + return await UserManager.FindByIdAsync(Context.User.GetUserId()); } public enum ManageMessageId diff --git a/src/MusicStore.Spa/Views/Account/_ChangePasswordPartial.cshtml b/src/MusicStore.Spa/Views/Account/_ChangePasswordPartial.cshtml index d6c3c25b19..5594b781e8 100644 --- a/src/MusicStore.Spa/Views/Account/_ChangePasswordPartial.cshtml +++ b/src/MusicStore.Spa/Views/Account/_ChangePasswordPartial.cshtml @@ -2,7 +2,7 @@ @model MusicStore.Models.ManageUserViewModel -

You're logged in as @User.Identity.GetUserName().

+

You're logged in as @User.GetUserName().

@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", diff --git a/src/MusicStore.Spa/Views/Shared/_LoginPartial.cshtml b/src/MusicStore.Spa/Views/Shared/_LoginPartial.cshtml index 3dc4612ff4..a25dfd3ee1 100644 --- a/src/MusicStore.Spa/Views/Shared/_LoginPartial.cshtml +++ b/src/MusicStore.Spa/Views/Shared/_LoginPartial.cshtml @@ -14,15 +14,15 @@ @Html.Json(new { isAuthenticated = true, - userName = User.Identity.GetUserName(), - userId = User.Identity.GetUserId(), + userName = User.GetUserName(), + userId = User.GetUserId(), roles = ((ClaimsPrincipal)User).Claims .Where(c => c.Type == ClaimTypes.Role) .Select(role => role.Value), diff --git a/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs b/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs index 6f56f8abb1..0fac2e888f 100644 --- a/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs +++ b/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs @@ -14,7 +14,7 @@ using MusicStore.ViewModels; namespace MusicStore.Areas.Admin.Controllers { [Area("Admin")] - [Microsoft.AspNet.Security.Authorize("ManageStore")] + [Microsoft.AspNet.Authorization.Authorize("ManageStore")] public class StoreManagerController : Controller { private IConnectionManager _connectionManager; diff --git a/src/MusicStore/Controllers/AccountController.cs b/src/MusicStore/Controllers/AccountController.cs index a9a847a2b4..2ce65e0e9f 100644 --- a/src/MusicStore/Controllers/AccountController.cs +++ b/src/MusicStore/Controllers/AccountController.cs @@ -2,11 +2,11 @@ using System.Security.Claims; using System.Security.Principal; using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Security; using Microsoft.Framework.DependencyInjection; using MusicStore.Models; @@ -371,7 +371,7 @@ namespace MusicStore.Controllers ViewBag.ReturnUrl = returnUrl; ViewBag.LoginProvider = loginInfo.LoginProvider; // REVIEW: handle case where email not in claims? - var email = loginInfo.ExternalIdentity.FindFirstValue(ClaimTypes.Email); + var email = loginInfo.ExternalPrincipal.FindFirstValue(ClaimTypes.Email); return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = email }); } } @@ -383,7 +383,7 @@ namespace MusicStore.Controllers [ValidateAntiForgeryToken] public async Task ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null) { - if (User.Identity.IsAuthenticated) + if (User.IsSignedIn()) { return RedirectToAction("Index", "Manage"); } @@ -401,7 +401,7 @@ namespace MusicStore.Controllers #if TESTING //Just for automated testing adding a claim named 'ManageStore' - Not required for production - var manageClaim = info.ExternalIdentity.Claims.Where(c => c.Type == "ManageStore").FirstOrDefault(); + var manageClaim = info.ExternalPrincipal.Claims.Where(c => c.Type == "ManageStore").FirstOrDefault(); if (manageClaim != null) { await UserManager.AddClaimAsync(user, manageClaim); @@ -463,7 +463,7 @@ namespace MusicStore.Controllers private async Task GetCurrentUserAsync() { - return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId()); + return await UserManager.FindByIdAsync(Context.User.GetUserId()); } private ActionResult RedirectToLocal(string returnUrl) diff --git a/src/MusicStore/Controllers/CheckoutController.cs b/src/MusicStore/Controllers/CheckoutController.cs index 9e547fe1e2..738389029f 100644 --- a/src/MusicStore/Controllers/CheckoutController.cs +++ b/src/MusicStore/Controllers/CheckoutController.cs @@ -4,7 +4,7 @@ using System.Security.Principal; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authorization; using MusicStore.Models; namespace MusicStore.Controllers @@ -42,7 +42,7 @@ namespace MusicStore.Controllers } else { - order.Username = Context.User.Identity.GetUserName(); + order.Username = Context.User.GetUserName(); order.OrderDate = DateTime.Now; //Add the Order @@ -73,7 +73,7 @@ namespace MusicStore.Controllers // Validate customer owns this order bool isValid = await DbContext.Orders.AnyAsync( o => o.OrderId == id && - o.Username == Context.User.Identity.GetUserName()); + o.Username == Context.User.GetUserName()); if (isValid) { diff --git a/src/MusicStore/Controllers/ManageController.cs b/src/MusicStore/Controllers/ManageController.cs index bce669c2d0..4f153fdfff 100644 --- a/src/MusicStore/Controllers/ManageController.cs +++ b/src/MusicStore/Controllers/ManageController.cs @@ -1,9 +1,9 @@ using System.Linq; using System.Security.Principal; using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Security; using MusicStore.Models; namespace MusicStore.Controllers @@ -287,7 +287,7 @@ namespace MusicStore.Controllers return View("Error"); } var userLogins = await UserManager.GetLoginsAsync(user); - var otherLogins = SignInManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList(); + var otherLogins = SignInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList(); ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1; return View(new ManageLoginsViewModel { @@ -304,7 +304,7 @@ namespace MusicStore.Controllers { // Request a redirect to the external login provider to link a login for the current user var redirectUrl = Url.Action("LinkLoginCallback", "Manage"); - var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.Identity.GetUserId()); + var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.GetUserId()); return new ChallengeResult(provider, properties); } @@ -318,7 +318,7 @@ namespace MusicStore.Controllers return View("Error"); } - var loginInfo = await SignInManager.GetExternalLoginInfoAsync(User.Identity.GetUserId()); + var loginInfo = await SignInManager.GetExternalLoginInfoAsync(User.GetUserId()); if (loginInfo == null) { return RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }); @@ -353,7 +353,7 @@ namespace MusicStore.Controllers private async Task GetCurrentUserAsync() { - return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId()); + return await UserManager.FindByIdAsync(Context.User.GetUserId()); } #endregion diff --git a/src/MusicStore/Models/ManageViewModels.cs b/src/MusicStore/Models/ManageViewModels.cs index 426d8a47e1..f7252f21d1 100644 --- a/src/MusicStore/Models/ManageViewModels.cs +++ b/src/MusicStore/Models/ManageViewModels.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using Microsoft.AspNet.Http.Security; +using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Mvc.Rendering; diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 960de96e8e..67e472b14b 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -3,13 +3,14 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authentication; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.Logging.Console; using MusicStore.Models; +using Microsoft.AspNet.Authorization; namespace MusicStore { @@ -93,7 +94,7 @@ namespace MusicStore // Configure Auth services.Configure(options => { - options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build()); + options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); } diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index 55760e1f82..d07492d50d 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -4,7 +4,7 @@ using System.Security.Principal; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Server.WebListener; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; @@ -13,6 +13,7 @@ using Microsoft.Framework.Logging; using Microsoft.Framework.Logging.Console; using Microsoft.Net.Http.Server; using MusicStore.Models; +using Microsoft.AspNet.Authorization; namespace MusicStore { @@ -65,7 +66,7 @@ namespace MusicStore // Configure Auth services.Configure(options => { - options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build()); + options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); } @@ -84,7 +85,7 @@ namespace MusicStore if ((app.Server as ServerInformation) != null) { var serverInformation = (ServerInformation)app.Server; - serverInformation.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationTypes.NTLM; + serverInformation.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.NTLM; } app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll); @@ -99,7 +100,7 @@ namespace MusicStore //Who will get admin access? For demo sake I'm listing the currently logged on user as the application administrator. But this can be changed to suit the needs. var identity = (ClaimsIdentity)context.User.Identity; - if (identity.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" + Environment.GetEnvironmentVariable("USERNAME")) + if (context.User.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" + Environment.GetEnvironmentVariable("USERNAME")) { identity.AddClaim(new Claim("ManageStore", "Allowed")); } diff --git a/src/MusicStore/StartupOpenIdConnect.cs b/src/MusicStore/StartupOpenIdConnect.cs index 2955fefad5..33f91bc6ab 100644 --- a/src/MusicStore/StartupOpenIdConnect.cs +++ b/src/MusicStore/StartupOpenIdConnect.cs @@ -3,13 +3,14 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authentication; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.Logging.Console; using MusicStore.Models; +using Microsoft.AspNet.Authorization; namespace MusicStore { @@ -81,7 +82,7 @@ namespace MusicStore // Configure Auth services.Configure(options => { - options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build()); + options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); } diff --git a/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml b/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml index 543c5a6aac..6daeb0dd76 100644 --- a/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml +++ b/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml @@ -6,7 +6,7 @@

Use another service to log in.


@{ - var loginProviders = SignInManager.GetExternalAuthenticationTypes(); + var loginProviders = SignInManager.GetExternalAuthenticationSchemes(); if (loginProviders.Count() == 0) {
@@ -25,7 +25,7 @@

@foreach (AuthenticationDescription p in loginProviders.Where(a => a.Caption != null)) { - + }

diff --git a/src/MusicStore/Views/Shared/_LoginPartial.cshtml b/src/MusicStore/Views/Shared/_LoginPartial.cshtml index fbf9acb6dc..b539905a3b 100644 --- a/src/MusicStore/Views/Shared/_LoginPartial.cshtml +++ b/src/MusicStore/Views/Shared/_LoginPartial.cshtml @@ -1,6 +1,6 @@ @using System.Security.Principal -@if (User.Identity.IsAuthenticated) +@if (User.IsSignedIn()) { //Either NTLM will be used or social authentication will be used. Based on the authentication schemes enabled remove an unused block. if (User.Identity.AuthenticationType != "NTLM") @@ -11,7 +11,7 @@ @@ -22,7 +22,7 @@ //This code block necessary only for NTLM authentication } diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index 67b75cd4c9..c352cbe9b8 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -15,16 +15,16 @@ "EntityFramework.SqlServer": "7.0.0-*", "EntityFramework.InMemory": "7.0.0-*", // For Mono. "Kestrel": "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.OpenIdConnect": "1.0.0-*", + "Microsoft.AspNet.Authentication.Twitter": "1.0.0-*", "Microsoft.AspNet.Diagnostics": "1.0.0-*", "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*", "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*", "Microsoft.AspNet.Mvc": "6.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.OpenIdConnect": "1.0.0-*", - "Microsoft.AspNet.Security.Twitter": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Session": "1.0.0-*", diff --git a/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs b/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs index e0f6ea586e..f14dddb22e 100644 --- a/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs +++ b/test/E2ETests/compiler/shared/Mocks/Common/CustomStateDataFormat.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNet.Http.Security; -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Authentication; using Newtonsoft.Json; namespace MusicStore.Mocks.Common diff --git a/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs b/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs index f2158ac349..e1f7be98c2 100644 --- a/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/Facebook/FacebookNotifications.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security.Facebook; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.Facebook; +using Microsoft.AspNet.Authentication.OAuth; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.Facebook @@ -16,7 +16,7 @@ namespace MusicStore.Mocks.Facebook { internal static async Task OnAuthenticated(FacebookAuthenticatedContext context) { - if (context.Identity != null) + if (context.Principal != null) { Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", ""); Helpers.ThrowIfConditionFailed(() => context.Email == "AspnetvnextTest@test.com", ""); @@ -27,7 +27,7 @@ namespace MusicStore.Mocks.Facebook Helpers.ThrowIfConditionFailed(() => context.User.SelectToken("id").ToString() == context.Id, ""); Helpers.ThrowIfConditionFailed(() => context.ExpiresIn.Value == TimeSpan.FromSeconds(100), ""); Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", ""); - context.Identity.AddClaim(new Claim("ManageStore", "false")); + context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false")); } await Task.FromResult(0); @@ -35,14 +35,15 @@ namespace MusicStore.Mocks.Facebook internal static async Task OnReturnEndpoint(OAuthReturnEndpointContext context) { - if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType) + if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme) { //This way we will know all notifications were fired. - var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); + var identity = context.Principal.Identities.First(); + var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); if (manageStoreClaim != null) { - context.Identity.RemoveClaim(manageStoreClaim); - context.Identity.AddClaim(new Claim("ManageStore", "Allowed")); + identity.RemoveClaim(manageStoreClaim); + identity.AddClaim(new Claim("ManageStore", "Allowed")); } } diff --git a/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs b/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs index 348885e7af..7d79280572 100644 --- a/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/Google/GoogleNotifications.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security.Google; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.Google; +using Microsoft.AspNet.Authentication.OAuth; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.Google @@ -16,7 +16,7 @@ namespace MusicStore.Mocks.Google { internal static async Task OnAuthenticated(GoogleAuthenticatedContext context) { - if (context.Identity != null) + if (context.Principal != null) { Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", "Access token is not valid"); Helpers.ThrowIfConditionFailed(() => context.RefreshToken == "ValidRefreshToken", "Refresh token is not valid"); @@ -26,7 +26,7 @@ namespace MusicStore.Mocks.Google Helpers.ThrowIfConditionFailed(() => context.Name == "AspnetvnextTest AspnetvnextTest", "Name is not valid"); Helpers.ThrowIfConditionFailed(() => context.ExpiresIn.Value == TimeSpan.FromSeconds(1200), "ExpiresIn is not valid"); Helpers.ThrowIfConditionFailed(() => context.User != null, "User object is not valid"); - context.Identity.AddClaim(new Claim("ManageStore", "false")); + context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false")); } await Task.FromResult(0); @@ -34,14 +34,15 @@ namespace MusicStore.Mocks.Google internal static async Task OnReturnEndpoint(OAuthReturnEndpointContext context) { - if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType) + if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme) { //This way we will know all notifications were fired. - var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); + var identity = context.Principal.Identities.First(); + var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); if (manageStoreClaim != null) { - context.Identity.RemoveClaim(manageStoreClaim); - context.Identity.AddClaim(new Claim("ManageStore", "Allowed")); + identity.RemoveClaim(manageStoreClaim); + identity.AddClaim(new Claim("ManageStore", "Allowed")); } } diff --git a/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs b/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs index d6178b97e9..686d90e18c 100644 --- a/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/MicrosoftAccount/MicrosoftAccountNotifications.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security.MicrosoftAccount; -using Microsoft.AspNet.Security.OAuth; +using Microsoft.AspNet.Authentication.MicrosoftAccount; +using Microsoft.AspNet.Authentication.OAuth; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.MicrosoftAccount @@ -16,7 +16,7 @@ namespace MusicStore.Mocks.MicrosoftAccount { internal static async Task OnAuthenticated(MicrosoftAccountAuthenticatedContext context) { - if (context.Identity != null) + if (context.Principal != null) { Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", "Access token is not valid"); Helpers.ThrowIfConditionFailed(() => context.RefreshToken == "ValidRefreshToken", "Refresh token is not valid"); @@ -27,7 +27,7 @@ namespace MusicStore.Mocks.MicrosoftAccount Helpers.ThrowIfConditionFailed(() => context.ExpiresIn.Value == TimeSpan.FromSeconds(3600), "ExpiresIn is not valid"); Helpers.ThrowIfConditionFailed(() => context.User != null, "User object is not valid"); Helpers.ThrowIfConditionFailed(() => context.Id == context.User.SelectToken("id").ToString(), "User id is not valid"); - context.Identity.AddClaim(new Claim("ManageStore", "false")); + context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false")); } await Task.FromResult(0); @@ -35,14 +35,15 @@ namespace MusicStore.Mocks.MicrosoftAccount internal static async Task OnReturnEndpoint(OAuthReturnEndpointContext context) { - if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType) + if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme) { //This way we will know all notifications were fired. - var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); + var identity = context.Principal.Identities.First(); + var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); if (manageStoreClaim != null) { - context.Identity.RemoveClaim(manageStoreClaim); - context.Identity.AddClaim(new Claim("ManageStore", "Allowed")); + identity.RemoveClaim(manageStoreClaim); + identity.AddClaim(new Claim("ManageStore", "Allowed")); } } diff --git a/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/CustomStringDataFormat.cs b/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/CustomStringDataFormat.cs index 44c2a14e95..2883a51f71 100644 --- a/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/CustomStringDataFormat.cs +++ b/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/CustomStringDataFormat.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNet.Security; +using Microsoft.AspNet.Authentication; namespace MusicStore.Mocks.OpenIdConnect { diff --git a/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs b/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs index f29c0db73e..c63419943b 100644 --- a/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.AspNet.Authentication.Notifications; +using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Security.Notifications; -using Microsoft.AspNet.Security.OpenIdConnect; using Microsoft.IdentityModel.Protocols; using MusicStore.Mocks.Common; diff --git a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs index 7b5106ff05..2944dbb7eb 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs @@ -1,10 +1,10 @@ using System; +using Microsoft.AspNet.Authentication.OpenIdConnect; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security; -using Microsoft.AspNet.Security.OpenIdConnect; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; @@ -71,7 +71,7 @@ namespace MusicStore // Configure Auth services.Configure(options => { - options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build()); + options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); } diff --git a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs index eaf0708a7a..8306b76402 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs @@ -1,16 +1,16 @@ using System; using System.IO; using System.Threading.Tasks; +using Microsoft.AspNet.Authentication.Facebook; +using Microsoft.AspNet.Authentication.Google; +using Microsoft.AspNet.Authentication.MicrosoftAccount; +using Microsoft.AspNet.Authentication.Twitter; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Http; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security; -using Microsoft.AspNet.Security.Facebook; -using Microsoft.AspNet.Security.Google; -using Microsoft.AspNet.Security.MicrosoftAccount; -using Microsoft.AspNet.Security.Twitter; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; @@ -107,7 +107,7 @@ namespace MusicStore // Configure Auth services.Configure(options => { - options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build()); + options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); }); } diff --git a/test/E2ETests/compiler/shared/Mocks/Twitter/CustomTwitterStateDataFormat.cs b/test/E2ETests/compiler/shared/Mocks/Twitter/CustomTwitterStateDataFormat.cs index 9d0ef8faed..3500c676c1 100644 --- a/test/E2ETests/compiler/shared/Mocks/Twitter/CustomTwitterStateDataFormat.cs +++ b/test/E2ETests/compiler/shared/Mocks/Twitter/CustomTwitterStateDataFormat.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNet.Security; -using Microsoft.AspNet.Security.Twitter.Messages; +using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Authentication.Twitter.Messages; using Newtonsoft.Json; namespace MusicStore.Mocks.Twitter diff --git a/test/E2ETests/compiler/shared/Mocks/Twitter/TwitterNotifications.cs b/test/E2ETests/compiler/shared/Mocks/Twitter/TwitterNotifications.cs index 7f88927b89..6deb764a35 100644 --- a/test/E2ETests/compiler/shared/Mocks/Twitter/TwitterNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/Twitter/TwitterNotifications.cs @@ -1,8 +1,8 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.AspNet.Authentication.Twitter; using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Security.Twitter; using MusicStore.Mocks.Common; namespace MusicStore.Mocks.Twitter @@ -14,13 +14,13 @@ namespace MusicStore.Mocks.Twitter { internal static async Task OnAuthenticated(TwitterAuthenticatedContext context) { - if (context.Identity != null) + if (context.Principal != null) { Helpers.ThrowIfConditionFailed(() => context.UserId == "valid_user_id", "UserId is not valid"); Helpers.ThrowIfConditionFailed(() => context.ScreenName == "valid_screen_name", "ScreenName is not valid"); Helpers.ThrowIfConditionFailed(() => context.AccessToken == "valid_oauth_token", "AccessToken is not valid"); Helpers.ThrowIfConditionFailed(() => context.AccessTokenSecret == "valid_oauth_token_secret", "AccessTokenSecret is not valid"); - context.Identity.AddClaim(new Claim("ManageStore", "false")); + context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false")); } await Task.FromResult(0); @@ -28,14 +28,15 @@ namespace MusicStore.Mocks.Twitter internal static async Task OnReturnEndpoint(TwitterReturnEndpointContext context) { - if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType) + if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme) { //This way we will know all notifications were fired. - var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); + var identity = context.Principal.Identities.First(); + var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault(); if (manageStoreClaim != null) { - context.Identity.RemoveClaim(manageStoreClaim); - context.Identity.AddClaim(new Claim("ManageStore", "Allowed")); + identity.RemoveClaim(manageStoreClaim); + identity.AddClaim(new Claim("ManageStore", "Allowed")); } }