I am trying to pass a custom header value (no cookies) to IdentityServer4 as the user attempts to login. Here is how its all setup.
Custom authorisation attribute:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class CustomAuthorizeAttribute : AuthorizeAttribute, IAuthorizationFilter
{
private readonly string _customId;
public CustomAuthorizeAttribute(string customId)
{
_customId = customId;
}
public void OnAuthorization(AuthorizationFilterContext context)
{
context.HttpContext.Request.Headers.Add("X-CustomId", _customId);
}
}
Controller:
[CustomAuthorize("0123456789")]
public IActionResult Secure()
{
ViewData["Message"] = "Secure Page.";
return View();
}
IdentityServer > AccountControlelr:
[HttpGet]
public async Task<IActionResult> Login(string returnUrl)
{
var customId = _httpContextAccessor.HttpContext.Request.Headers["X-CustomId"];
// build a model so we know what to show on the login page
var vm = await BuildLoginViewModelAsync(returnUrl);
if (vm.IsExternalLoginOnly)
{
// we only have one option for logging in and it's an external provider
return await ExternalLogin(vm.ExternalLoginScheme, returnUrl);
}
return View(vm);
}
The custom header value never makes it to any of the login endpoints. Wondering if anyone has come across this before and have any ideas how to get it working? Many Thanks