16
16
using Microsoft . AspNetCore . Http ;
17
17
using Microsoft . Extensions . Logging ;
18
18
using Microsoft . Extensions . Options ;
19
- using Microsoft . Extensions . Primitives ;
20
19
using Microsoft . IdentityModel . Protocols . OpenIdConnect ;
21
20
using Microsoft . IdentityModel . Tokens ;
22
21
using Microsoft . Net . Http . Headers ;
@@ -30,23 +29,8 @@ namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
30
29
public class OpenIdConnectHandler : RemoteAuthenticationHandler < OpenIdConnectOptions > , IAuthenticationSignOutHandler
31
30
{
32
31
private const string NonceProperty = "N" ;
33
- private const string UriSchemeDelimiter = "://" ;
34
32
35
33
private const string HeaderValueEpocDate = "Thu, 01 Jan 1970 00:00:00 GMT" ;
36
- private const string InputTagFormat = @"<input type=""hidden"" name=""{0}"" value=""{1}"" />" ;
37
- private const string HtmlFormFormat = @"<!doctype html>
38
- <html>
39
- <head>
40
- <title>Please wait while you're being redirected to the identity provider</title>
41
- </head>
42
- <body>
43
- <form name=""form"" method=""post"" action=""{0}"">
44
- {1}
45
- <noscript>Click here to finish the process: <input type=""submit"" /></noscript>
46
- </form>
47
- <script>document.form.submit();</script>
48
- </body>
49
- </html>" ;
50
34
51
35
private static readonly RandomNumberGenerator CryptoRandom = RandomNumberGenerator . Create ( ) ;
52
36
@@ -241,19 +225,7 @@ public async virtual Task SignOutAsync(AuthenticationProperties properties)
241
225
}
242
226
else if ( Options . AuthenticationMethod == OpenIdConnectRedirectBehavior . FormPost )
243
227
{
244
- var inputs = new StringBuilder ( ) ;
245
- foreach ( var parameter in message . Parameters )
246
- {
247
- var name = HtmlEncoder . Encode ( parameter . Key ) ;
248
- var value = HtmlEncoder . Encode ( parameter . Value ) ;
249
-
250
- var input = string . Format ( CultureInfo . InvariantCulture , InputTagFormat , name , value ) ;
251
- inputs . AppendLine ( input ) ;
252
- }
253
-
254
- var issuer = HtmlEncoder . Encode ( message . IssuerAddress ) ;
255
-
256
- var content = string . Format ( CultureInfo . InvariantCulture , HtmlFormFormat , issuer , inputs ) ;
228
+ var content = message . BuildFormPost ( ) ;
257
229
var buffer = Encoding . UTF8 . GetBytes ( content ) ;
258
230
259
231
Response . ContentLength = buffer . Length ;
@@ -422,19 +394,7 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop
422
394
}
423
395
else if ( Options . AuthenticationMethod == OpenIdConnectRedirectBehavior . FormPost )
424
396
{
425
- var inputs = new StringBuilder ( ) ;
426
- foreach ( var parameter in message . Parameters )
427
- {
428
- var name = HtmlEncoder . Encode ( parameter . Key ) ;
429
- var value = HtmlEncoder . Encode ( parameter . Value ) ;
430
-
431
- var input = string . Format ( CultureInfo . InvariantCulture , InputTagFormat , name , value ) ;
432
- inputs . AppendLine ( input ) ;
433
- }
434
-
435
- var issuer = HtmlEncoder . Encode ( message . IssuerAddress ) ;
436
-
437
- var content = string . Format ( CultureInfo . InvariantCulture , HtmlFormFormat , issuer , inputs ) ;
397
+ var content = message . BuildFormPost ( ) ;
438
398
var buffer = Encoding . UTF8 . GetBytes ( content ) ;
439
399
440
400
Response . ContentLength = buffer . Length ;
0 commit comments