using System.Threading.Tasks;
using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine(GetAntiforgeryTokenAsync(default).Result);
public static Task<string> GetAntiforgeryTokenAsync(CancellationToken cancellationToken)
cancellationToken.ThrowIfCancellationRequested();
return GetAntiforgeryTokenAsyncInternal(cancellationToken);
private static async Task<string> GetAntiforgeryTokenAsyncInternal(CancellationToken cancellationToken)
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (_, __, ___, s) => true;
handler.AllowAutoRedirect = true;
using HttpClient client = new HttpClient(handler);
using HttpRequestMessage request = new HttpRequestMessage();
request.Method = HttpMethod.Get;
request.RequestUri = new Uri("https://passport.secib.fr/Account/Login?ReturnUrl=%2Fpassword%2Fchange");
using HttpResponseMessage response = await client.SendAsync(request);
if(!response.IsSuccessStatusCode)
throw new InvalidOperationException("Cannot get antiforgery token");
string body = await response.Content.ReadAsStringAsync();
Match match = Regex.Match(body, "<input name=\"__RequestVerificationToken\" type=\"hidden\" value=\"([^\"]*)\">");
Console.WriteLine(match.Groups.Count);