From 1a59b385a012ac0873fb599fbe6c648b10088fd5 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 30 Oct 2015 11:39:39 -0700 Subject: [PATCH] React to WebEncoders changes. --- samples/SocialSample/Startup.cs | 6 +-- .../ChunkingCookieManager.cs | 12 +++--- .../CookieAuthenticationMiddleware.cs | 4 +- .../FacebookMiddleware.cs | 4 +- .../GoogleMiddleware.cs | 4 +- .../JwtBearerMiddleware.cs | 4 +- .../MicrosoftAccountMiddleware.cs | 4 +- .../OAuthMiddleware.cs | 4 +- .../OpenIdConnectHandler.cs | 18 ++++----- .../OpenIdConnectMiddleware.cs | 8 ++-- .../TwitterHandler.cs | 20 +++++----- .../TwitterMiddleware.cs | 4 +- .../AuthenticationHandler.cs | 6 +-- .../AuthenticationMiddleware.cs | 6 +-- .../AuthenticationHandlerFacts.cs | 7 ++-- .../Facebook/FacebookMiddlewareTests.cs | 15 ++++---- .../Google/GoogleMiddlewareTests.cs | 38 +++++++++---------- .../MicrosoftAccountMiddlewareTests.cs | 4 +- ...uthenticationPropertiesFormaterKeyValue.cs | 4 +- .../OpenIdConnect/ExpectedQueryValues.cs | 14 +++---- .../OpenIdConnectHandlerTests.cs | 8 ++-- ...ConnectMiddlewareForTestingAuthenticate.cs | 6 +-- .../OpenIdConnectMiddlewareTests.cs | 6 +-- 23 files changed, 103 insertions(+), 103 deletions(-) diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index d9db3b1a3d..0b76698aaa 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Security.Claims; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Authentication.Google; @@ -13,7 +14,6 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; using Newtonsoft.Json.Linq; namespace CookieSample @@ -66,7 +66,7 @@ namespace CookieSample OnRemoteError = ctx => { - ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message)); + ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message)); ctx.HandleResponse(); return Task.FromResult(0); } @@ -83,7 +83,7 @@ namespace CookieSample { OnRemoteError = ctx => { - ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message)); + ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message)); ctx.HandleResponse(); return Task.FromResult(0); } diff --git a/src/Microsoft.AspNet.Authentication.Cookies/ChunkingCookieManager.cs b/src/Microsoft.AspNet.Authentication.Cookies/ChunkingCookieManager.cs index 6cda19b466..7560cd1456 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/ChunkingCookieManager.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/ChunkingCookieManager.cs @@ -5,9 +5,9 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Text.Encodings.Web; using Microsoft.AspNet.Http; using Microsoft.Extensions.Primitives; -using Microsoft.Extensions.WebEncoders; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Authentication.Cookies @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authentication.Cookies /// public class ChunkingCookieManager : ICookieManager { - public ChunkingCookieManager(IUrlEncoder urlEncoder) + public ChunkingCookieManager(UrlEncoder urlEncoder) { // Lowest common denominator. Safari has the lowest known limit (4093), and we leave little extra just in case. // See http://browsercookielimits.x64.me/. @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Authentication.Cookies /// public bool ThrowForPartialCookies { get; set; } - private IUrlEncoder Encoder { get; set; } + private UrlEncoder Encoder { get; set; } // Parse the "chunks:XX" to determine how many chunks there should be. private static int ParseChunksCount(string value) @@ -149,7 +149,7 @@ namespace Microsoft.AspNet.Authentication.Cookies throw new ArgumentNullException(nameof(options)); } - var escapedKey = Encoder.UrlEncode(key); + var escapedKey = Encoder.Encode(key); var template = new SetCookieHeaderValue(escapedKey) { @@ -169,7 +169,7 @@ namespace Microsoft.AspNet.Authentication.Cookies quoted = true; value = RemoveQuotes(value); } - var escapedValue = Encoder.UrlEncode(value); + var escapedValue = Encoder.Encode(value); // Normal cookie var responseHeaders = context.Response.Headers; @@ -239,7 +239,7 @@ namespace Microsoft.AspNet.Authentication.Cookies throw new ArgumentNullException(nameof(options)); } - var escapedKey = Encoder.UrlEncode(key); + var escapedKey = Encoder.Encode(key); var keys = new List(); keys.Add(escapedKey + "="); diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs index aca234da08..1f2572ffea 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.Cookies { @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Authentication.Cookies RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder urlEncoder, + UrlEncoder urlEncoder, CookieAuthenticationOptions options) : base(next, options, loggerFactory, urlEncoder) { diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs index 8976b93fe0..711d3e5630 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs @@ -3,12 +3,12 @@ using System; using System.Globalization; +using System.Text.Encodings.Web; using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.Facebook { @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Authentication.Facebook RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IOptions sharedOptions, FacebookOptions options) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options) diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs index fe398c5f6e..e32e0c8f55 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs @@ -3,12 +3,12 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Text.Encodings.Web; using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.Google { @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Authentication.Google RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IOptions sharedOptions, GoogleOptions options) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options) diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs index 54d225c3e3..da6d21c1c8 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs @@ -3,9 +3,9 @@ using System; using System.Net.Http; +using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer public JwtBearerMiddleware( RequestDelegate next, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, JwtBearerOptions options) : base(next, options, loggerFactory, encoder) { diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs index f93b0feca8..a20d08d5f1 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text.Encodings.Web; using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.MicrosoftAccount { @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IOptions sharedOptions, MicrosoftAccountOptions options) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options) diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs index 1b318a90a7..127eba20cb 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs @@ -5,11 +5,11 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net.Http; +using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.OAuth { @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication.OAuth RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IOptions sharedOptions, TOptions options) : base(next, options, loggerFactory, encoder) diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs index 81b42227a6..b0472703a8 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs @@ -12,12 +12,12 @@ using System.Net.Http.Headers; using System.Security.Claims; using System.Security.Cryptography; using System.Text; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.Net.Http.Headers; using Newtonsoft.Json.Linq; @@ -53,9 +53,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect protected HttpClient Backchannel { get; private set; } - protected IHtmlEncoder HtmlEncoder { get; private set; } + protected HtmlEncoder HtmlEncoder { get; private set; } - public OpenIdConnectHandler(HttpClient backchannel, IHtmlEncoder htmlEncoder) + public OpenIdConnectHandler(HttpClient backchannel, HtmlEncoder htmlEncoder) { Backchannel = backchannel; HtmlEncoder = htmlEncoder; @@ -133,14 +133,14 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect var inputs = new StringBuilder(); foreach (var parameter in message.Parameters) { - var name = HtmlEncoder.HtmlEncode(parameter.Key); - var value = HtmlEncoder.HtmlEncode(parameter.Value); + var name = HtmlEncoder.Encode(parameter.Key); + var value = HtmlEncoder.Encode(parameter.Value); var input = string.Format(CultureInfo.InvariantCulture, InputTagFormat, name, value); inputs.AppendLine(input); } - var issuer = HtmlEncoder.HtmlEncode(message.IssuerAddress); + var issuer = HtmlEncoder.Encode(message.IssuerAddress); var content = string.Format(CultureInfo.InvariantCulture, HtmlFormFormat, issuer, inputs); var buffer = Encoding.UTF8.GetBytes(content); @@ -260,14 +260,14 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect var inputs = new StringBuilder(); foreach (var parameter in message.Parameters) { - var name = HtmlEncoder.HtmlEncode(parameter.Key); - var value = HtmlEncoder.HtmlEncode(parameter.Value); + var name = HtmlEncoder.Encode(parameter.Key); + var value = HtmlEncoder.Encode(parameter.Value); var input = string.Format(CultureInfo.InvariantCulture, InputTagFormat, name, value); inputs.AppendLine(input); } - var issuer = HtmlEncoder.HtmlEncode(message.IssuerAddress); + var issuer = HtmlEncoder.Encode(message.IssuerAddress); var content = string.Format(CultureInfo.InvariantCulture, HtmlFormFormat, issuer, inputs); var buffer = Encoding.UTF8.GetBytes(content); diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs index 691c861949..4ce09644ea 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs @@ -5,12 +5,12 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Text; +using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; @@ -36,11 +36,11 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IServiceProvider services, IOptions sharedOptions, OpenIdConnectOptions options, - IHtmlEncoder htmlEncoder) + HtmlEncoder htmlEncoder) : base(next, options, loggerFactory, encoder) { if (next == null) @@ -169,7 +169,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect protected HttpClient Backchannel { get; private set; } - protected IHtmlEncoder HtmlEncoder { get; private set; } + protected HtmlEncoder HtmlEncoder { get; private set; } /// /// Provides the object for processing authentication-related requests. diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs index da92af5485..61709aafdc 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs @@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Authentication.Twitter var parameterBuilder = new StringBuilder(); foreach (var authorizationKey in authorizationParts) { - parameterBuilder.AppendFormat("{0}={1}&", UrlEncoder.UrlEncode(authorizationKey.Key), UrlEncoder.UrlEncode(authorizationKey.Value)); + parameterBuilder.AppendFormat("{0}={1}&", UrlEncoder.Encode(authorizationKey.Key), UrlEncoder.Encode(authorizationKey.Value)); } parameterBuilder.Length--; var parameterString = parameterBuilder.ToString(); @@ -172,9 +172,9 @@ namespace Microsoft.AspNet.Authentication.Twitter var canonicalizedRequestBuilder = new StringBuilder(); canonicalizedRequestBuilder.Append(HttpMethod.Post.Method); canonicalizedRequestBuilder.Append("&"); - canonicalizedRequestBuilder.Append(UrlEncoder.UrlEncode(RequestTokenEndpoint)); + canonicalizedRequestBuilder.Append(UrlEncoder.Encode(RequestTokenEndpoint)); canonicalizedRequestBuilder.Append("&"); - canonicalizedRequestBuilder.Append(UrlEncoder.UrlEncode(parameterString)); + canonicalizedRequestBuilder.Append(UrlEncoder.Encode(parameterString)); var signature = ComputeSignature(consumerSecret, null, canonicalizedRequestBuilder.ToString()); authorizationParts.Add("oauth_signature", signature); @@ -184,7 +184,7 @@ namespace Microsoft.AspNet.Authentication.Twitter foreach (var authorizationPart in authorizationParts) { authorizationHeaderBuilder.AppendFormat( - "{0}=\"{1}\", ", authorizationPart.Key, UrlEncoder.UrlEncode(authorizationPart.Value)); + "{0}=\"{1}\", ", authorizationPart.Key, UrlEncoder.Encode(authorizationPart.Value)); } authorizationHeaderBuilder.Length = authorizationHeaderBuilder.Length - 2; @@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Authentication.Twitter var parameterBuilder = new StringBuilder(); foreach (var authorizationKey in authorizationParts) { - parameterBuilder.AppendFormat("{0}={1}&", UrlEncoder.UrlEncode(authorizationKey.Key), UrlEncoder.UrlEncode(authorizationKey.Value)); + parameterBuilder.AppendFormat("{0}={1}&", UrlEncoder.Encode(authorizationKey.Key), UrlEncoder.Encode(authorizationKey.Value)); } parameterBuilder.Length--; var parameterString = parameterBuilder.ToString(); @@ -234,9 +234,9 @@ namespace Microsoft.AspNet.Authentication.Twitter var canonicalizedRequestBuilder = new StringBuilder(); canonicalizedRequestBuilder.Append(HttpMethod.Post.Method); canonicalizedRequestBuilder.Append("&"); - canonicalizedRequestBuilder.Append(UrlEncoder.UrlEncode(AccessTokenEndpoint)); + canonicalizedRequestBuilder.Append(UrlEncoder.Encode(AccessTokenEndpoint)); canonicalizedRequestBuilder.Append("&"); - canonicalizedRequestBuilder.Append(UrlEncoder.UrlEncode(parameterString)); + canonicalizedRequestBuilder.Append(UrlEncoder.Encode(parameterString)); var signature = ComputeSignature(consumerSecret, token.TokenSecret, canonicalizedRequestBuilder.ToString()); authorizationParts.Add("oauth_signature", signature); @@ -247,7 +247,7 @@ namespace Microsoft.AspNet.Authentication.Twitter foreach (var authorizationPart in authorizationParts) { authorizationHeaderBuilder.AppendFormat( - "{0}=\"{1}\", ", authorizationPart.Key, UrlEncoder.UrlEncode(authorizationPart.Value)); + "{0}=\"{1}\", ", authorizationPart.Key, UrlEncoder.Encode(authorizationPart.Value)); } authorizationHeaderBuilder.Length = authorizationHeaderBuilder.Length - 2; @@ -294,8 +294,8 @@ namespace Microsoft.AspNet.Authentication.Twitter algorithm.Key = Encoding.ASCII.GetBytes( string.Format(CultureInfo.InvariantCulture, "{0}&{1}", - UrlEncoder.UrlEncode(consumerSecret), - string.IsNullOrEmpty(tokenSecret) ? string.Empty : UrlEncoder.UrlEncode(tokenSecret))); + UrlEncoder.Encode(consumerSecret), + string.IsNullOrEmpty(tokenSecret) ? string.Empty : UrlEncoder.Encode(tokenSecret))); var hash = algorithm.ComputeHash(Encoding.ASCII.GetBytes(signatureData)); return Convert.ToBase64String(hash); } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs index 2eeb010c53..bcfbe00149 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs @@ -5,11 +5,11 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net.Http; +using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.Twitter { @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Authentication.Twitter RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IOptions sharedOptions, TwitterOptions options) : base(next, options, loggerFactory, encoder) diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs index dcdf0badf7..7c4102cf39 100644 --- a/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication { @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Authentication protected ILogger Logger { get; private set; } - protected IUrlEncoder UrlEncoder { get; private set; } + protected UrlEncoder UrlEncoder { get; private set; } public IAuthenticationHandler PriorHandler { get; set; } @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Authentication /// The utility object to observe the current request and response /// The logging factory used to create loggers /// async completion - public async Task InitializeAsync(TOptions options, HttpContext context, ILogger logger, IUrlEncoder encoder) + public async Task InitializeAsync(TOptions options, HttpContext context, ILogger logger, UrlEncoder encoder) { if (options == null) { diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs index 0f26048bbc..ce668e5c2d 100644 --- a/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication { @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authentication RequestDelegate next, TOptions options, ILoggerFactory loggerFactory, - IUrlEncoder encoder) + UrlEncoder encoder) { if (next == null) { @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Authentication public ILogger Logger { get; set; } - public IUrlEncoder UrlEncoder { get; set; } + public UrlEncoder UrlEncoder { get; set; } public async Task Invoke(HttpContext context) { diff --git a/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs b/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs index 765065045a..073d6f1e4b 100644 --- a/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs +++ b/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Security.Claims; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; @@ -90,7 +91,7 @@ namespace Microsoft.AspNet.Authentication await handler.InitializeAsync( new CountOptions(), context, new LoggerFactory().CreateLogger("CountHandler"), - Extensions.WebEncoders.UrlEncoder.Default); + UrlEncoder.Default); handler.Options.AuthenticationScheme = scheme; handler.Options.AutomaticAuthenticate = true; return handler; @@ -116,7 +117,7 @@ namespace Microsoft.AspNet.Authentication await handler.InitializeAsync( new TestOptions(), context, new LoggerFactory().CreateLogger("TestHandler"), - Extensions.WebEncoders.UrlEncoder.Default); + UrlEncoder.Default); handler.Options.AuthenticationScheme = scheme; return handler; } @@ -149,7 +150,7 @@ namespace Microsoft.AspNet.Authentication await handler.InitializeAsync( new TestAutoOptions(), context, new LoggerFactory().CreateLogger("TestAutoHandler"), - Extensions.WebEncoders.UrlEncoder.Default); + UrlEncoder.Default); handler.Options.AuthenticationScheme = scheme; handler.Options.AutomaticAuthenticate = auto; return handler; diff --git a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index ae212e9c2a..21ace654ee 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -2,12 +2,14 @@ // 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.Net; using System.Net.Http; -using System.Collections.Generic; using System.Text; -using System.Linq; +using System.Text.Encodings.Web; using System.Threading.Tasks; +using Microsoft.AspNet.Authentication.Cookies; using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; @@ -15,11 +17,8 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.WebEncoders; using Newtonsoft.Json; using Xunit; -using System.Diagnostics; -using Microsoft.AspNet.Authentication.Cookies; namespace Microsoft.AspNet.Authentication.Facebook { @@ -90,7 +89,7 @@ namespace Microsoft.AspNet.Authentication.Facebook Assert.Contains("https://www.facebook.com/v2.2/dialog/oauth", location); Assert.Contains("response_type=code", location); Assert.Contains("client_id=", location); - Assert.Contains("redirect_uri=" + UrlEncoder.Default.UrlEncode("http://example.com/base/signin-facebook"), location); + Assert.Contains("redirect_uri=" + UrlEncoder.Default.Encode("http://example.com/base/signin-facebook"), location); Assert.Contains("scope=", location); Assert.Contains("state=", location); } @@ -117,7 +116,7 @@ namespace Microsoft.AspNet.Authentication.Facebook Assert.Contains("https://www.facebook.com/v2.2/dialog/oauth", location); Assert.Contains("response_type=code", location); Assert.Contains("client_id=", location); - Assert.Contains("redirect_uri="+ UrlEncoder.Default.UrlEncode("http://example.com/signin-facebook"), location); + Assert.Contains("redirect_uri="+ UrlEncoder.Default.Encode("http://example.com/signin-facebook"), location); Assert.Contains("scope=", location); Assert.Contains("state=", location); } @@ -216,7 +215,7 @@ namespace Microsoft.AspNet.Authentication.Facebook properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await server.SendAsync( - "https://example.com/signin-facebook?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-facebook?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); Assert.Equal("/me", transaction.Response.Headers.GetValues("Location").First()); diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index 591e00cbd4..beda30bbdf 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Security.Claims; using System.Text; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.Builder; @@ -16,7 +17,6 @@ using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.WebEncoders; using Newtonsoft.Json; using Xunit; @@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Authentication.Google var transaction = await server.SendAsync("https://example.com/challenge"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); var query = transaction.Response.Headers.Location.Query; - Assert.Contains("&scope=" + UrlEncoder.Default.UrlEncode("openid profile email"), query); + Assert.Contains("&scope=" + UrlEncoder.Default.Encode("openid profile email"), query); } [Fact] @@ -152,7 +152,7 @@ namespace Microsoft.AspNet.Authentication.Google var transaction = await server.SendAsync("https://example.com/401"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); var query = transaction.Response.Headers.Location.Query; - Assert.Contains("&scope=" + UrlEncoder.Default.UrlEncode("openid profile email"), query); + Assert.Contains("&scope=" + UrlEncoder.Default.Encode("openid profile email"), query); } [Fact] @@ -185,10 +185,10 @@ namespace Microsoft.AspNet.Authentication.Google var transaction = await server.SendAsync("https://example.com/challenge2"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); var query = transaction.Response.Headers.Location.Query; - Assert.Contains("scope=" + UrlEncoder.Default.UrlEncode("https://www.googleapis.com/auth/plus.login"), query); + Assert.Contains("scope=" + UrlEncoder.Default.Encode("https://www.googleapis.com/auth/plus.login"), query); Assert.Contains("access_type=offline", query); Assert.Contains("approval_prompt=force", query); - Assert.Contains("login_hint=" + UrlEncoder.Default.UrlEncode("test@example.com"), query); + Assert.Contains("login_hint=" + UrlEncoder.Default.Encode("test@example.com"), query); } [Fact] @@ -263,7 +263,7 @@ namespace Microsoft.AspNet.Authentication.Google { OnRemoteError = ctx => { - ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message)); + ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message)); ctx.HandleResponse(); return Task.FromResult(0); } @@ -341,7 +341,7 @@ namespace Microsoft.AspNet.Authentication.Google properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await server.SendAsync( - "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); Assert.Equal("/me", transaction.Response.Headers.GetValues("Location").First()); @@ -388,7 +388,7 @@ namespace Microsoft.AspNet.Authentication.Google { OnRemoteError = ctx => { - ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message)); + ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message)); ctx.HandleResponse(); return Task.FromResult(0); } @@ -404,16 +404,16 @@ namespace Microsoft.AspNet.Authentication.Google var state = stateFormat.Protect(properties); await Assert.ThrowsAsync(() => server.SendAsync( - "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue)); //var transaction = await server.SendAsync( - // "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + // "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), // correlationKey + "=" + correlationValue); //if (redirect) //{ // Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); - // Assert.Equal("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode("Access token was not found."), + // Assert.Equal("/error?ErrorMessage=" + UrlEncoder.Default.Encode("Access token was not found."), // transaction.Response.Headers.GetValues("Location").First()); //} //else @@ -446,7 +446,7 @@ namespace Microsoft.AspNet.Authentication.Google { OnRemoteError = ctx => { - ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message)); + ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message)); ctx.HandleResponse(); return Task.FromResult(0); } @@ -460,12 +460,12 @@ namespace Microsoft.AspNet.Authentication.Google properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await server.SendAsync( - "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); if (redirect) { Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); - Assert.Equal("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode("Access token was not found."), + Assert.Equal("/error?ErrorMessage=" + UrlEncoder.Default.Encode("Access token was not found."), transaction.Response.Headers.GetValues("Location").First()); } else @@ -540,7 +540,7 @@ namespace Microsoft.AspNet.Authentication.Google properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await server.SendAsync( - "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); Assert.Equal("/me", transaction.Response.Headers.GetValues("Location").First()); @@ -618,7 +618,7 @@ namespace Microsoft.AspNet.Authentication.Google properties.Items.Add(correlationKey, correlationValue); var state = stateFormat.Protect(properties); var transaction = await server.SendAsync( - "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); Assert.Equal("/", transaction.Response.Headers.GetValues("Location").First()); @@ -704,7 +704,7 @@ namespace Microsoft.AspNet.Authentication.Google //Post a message to the Google middleware var transaction = await server.SendAsync( - "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-google?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); @@ -740,7 +740,7 @@ namespace Microsoft.AspNet.Authentication.Google { OnRemoteError = ctx => { - ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message)); + ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message)); ctx.HandleResponse(); return Task.FromResult(0); } @@ -752,7 +752,7 @@ namespace Microsoft.AspNet.Authentication.Google "https://example.com/signin-google?code=TestCode"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); - Assert.Equal("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode("The oauth state was missing or invalid."), + Assert.Equal("/error?ErrorMessage=" + UrlEncoder.Default.Encode("The oauth state was missing or invalid."), transaction.Response.Headers.GetValues("Location").First()); } diff --git a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index 2768a18c36..650c86465e 100644 --- a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Security.Claims; using System.Text; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Authentication.MicrosoftAccount; using Microsoft.AspNet.Authentication.OAuth; @@ -15,7 +16,6 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.WebEncoders; using Newtonsoft.Json; using Xunit; @@ -161,7 +161,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount properties.RedirectUri = "/me"; var state = stateFormat.Protect(properties); var transaction = await server.SendAsync( - "https://example.com/signin-microsoft?code=TestCode&state=" + UrlEncoder.Default.UrlEncode(state), + "https://example.com/signin-microsoft?code=TestCode&state=" + UrlEncoder.Default.Encode(state), correlationKey + "=" + correlationValue); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); Assert.Equal("/me", transaction.Response.Headers.GetValues("Location").First()); diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/AuthenticationPropertiesFormaterKeyValue.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/AuthenticationPropertiesFormaterKeyValue.cs index 74b36d9cbe..66cc84621b 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/AuthenticationPropertiesFormaterKeyValue.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/AuthenticationPropertiesFormaterKeyValue.cs @@ -3,8 +3,8 @@ using System; using System.Text; +using System.Text.Encodings.Web; using Microsoft.AspNet.Http.Authentication; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect var sb = new StringBuilder(); foreach(var item in data.Items) { - sb.Append(encoder.UrlEncode(item.Key) + " " + encoder.UrlEncode(item.Value) + " "); + sb.Append(encoder.Encode(item.Key) + " " + encoder.Encode(item.Value) + " "); } return sb.ToString(); diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/ExpectedQueryValues.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/ExpectedQueryValues.cs index aae31676d1..d1f65aed2a 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/ExpectedQueryValues.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/ExpectedQueryValues.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; -using Microsoft.Extensions.WebEncoders; +using System.Text.Encodings.Web; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Xunit; @@ -144,32 +144,32 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect public string ExpectedClientId { - get { return OpenIdConnectParameterNames.ClientId + "=" + Encoder.UrlEncode(ClientId); } + get { return OpenIdConnectParameterNames.ClientId + "=" + Encoder.Encode(ClientId); } } public string ExpectedRedirectUri { - get { return OpenIdConnectParameterNames.RedirectUri + "=" + Encoder.UrlEncode(RedirectUri); } + get { return OpenIdConnectParameterNames.RedirectUri + "=" + Encoder.Encode(RedirectUri); } } public string ExpectedResource { - get { return OpenIdConnectParameterNames.Resource + "=" + Encoder.UrlEncode(Resource); } + get { return OpenIdConnectParameterNames.Resource + "=" + Encoder.Encode(Resource); } } public string ExpectedResponseMode { - get { return OpenIdConnectParameterNames.ResponseMode + "=" + Encoder.UrlEncode(ResponseMode); } + get { return OpenIdConnectParameterNames.ResponseMode + "=" + Encoder.Encode(ResponseMode); } } public string ExpectedScope { - get { return OpenIdConnectParameterNames.Scope + "=" + Encoder.UrlEncode(Scope); } + get { return OpenIdConnectParameterNames.Scope + "=" + Encoder.Encode(Scope); } } public string ExpectedState { - get { return Encoder.UrlEncode(State); } + get { return Encoder.Encode(State); } } } } diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs index b7d9608744..3c48657d1c 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs @@ -8,13 +8,13 @@ using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Net.Http; using System.Security.Claims; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Xunit; @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect // expected user state is added to the message.Parameters.Items[ExpectedStateParameter] // Userstate == null var message = new OpenIdConnectMessage(); - message.State = UrlEncoder.Default.UrlEncode(formater.Protect(properties)); + message.State = UrlEncoder.Default.Encode(formater.Protect(properties)); message.Code = Guid.NewGuid().ToString(); message.Parameters.Add(ExpectedStateParameter, null); dataset.Add(SetStateOptions, message); @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect var userstate = Guid.NewGuid().ToString(); message.Code = Guid.NewGuid().ToString(); properties.Items.Add(OpenIdConnectDefaults.UserstatePropertiesKey, userstate); - message.State = UrlEncoder.Default.UrlEncode(formater.Protect(properties)); + message.State = UrlEncoder.Default.Encode(formater.Protect(properties)); message.Parameters.Add(ExpectedStateParameter, userstate); dataset.Add(SetStateOptions, message); return dataset; @@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect }; } - private static TestServer CreateServer(Action configureOptions, IUrlEncoder encoder, OpenIdConnectHandler handler = null) + private static TestServer CreateServer(Action configureOptions, UrlEncoder encoder, OpenIdConnectHandler handler = null) { return TestServer.Create( app => diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs index 7d7afa56ec..da8f450796 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text.Encodings.Web; using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Builder; using Microsoft.AspNet.DataProtection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { @@ -24,11 +24,11 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, - IUrlEncoder encoder, + UrlEncoder encoder, IServiceProvider services, IOptions sharedOptions, OpenIdConnectOptions options, - IHtmlEncoder htmlEncoder, + HtmlEncoder htmlEncoder, OpenIdConnectHandler handler = null ) : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, htmlEncoder) diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index d5794003d1..b9f0f26f89 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Security.Claims; +using System.Text.Encodings.Web; using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.AspNet.Authentication.Cookies; @@ -17,7 +18,6 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Xunit; @@ -358,7 +358,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect var transaction = await SendAsync(server, DefaultHost + Signout); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); - Assert.Contains(UrlEncoder.Default.UrlEncode("https://example.com/logout"), transaction.Response.Headers.Location.AbsoluteUri); + Assert.Contains(UrlEncoder.Default.Encode("https://example.com/logout"), transaction.Response.Headers.Location.AbsoluteUri); } [Fact] @@ -375,7 +375,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect var transaction = await SendAsync(server, "https://example.com/signout_with_specific_redirect_uri"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); - Assert.Contains(UrlEncoder.Default.UrlEncode("http://www.example.com/specific_redirect_uri"), transaction.Response.Headers.Location.AbsoluteUri); + Assert.Contains(UrlEncoder.Default.Encode("http://www.example.com/specific_redirect_uri"), transaction.Response.Headers.Location.AbsoluteUri); } private static TestServer CreateServer(Action configureOptions, Func handler = null, AuthenticationProperties properties = null)