private void SetupGoogleLoginForm(string userName) { string samlRequest = Request.QueryString["SAMLRequest"]; if (samlRequest == null) { samlRequest = Request.Form["SAMLRequest"]; } string relayState = Request.QueryString["RelayState"]; if (relayState == null) { relayState = Request.Form["RelayState"]; } if (samlRequest != null && relayState != null) { string responseXml; string actionUrl; SamlParser.CreateSignedResponse( samlRequest, userName, out responseXml, out actionUrl); this.actionUrl = actionUrl; SAMLResponse.Value = responseXml; RelayState.Value = relayState; } }
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; }
private void SetupGoogleLoginForm(string userName) { string samlRequest = Request.QueryString["SAMLRequest"]; if (samlRequest == null) { samlRequest = Request.Form["SAMLRequest"]; } string relayState = Request.QueryString["RelayState"]; if (relayState == null) { relayState = Request.Form["RelayState"]; } if (samlRequest != null && relayState != null) { XmlDocument samlRequestUnpacked = SamlParser.UnpackRequest(samlRequest); string responseXml; string actionUrl; SamlParser.CreateSignedResponse( samlRequest, userName, out responseXml, out actionUrl); this.actionUrl = actionUrl; LiteralAssertionUrl.Text = actionUrl; TextAreaSamlRequestEncoded.Value = samlRequest; TextAreaSamlRequestDecoded.Value = FormatXml(samlRequestUnpacked); SAMLResponse.Value = responseXml; RelayState.Value = relayState; } }