public async Task LoginAsync() { if (_pending) { throw new InvalidOperationException(); } _pending = true; // load webpage and redirect first var postUri = (await _client.GetAsync(Urls.MyTritonLink)).RequestMessage.RequestUri; var content = new FormUrlEncodedContent(new[] { new Value("urn:mace:ucsd.edu:sso:username", _user), new Value("urn:mace:ucsd.edu:sso:password", _password.ToUnsecureString()), new Value("_eventId_proceed", "") }); // parse the saml form var samlResponse = await _client.PostAsync(postUri, content); var parser = new SamlParser(await samlResponse.Content.ReadAsStreamAsync()); var(target, values) = await parser.ParseAsync(); if (!target.IsAbsoluteUri) { target = new Uri(new Uri(postUri.GetLeftPart(UriPartial.Authority)), target); } // post saml values and then we should be logged in content = new FormUrlEncodedContent(values); await _client.PostAsync(target, content); // todo validate whether any error occurred _pending = false; }