Category / Section
How to pass custom data to authorization server?
Published:
In some scenarios, you may need to send custom data, such as cookies, to the authorization server to confirm if the requestor is logged-in or to process the data. This can be achieved using the authorizationServer
header property.
Sending Custom Data in JavaScript
To send custom data to the authorization server, you can use the following code snippet:
authorizationServer: {
url: authorizationServerUrl,
headers: {
"Cookie": "Set-Cookie: sessionId=38afes7a8",
}
}
In this example, we pass a cookie value in the authorization server header property.
Retrieving Custom Data in Backend
To retrieve the custom data in your backend authorization server endpoint, you can use the following code snippet in C#:
[HttpPost]
[Route("GetDetails")]
public string GetDetails([FromBody] object embedQuerString)
{
bool isHeaderPresent = Request.Headers.ContainsKey("Cookie");
if(isHeaderPresent){
Request.Headers.TryGetValue("Cookie", out var headerValue);
var cookieValue = headerValue;
}
.......
}
In this example, the custom data is stored in the
cookieValue
property.