diff --git a/samples/CookieSample/Startup.cs b/samples/CookieSample/Startup.cs index 3f09191900..6547450e51 100644 --- a/samples/CookieSample/Startup.cs +++ b/samples/CookieSample/Startup.cs @@ -28,7 +28,7 @@ namespace CookieSample if (string.IsNullOrEmpty(context.User.Identity.Name)) { var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") })); - context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user); + context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello First timer"); return; diff --git a/samples/CookieSessionSample/Startup.cs b/samples/CookieSessionSample/Startup.cs index 0f962caeda..f0b1b5219b 100644 --- a/samples/CookieSessionSample/Startup.cs +++ b/samples/CookieSessionSample/Startup.cs @@ -36,7 +36,7 @@ namespace CookieSessionSample { claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe")); } - context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims))); + context.Authentication.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/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index 7c1969d3bc..2077d802bb 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -40,7 +40,7 @@ namespace OpenIdConnectSample { if (string.IsNullOrEmpty(context.User.Identity.Name)) { - context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme); + context.Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" }); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello First timer"); diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index 4bfc7b6594..f552ceea3c 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -188,14 +188,14 @@ namespace CookieSample { // By default the client will be redirect back to the URL that issued the challenge (/login?authtype=foo), // send them to the home page instead (/). - context.Response.Challenge(new AuthenticationProperties() { RedirectUri = "/" }, authType); + context.Authentication.Challenge(authType, new AuthenticationProperties() { RedirectUri = "/" }); return; } context.Response.ContentType = "text/html"; await context.Response.WriteAsync(""); await context.Response.WriteAsync("Choose an authentication scheme:
"); - foreach (var type in context.GetAuthenticationSchemes()) + foreach (var type in context.Authentication.GetAuthenticationSchemes()) { await context.Response.WriteAsync("" + (type.Caption ?? "(suppressed)") + "
"); } @@ -208,7 +208,7 @@ namespace CookieSample { signoutApp.Run(async context => { - context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationScheme); + context.Authentication.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 + "
"); @@ -223,7 +223,7 @@ namespace CookieSample if (string.IsNullOrEmpty(context.User.Identity.Name)) { // The cookie middleware will intercept this 401 and redirect to /login - context.Response.Challenge(); + context.Authentication.Challenge(); return; } await next(); diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs index 27b0d2c4e0..5e1acbcb16 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs @@ -157,23 +157,23 @@ namespace Microsoft.AspNet.Authentication.Cookies Options, Options.AuthenticationScheme, signin.Principal, - signin.Properties, + new AuthenticationProperties(signin.Properties), cookieOptions); DateTimeOffset issuedUtc; - if (signin.Properties.IssuedUtc.HasValue) + if (signInContext.Properties.IssuedUtc.HasValue) { - issuedUtc = signin.Properties.IssuedUtc.Value; + issuedUtc = signInContext.Properties.IssuedUtc.Value; } else { issuedUtc = Options.SystemClock.UtcNow; - signin.Properties.IssuedUtc = issuedUtc; + signInContext.Properties.IssuedUtc = issuedUtc; } - if (!signin.Properties.ExpiresUtc.HasValue) + if (!signInContext.Properties.ExpiresUtc.HasValue) { - signin.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan); + signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan); } Options.Notifications.ResponseSignIn(signInContext); @@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Authentication.Cookies Context, Options, cookieOptions); - + Options.Notifications.ResponseSignOut(context); Options.CookieManager.DeleteCookie( diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs index 175c38c207..c30e70526f 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs @@ -102,14 +102,14 @@ namespace Microsoft.AspNet.Authentication.Google string name, string defaultValue = null) { string value; - if (!properties.Dictionary.TryGetValue(name, out value)) + if (!properties.Items.TryGetValue(name, out value)) { value = defaultValue; } else { // Remove the parameter from AuthenticationProperties so it won't be serialized to state parameter - properties.Dictionary.Remove(name); + properties.Items.Remove(name); } if (value == null) diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs index 5d3cb8c60d..21c684a68d 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Authentication.OAuth if (context.SignInScheme != null && context.Principal != null) { - Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties); + Context.Authentication.SignIn(context.SignInScheme, context.Principal, context.Properties); } if (!context.IsRequestCompleted && context.RedirectUri != null) diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs index 25af5a4a0c..3ea2a4578d 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs @@ -161,7 +161,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect // When redeeming a 'code' for an AccessToken, this value is needed if (!string.IsNullOrWhiteSpace(Options.RedirectUri)) { - properties.Dictionary.Add(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey, Options.RedirectUri); + properties.Items.Add(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey, Options.RedirectUri); } if (_configuration == null && Options.ConfigurationManager != null) @@ -385,12 +385,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme); if (!string.IsNullOrWhiteSpace(message.SessionState)) { - ticket.Properties.Dictionary[OpenIdConnectSessionProperties.SessionState] = message.SessionState; + ticket.Properties.Items[OpenIdConnectSessionProperties.SessionState] = message.SessionState; } if (_configuration != null && !string.IsNullOrWhiteSpace(_configuration.CheckSessionIframe)) { - ticket.Properties.Dictionary[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe; + ticket.Properties.Items[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe; } // Rename? @@ -466,8 +466,8 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect Code = message.Code, JwtSecurityToken = jwt, ProtocolMessage = message, - RedirectUri = ticket.Properties.Dictionary.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey) ? - ticket.Properties.Dictionary[OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey] : string.Empty, + RedirectUri = ticket.Properties.Items.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey) ? + ticket.Properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey] : string.Empty, }; await Options.Notifications.AuthorizationCodeReceived(authorizationCodeReceivedNotification); @@ -632,7 +632,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect { if (ticket.Principal != null) { - Request.HttpContext.Response.SignIn(Options.SignInScheme, ticket.Principal, ticket.Properties); + Request.HttpContext.Authentication.SignIn(Options.SignInScheme, ticket.Principal, ticket.Properties); } // Redirect back to the original secured resource, if any. diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs index 6df6fc1a80..e487f76982 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs @@ -208,7 +208,7 @@ namespace Microsoft.AspNet.Authentication.Twitter if (context.SignInScheme != null && context.Principal != null) { - Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties); + Context.Authentication.SignIn(context.SignInScheme, context.Principal, context.Properties); } if (!context.IsRequestCompleted && context.RedirectUri != null) diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs index fed4778780..22bc9eb36b 100644 --- a/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs @@ -31,9 +31,9 @@ namespace Microsoft.AspNet.Authentication private AuthenticationOptions _baseOptions; - protected IChallengeContext ChallengeContext { get; set; } + protected ChallengeContext ChallengeContext { get; set; } protected SignInContext SignInContext { get; set; } - protected ISignOutContext SignOutContext { get; set; } + protected SignOutContext SignOutContext { get; set; } protected HttpContext Context { get; private set; } @@ -145,9 +145,9 @@ namespace Microsoft.AspNet.Authentication return Task.FromResult(false); } - public virtual void GetDescriptions(IDescribeSchemesContext describeContext) + public virtual void GetDescriptions(DescribeSchemesContext describeContext) { - describeContext.Accept(BaseOptions.Description.Dictionary); + describeContext.Accept(BaseOptions.Description.Items); if (PriorHandler != null) { @@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Authentication } } - public virtual void Authenticate(IAuthenticateContext context) + public virtual void Authenticate(AuthenticateContext context) { if (ShouldHandleScheme(context.AuthenticationScheme)) { @@ -163,7 +163,7 @@ namespace Microsoft.AspNet.Authentication if (ticket?.Principal != null) { AuthenticateCalled = true; - context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); + context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items); } else { @@ -177,7 +177,7 @@ namespace Microsoft.AspNet.Authentication } } - public virtual async Task AuthenticateAsync(IAuthenticateContext context) + public virtual async Task AuthenticateAsync(AuthenticateContext context) { if (ShouldHandleScheme(context.AuthenticationScheme)) { @@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Authentication if (ticket?.Principal != null) { AuthenticateCalled = true; - context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); + context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items); } else { @@ -326,13 +326,13 @@ namespace Microsoft.AspNet.Authentication return Task.FromResult(0); } - public virtual void SignIn(ISignInContext context) + public virtual void SignIn(SignInContext context) { if (ShouldHandleScheme(context.AuthenticationScheme)) { - SignInContext = new SignInContext(context.Principal, new AuthenticationProperties(context.Properties)); + SignInContext = context; SignOutContext = null; - context.Accept(BaseOptions.Description.Dictionary); + context.Accept(); } if (PriorHandler != null) @@ -341,7 +341,7 @@ namespace Microsoft.AspNet.Authentication } } - public virtual void SignOut(ISignOutContext context) + public virtual void SignOut(SignOutContext context) { if (ShouldHandleScheme(context.AuthenticationScheme)) { @@ -356,7 +356,7 @@ namespace Microsoft.AspNet.Authentication } } - public virtual void Challenge(IChallengeContext context) + public virtual void Challenge(ChallengeContext context) { if (ShouldHandleScheme(context.AuthenticationScheme)) { @@ -414,7 +414,7 @@ namespace Microsoft.AspNet.Authentication Secure = Request.IsHttps }; - properties.Dictionary[correlationKey] = correlationId; + properties.Items[correlationKey] = correlationId; Response.Cookies.Append(correlationKey, correlationId, cookieOptions); } @@ -437,7 +437,7 @@ namespace Microsoft.AspNet.Authentication Response.Cookies.Delete(correlationKey, cookieOptions); string correlationExtra; - if (!properties.Dictionary.TryGetValue( + if (!properties.Items.TryGetValue( correlationKey, out correlationExtra)) { @@ -445,7 +445,7 @@ namespace Microsoft.AspNet.Authentication return false; } - properties.Dictionary.Remove(correlationKey); + properties.Items.Remove(correlationKey); if (!string.Equals(correlationCookie, correlationExtra, StringComparison.Ordinal)) { diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs index ae1599ee03..5839d4d4e5 100644 --- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs @@ -22,24 +22,24 @@ namespace Microsoft.AspNet.Authentication public IAuthenticationHandler PriorHandler { get; set; } - private void ApplyTransform(IAuthenticateContext context) + private void ApplyTransform(AuthenticateContext context) { if (_transform != null) { // REVIEW: this cast seems really bad (missing interface way to get the result back out?) var authContext = context as AuthenticateContext; - if (authContext?.Result?.Principal != null) + if (authContext?.Principal != null) { context.Authenticated( - _transform.Invoke(authContext.Result.Principal), - authContext.Result.Properties.Dictionary, - authContext.Result.Description.Dictionary); + _transform.Invoke(authContext.Principal), + authContext.Properties, + authContext.Description); } } } - public void Authenticate(IAuthenticateContext context) + public void Authenticate(AuthenticateContext context) { if (PriorHandler != null) { @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Authentication } } - public async Task AuthenticateAsync(IAuthenticateContext context) + public async Task AuthenticateAsync(AuthenticateContext context) { if (PriorHandler != null) { @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Authentication } } - public void Challenge(IChallengeContext context) + public void Challenge(ChallengeContext context) { if (PriorHandler != null) { @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Authentication } } - public void GetDescriptions(IDescribeSchemesContext context) + public void GetDescriptions(DescribeSchemesContext context) { if (PriorHandler != null) { @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Authentication } } - public void SignIn(ISignInContext context) + public void SignIn(SignInContext context) { if (PriorHandler != null) { @@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Authentication } } - public void SignOut(ISignOutContext context) + public void SignOut(SignOutContext context) { if (PriorHandler != null) { diff --git a/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs index 9b262e6c25..ccfba6456b 100644 --- a/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs @@ -44,8 +44,8 @@ namespace Microsoft.AspNet.Authentication.DataHandler.Serializer public static void Write([NotNull] BinaryWriter writer, [NotNull] AuthenticationProperties properties) { writer.Write(FormatVersion); - writer.Write(properties.Dictionary.Count); - foreach (var kv in properties.Dictionary) + writer.Write(properties.Items.Count); + foreach (var kv in properties.Items) { writer.Write(kv.Key); writer.Write(kv.Value); diff --git a/src/Microsoft.AspNet.Authentication/SignInContext.cs b/src/Microsoft.AspNet.Authentication/SignInContext.cs deleted file mode 100644 index efe055ba83..0000000000 --- a/src/Microsoft.AspNet.Authentication/SignInContext.cs +++ /dev/null @@ -1,20 +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.Security.Claims; -using Microsoft.AspNet.Http.Authentication; - -namespace Microsoft.AspNet.Authentication -{ - public class SignInContext - { - public SignInContext(ClaimsPrincipal principal, AuthenticationProperties properties) - { - Principal = principal; - Properties = properties; - } - - public ClaimsPrincipal Principal { get; private set; } - public AuthenticationProperties Properties { get; private set; } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index 9c1ac2fdd6..aa13043976 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Authentication.Cookies private Task SignInAsAlice(HttpContext context) { - context.Response.SignIn("Cookies", + context.Authentication.SignIn("Cookies", new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), new AuthenticationProperties()); return Task.FromResult(null); @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Authentication.Cookies private Task SignInAsWrong(HttpContext context) { - context.Response.SignIn("Oops", + context.Authentication.SignIn("Oops", new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), new AuthenticationProperties()); return Task.FromResult(null); @@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Authentication.Cookies private Task SignOutAsWrong(HttpContext context) { - context.Response.SignOut("Oops"); + context.Authentication.SignOut("Oops"); return Task.FromResult(null); } @@ -305,7 +305,7 @@ namespace Microsoft.AspNet.Authentication.Cookies }, context => { - context.Response.SignIn("Cookies", + context.Authentication.SignIn("Cookies", new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), new AuthenticationProperties() { ExpiresUtc = clock.UtcNow.Add(TimeSpan.FromMinutes(5)) }); return Task.FromResult(null); @@ -435,7 +435,7 @@ namespace Microsoft.AspNet.Authentication.Cookies context => { Assert.Equal(new PathString("/base"), context.Request.PathBase); - context.Response.SignIn("Cookies", + context.Authentication.SignIn("Cookies", new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies")))); return Task.FromResult(null); }, @@ -545,12 +545,12 @@ namespace Microsoft.AspNet.Authentication.Cookies else if (req.Path == new PathString("/unauthorized")) { // Simulate Authorization failure - var result = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); - res.Challenge(CookieAuthenticationDefaults.AuthenticationScheme); + var result = await context.Authentication.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); + context.Authentication.Challenge(CookieAuthenticationDefaults.AuthenticationScheme); } else if (req.Path == new PathString("/protected/CustomRedirect")) { - context.Response.Challenge(new AuthenticationProperties() { RedirectUri = "/CustomRedirect" }); + context.Authentication.Challenge(new AuthenticationProperties() { RedirectUri = "/CustomRedirect" }); } else if (req.Path == new PathString("/me")) { @@ -558,7 +558,7 @@ namespace Microsoft.AspNet.Authentication.Cookies } else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder)) { - var result = await context.AuthenticateAsync(remainder.Value.Substring(1)); + var result = await context.Authentication.AuthenticateAsync(remainder.Value.Substring(1)); Describe(res, result); } else if (req.Path == new PathString("/testpath") && testpath != null) @@ -594,7 +594,7 @@ namespace Microsoft.AspNet.Authentication.Cookies } if (result != null && result.Properties != null) { - xml.Add(result.Properties.Dictionary.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value)))); + xml.Add(result.Properties.Items.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value)))); } using (var memory = new MemoryStream()) { diff --git a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index ad3f6b74fe..2cde6c7678 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Authentication.Facebook }, context => { - context.Response.Challenge("Facebook"); + context.Authentication.Challenge("Facebook"); return true; }); var transaction = await SendAsync(server, "http://example.com/challenge"); @@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Authentication.Facebook }, context => { - context.Response.Challenge("Facebook"); + context.Authentication.Challenge("Facebook"); return true; }); var transaction = await SendAsync(server, "http://example.com/challenge"); diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index 6ed8a1734b..08917a6748 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -142,14 +142,14 @@ namespace Microsoft.AspNet.Authentication.Google var res = context.Response; if (req.Path == new PathString("/challenge2")) { - res.Challenge(new AuthenticationProperties( + context.Authentication.Challenge("Google", new AuthenticationProperties( new Dictionary() { { "scope", "https://www.googleapis.com/auth/plus.login" }, { "access_type", "offline" }, { "approval_prompt", "force" }, { "login_hint", "test@example.com" } - }), "Google"); + })); res.StatusCode = 401; } @@ -280,7 +280,7 @@ namespace Microsoft.AspNet.Authentication.Google var properties = new AuthenticationProperties(); var correlationKey = ".AspNet.Correlation.Google"; var correlationValue = "TestCorrelationId"; - properties.Dictionary.Add(correlationKey, correlationValue); + properties.Items.Add(correlationKey, correlationValue); properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await SendAsync(server, @@ -325,7 +325,7 @@ namespace Microsoft.AspNet.Authentication.Google var properties = new AuthenticationProperties(); var correlationKey = ".AspNet.Correlation.Google"; var correlationValue = "TestCorrelationId"; - properties.Dictionary.Add(correlationKey, correlationValue); + properties.Items.Add(correlationKey, correlationValue); properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await SendAsync(server, @@ -355,7 +355,7 @@ namespace Microsoft.AspNet.Authentication.Google var properties = new AuthenticationProperties(); var correlationKey = ".AspNet.Correlation.Google"; var correlationValue = "TestCorrelationId"; - properties.Dictionary.Add(correlationKey, correlationValue); + properties.Items.Add(correlationKey, correlationValue); properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await SendAsync(server, @@ -427,7 +427,7 @@ namespace Microsoft.AspNet.Authentication.Google var properties = new AuthenticationProperties(); var correlationKey = ".AspNet.Correlation.Google"; var correlationValue = "TestCorrelationId"; - properties.Dictionary.Add(correlationKey, correlationValue); + properties.Items.Add(correlationKey, correlationValue); properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await SendAsync(server, @@ -497,7 +497,7 @@ namespace Microsoft.AspNet.Authentication.Google var res = context.Response; if (req.Path == new PathString("/challenge")) { - res.Challenge("Google"); + context.Authentication.Challenge("Google"); res.StatusCode = 401; } else if (req.Path == new PathString("/me")) @@ -507,14 +507,14 @@ namespace Microsoft.AspNet.Authentication.Google else if (req.Path == new PathString("/unauthorized")) { // Simulate Authorization failure - var result = await context.AuthenticateAsync("Google"); - res.Challenge("Google"); + var result = await context.Authentication.AuthenticateAsync("Google"); + context.Authentication.Challenge("Google"); } else if (req.Path == new PathString("/unauthorizedAuto")) { - var result = await context.AuthenticateAsync("Google"); + var result = await context.Authentication.AuthenticateAsync("Google"); res.StatusCode = 401; - res.Challenge(); + context.Authentication.Challenge(); } else if (req.Path == new PathString("/401")) { diff --git a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index 28ca0ecc94..60230224b6 100644 --- a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount }, context => { - context.Response.Challenge("Microsoft"); + context.Authentication.Challenge("Microsoft"); return true; }); var transaction = await SendAsync(server, "http://example.com/challenge"); @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount }, context => { - context.Response.Challenge("Microsoft"); + context.Authentication.Challenge("Microsoft"); return true; }); var transaction = await SendAsync(server, "http://example.com/challenge"); @@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount var properties = new AuthenticationProperties(); var correlationKey = ".AspNet.Correlation.Microsoft"; var correlationValue = "TestCorrelationId"; - properties.Dictionary.Add(correlationKey, correlationValue); + properties.Items.Add(correlationKey, correlationValue); properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await SendAsync(server, diff --git a/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs index 2fd8bb4226..4d589a43c8 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs @@ -326,8 +326,8 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer else if (context.Request.Path == new PathString("/unauthorized")) { // Simulate Authorization failure - var result = await context.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme); - context.Response.Challenge(OAuthBearerAuthenticationDefaults.AuthenticationScheme); + var result = await context.Authentication.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme); + context.Authentication.Challenge(OAuthBearerAuthenticationDefaults.AuthenticationScheme); } else diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs index 1974373470..1134c7300c 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs @@ -493,28 +493,6 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect } } - public class OpenIdConnectAuthenticationContext : IAuthenticateContext - { - public OpenIdConnectAuthenticationContext(string scheme = null) - { - AuthenticationScheme = scheme ?? OpenIdConnectAuthenticationDefaults.AuthenticationScheme; - } - - public string AuthenticationScheme - { - get; - set; - } - - public void Authenticated(ClaimsPrincipal principal, IDictionary properties, IDictionary description) - { - } - - public void NotAuthenticated() - { - } - } - /// /// Provides a Facade over IOptions /// @@ -576,7 +554,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect return true; } - public override void Challenge(IChallengeContext context) + public override void Challenge(ChallengeContext context) { } diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index 85e74e19a5..da290cca17 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -205,21 +205,21 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect var res = context.Response; if (req.Path == new PathString("/challenge")) { - res.Challenge("OpenIdConnect"); + context.Authentication.Challenge("OpenIdConnect"); res.StatusCode = 401; } else if (req.Path == new PathString("/signin")) { // REVIEW: this used to just be res.SignIn() - res.SignIn("OpenIdConnect", new ClaimsPrincipal()); + context.Authentication.SignIn("OpenIdConnect", new ClaimsPrincipal()); } else if (req.Path == new PathString("/signout")) { - res.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationScheme); + context.Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationScheme); } else if (req.Path == new PathString("/signout_with_specific_redirect_uri")) { - res.SignOut( + context.Authentication.SignOut( OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" }); } diff --git a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs index bca10fbf44..d0b9494d19 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Authentication.Twitter }), context => { - context.Response.Challenge("Twitter"); + context.Authentication.Challenge("Twitter"); return true; }); var transaction = await SendAsync(server, "http://example.com/challenge"); @@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Authentication.Twitter }), context => { - context.Response.Challenge("Twitter"); + context.Authentication.Challenge("Twitter"); return true; }); var transaction = await SendAsync(server, "http://example.com/challenge");