blue-alarm-98979
04/04/2024, 7:20 AMmagnificent-energy-493
loginflow
object that you get from the CreateBrowserLoginFlow()
method. The CSRF token is located in the loginflow.Ui.Nodes
list. You need to find the node with the Name
attribute set to "csrf_token"
and get its Value
attribute.
Here is an example of how you can get the CSRF token:
Configuration config = new Configuration();
config.BasePath = "<base_path>";
var frontendApi = new FrontendApi(config);
var loginflow = frontendApi.CreateBrowserLoginFlow();
var flowId = loginflow.Id;
// Find the CSRF token
string csrfToken = null;
foreach (var node in loginflow.Ui.Nodes)
{
if (node.Name == "csrf_token")
{
csrfToken = node.Value;
break;
}
}
if (csrfToken == null)
{
throw new Exception("CSRF token not found in login flow");
}
KratosUpdateLoginFlowWithPasswordMethod method = new(csrfToken, request.Email, "password", request.Password);
var updateLoginFlowBody = new KratosUpdateLoginFlowBody(method);
KratosSuccessfulNativeLogin result = frontendApi.UpdateLoginFlow(flowId, updateLoginFlowBody);
var session = result.Session;
blue-alarm-98979
04/04/2024, 8:43 AMblue-alarm-98979
04/04/2024, 9:29 AMforeach (var node in loginFlow.Ui.Nodes)
{
if (node.Attributes.ActualInstance is KratosUiNodeInputAttributes inputAttributes)
{
if (inputAttributes.Name == "csrf_token")
{
csrf_token = inputAttributes.Value;
break;
}
}
}
magnificent-energy-493
blue-alarm-98979
04/05/2024, 6:23 AMmagnificent-energy-493