The next generation of the Teknik Services. Written in ASP.NET.
https://www.teknik.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
using Microsoft.AspNetCore.Builder; |
|
using Microsoft.AspNetCore.Http; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using Teknik.Configuration; |
|
using Teknik.Utilities; |
|
|
|
namespace Teknik.IdentityServer.Middleware |
|
{ |
|
public class SetupHttpContextMiddleware |
|
{ |
|
private readonly RequestDelegate _next; |
|
|
|
public SetupHttpContextMiddleware(RequestDelegate next) |
|
{ |
|
_next = next; |
|
} |
|
|
|
public async Task Invoke(HttpContext httpContext) |
|
{ |
|
// Generate the NONCE used for this request |
|
string nonce = Convert.ToBase64String(Encoding.UTF8.GetBytes(StringHelper.RandomString(24))); |
|
httpContext.Items[Constants.NONCE_KEY] = nonce; |
|
|
|
await _next(httpContext); |
|
} |
|
} |
|
|
|
// Extension method used to add the middleware to the HTTP request pipeline. |
|
public static class SetupHttpContextMiddlewareExtensions |
|
{ |
|
public static IApplicationBuilder UseHttpContextSetup(this IApplicationBuilder builder) |
|
{ |
|
return builder.UseMiddleware<SetupHttpContextMiddleware>(); |
|
} |
|
} |
|
}
|
|
|