本文整理汇总了C#中Kentor.AuthServices.WebSso.HttpRequestData类的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestData类的具体用法?C# HttpRequestData怎么用?C# HttpRequestData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestData类属于Kentor.AuthServices.WebSso命名空间,在下文中一共展示了HttpRequestData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpRequestData_Ctor_Deserialize_StoredRequestState
public void HttpRequestData_Ctor_Deserialize_StoredRequestState()
{
var url = new Uri("http://example.com:42/ApplicationPath/Path?RelayState=Foo");
string appPath = "/ApplicationPath";
var storedRequestData = new StoredRequestState(
new EntityId("http://idp.example.com"),
new Uri("http://sp.example.com/loggedout"),
new Saml2Id("id123"),
null);
var cookies = new KeyValuePair<string, string>[]
{
new KeyValuePair<string, string>(
"Kentor.Foo",
HttpRequestData.ConvertBinaryData(
StubDataProtector.Protect(storedRequestData.Serialize())))
};
var subject = new HttpRequestData(
"GET",
url,
appPath,
Enumerable.Empty<KeyValuePair<string, string[]>>(),
cookies,
StubDataProtector.Unprotect);
subject.StoredRequestState.ShouldBeEquivalentTo(storedRequestData);
}
示例2: Run
public CommandResult Run(HttpRequestData request, IOptions options)
{
return new CommandResult()
{
HttpStatusCode = HttpStatusCode.NotFound
};
}
示例3: Run
public static CommandResult Run(
HttpRequestData request,
string returnPath,
IOptions options)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
var binding = Saml2Binding.Get(request);
if (binding != null)
{
var unbindResult = binding.Unbind(request, options);
VerifyMessageIsSigned(unbindResult, options);
switch (unbindResult.Data.LocalName)
{
case "LogoutRequest":
return HandleRequest(unbindResult, options);
case "LogoutResponse":
return HandleResponse(unbindResult, request);
default:
throw new NotImplementedException();
}
}
return InitiateLogout(request, returnPath, options);
}
示例4: Unbind
public override UnbindResult Unbind(HttpRequestData request, IOptions options)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var payload = Convert.FromBase64String(request.QueryString["SAMLRequest"].First());
using (var compressed = new MemoryStream(payload))
{
using (var decompressedStream = new DeflateStream(compressed, CompressionMode.Decompress, true))
{
using (var deCompressed = new MemoryStream())
{
decompressedStream.CopyTo(deCompressed);
var xml = new XmlDocument()
{
PreserveWhitespace = true
};
xml.LoadXml(Encoding.UTF8.GetString(deCompressed.GetBuffer()));
return new UnbindResult(
xml.DocumentElement,
request.QueryString["RelayState"].SingleOrDefault());
}
}
}
}
示例5: LogoutCommand_Run_ReturnsLogoutRequest
public void LogoutCommand_Run_ReturnsLogoutRequest()
{
Thread.CurrentPrincipal = new ClaimsPrincipal(
new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.NameIdentifier, "NameId", null, "https://idp.example.com"),
new Claim(AuthServicesClaimTypes.SessionIndex, "SessionId", null, "https://idp.example.com")
}, "Federation"));
var request = new HttpRequestData("GET", new Uri("http://sp-internal.example.com/AuthServices/Logout"));
var options = StubFactory.CreateOptions();
options.SPOptions.ServiceCertificates.Add(SignedXmlHelper.TestCert);
((SPOptions)(options.SPOptions)).PublicOrigin = new Uri("https://sp.example.com/");
var actual = CommandFactory.GetCommand(CommandFactory.LogoutCommandName)
.Run(request, options);
var expected = new CommandResult
{
HttpStatusCode = HttpStatusCode.SeeOther,
TerminateLocalSession = true,
// Deliberately not comparing Location.
// Deliberately not comparing SetCookieName.
SetCookieData = "https://sp.example.com/"
};
actual.ShouldBeEquivalentTo(expected, opt => opt
.Excluding(cr => cr.Location)
.Excluding(cr => cr.SetCookieName));
var relayState = HttpUtility.ParseQueryString(actual.Location.Query)["RelayState"];
actual.SetCookieName.Should().Be("Kentor." + relayState);
actual.Location.GetLeftPart(UriPartial.Path).Should().Be("https://idp.example.com/logout");
}
示例6: HttpRequestBaseExtensions_ToHttpRequestData
public void HttpRequestBaseExtensions_ToHttpRequestData()
{
var url = new Uri("http://example.com:42/ApplicationPath/Path?RelayState=SomeState");
string appPath = "/ApplicationPath";
var request = Substitute.For<HttpRequestBase>();
request.HttpMethod.Returns("GET");
request.Url.Returns(url);
request.Form.Returns(new NameValueCollection { { "Key", "Value" } });
request.ApplicationPath.Returns(appPath);
var cookieValue = HttpRequestData.ConvertBinaryData(
MachineKey.Protect(
new StoredRequestState(null, new Uri("urn:someUri"), null, null).Serialize(),
HttpRequestBaseExtensions.ProtectionPurpose));
request.Cookies.Returns(new HttpCookieCollection());
request.Cookies.Add(new HttpCookie("Kentor.SomeState", cookieValue));
var actual = request.ToHttpRequestData();
var expected = new HttpRequestData(
"GET",
url,
appPath,
new KeyValuePair<string, string[]>[]
{
new KeyValuePair<string, string[]>("Key", new string[] { "Value" })
},
Enumerable.Empty<KeyValuePair<string, string>>(),
null);
actual.ShouldBeEquivalentTo(expected, opt => opt.Excluding(s => s.StoredRequestState));
actual.StoredRequestState.ReturnUrl.AbsoluteUri.Should().Be("urn:someUri");
}
示例7: HttpRequestBaseExtensions_ToHttpRequestData
public void HttpRequestBaseExtensions_ToHttpRequestData()
{
var url = new Uri("http://example.com:42/ApplicationPath/Path?RelayState=SomeState");
string appPath = "/ApplicationPath";
var request = Substitute.For<HttpRequestBase>();
request.HttpMethod.Returns("GET");
request.Url.Returns(url);
request.Form.Returns(new NameValueCollection { { "Key", "Value" } });
request.ApplicationPath.Returns(appPath);
var cookieValue = HttpRequestData.EscapeBase64CookieValue(Convert.ToBase64String(
MachineKey.Protect(Encoding.UTF8.GetBytes("CookieValue"), "Kentor.AuthServices")));
request.Cookies.Returns(new HttpCookieCollection());
request.Cookies.Add(new HttpCookie("Kentor.SomeState", cookieValue));
var subject = request.ToHttpRequestData();
var expected = new HttpRequestData(
"GET",
url,
appPath,
new KeyValuePair<string, string[]>[]
{
new KeyValuePair<string, string[]>("Key", new string[] { "Value" })
},
Enumerable.Empty<KeyValuePair<string, string>>(),
null);
subject.ShouldBeEquivalentTo(expected, opt => opt.Excluding(s => s.CookieData));
subject.CookieData.Should().Be("CookieValue");
}
示例8: MetadataCommand_Run_CallsNotifications
public void MetadataCommand_Run_CallsNotifications()
{
var request = new HttpRequestData("GET", new Uri("http://localhost/AuthServices"));
var options = StubFactory.CreateOptions();
options.Notifications.MetadataCreated = (md, urls) =>
{
md.CacheDuration = new TimeSpan(0, 0, 17);
urls.ApplicationUrl.Host.Should().Be("localhost");
};
CommandResult notifiedCommandResult = null;
options.Notifications.MetadataCommandResultCreated = cr =>
{
notifiedCommandResult = cr;
};
var subject = new MetadataCommand();
var actualCommandResult = subject.Run(request, options);
actualCommandResult.Should().BeSameAs(notifiedCommandResult);
var parsedResult = XElement.Parse(actualCommandResult.Content);
parsedResult.Attribute("cacheDuration").Value
.Should().Be("PT17S");
}
示例9: Unbind
public override UnbindResult Unbind(HttpRequestData request, IOptions options)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var xmlDoc = new XmlDocument()
{
PreserveWhitespace = true
};
string encodedMessage;
if (!request.Form.TryGetValue("SAMLResponse", out encodedMessage))
{
encodedMessage = request.Form["SAMLRequest"];
}
xmlDoc.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(encodedMessage)));
string relayState = null;
request.Form.TryGetValue("RelayState", out relayState);
return new UnbindResult(xmlDoc.DocumentElement, relayState, TrustLevel.None);
}
示例10: Saml2ArtifactBinding_Unbind_FromGet
public void Saml2ArtifactBinding_Unbind_FromGet()
{
var issuer = new EntityId("https://idp.example.com");
var artifact = Uri.EscapeDataString(
Convert.ToBase64String(
Saml2ArtifactBinding.CreateArtifact(issuer, 0x1234)));
var relayState = MethodBase.GetCurrentMethod().Name;
PrepareArtifactState(relayState, issuer);
var r = new HttpRequestData(
"GET",
new Uri($"http://example.com/path/acs?SAMLart={artifact}&RelayState={relayState}"));
StubServer.LastArtifactResolutionSoapActionHeader = null;
var result = Saml2Binding.Get(Saml2BindingType.Artifact).Unbind(r, StubFactory.CreateOptions());
var xmlDocument = new XmlDocument() { PreserveWhitespace = true };
xmlDocument.LoadXml("<message> <child-node /> </message>");
var expected = new UnbindResult(xmlDocument.DocumentElement, relayState, TrustLevel.None);
result.ShouldBeEquivalentTo(expected);
StubServer.LastArtifactResolutionSoapActionHeader.Should().Be(
"http://www.oasis-open.org/committees/security");
StubServer.LastArtifactResolutionWasSigned.Should().BeFalse();
}
示例11: AcsCommand_Run_CallsNotifications
public void AcsCommand_Run_CallsNotifications()
{
var messageId = MethodBase.GetCurrentMethod().Name;
var response =
@"<saml2p:Response xmlns:saml2p=""urn:oasis:names:tc:SAML:2.0:protocol""
xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
ID = """ + messageId + @""" Version=""2.0"" IssueInstant=""2013-01-01T00:00:00Z"">
<saml2:Issuer>
https://idp.example.com
</saml2:Issuer>
<saml2p:Status>
<saml2p:StatusCode Value=""urn:oasis:names:tc:SAML:2.0:status:Success"" />
</saml2p:Status>
<saml2:Assertion
Version=""2.0"" ID=""" + messageId + @"_Assertion""
IssueInstant=""2013-09-25T00:00:00Z"">
<saml2:Issuer>https://idp.example.com</saml2:Issuer>
<saml2:Subject>
<saml2:NameID>SomeUser</saml2:NameID>
<saml2:SubjectConfirmation Method=""urn:oasis:names:tc:SAML:2.0:cm:bearer"" />
</saml2:Subject>
<saml2:Conditions NotOnOrAfter=""2100-01-01T00:00:00Z"" />
</saml2:Assertion>
</saml2p:Response>";
var formValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(
SignedXmlHelper.SignXml(response)));
var requestData = new HttpRequestData(
"POST",
new Uri("http://localhost"),
"/ModulePath",
new KeyValuePair<string, string[]>[]
{
new KeyValuePair<string, string[]>("SAMLResponse", new string[] { formValue })
},
null);
var options = StubFactory.CreateOptions();
var responseUnboundCalled = false;
options.Notifications.MessageUnbound = ur =>
{
ur.Should().NotBeNull();
responseUnboundCalled = true;
};
CommandResult notifiedCommandResult = null;
options.Notifications.AcsCommandResultCreated = (cr, r) =>
{
notifiedCommandResult = cr;
r.Id.Value.Should().Be(messageId);
};
new AcsCommand().Run(requestData, options)
.Should().BeSameAs(notifiedCommandResult);
responseUnboundCalled.Should().BeTrue("the ResponseUnbound notification should have been called.");
}
示例12: Run
public CommandResult Run(HttpRequestData request, IOptions options)
{
if(request == null)
{
throw new ArgumentNullException(nameof(request));
}
if(options == null)
{
throw new ArgumentNullException(nameof(options));
}
var binding = Saml2Binding.Get(request);
if (binding != null)
{
UnbindResult unbindResult = null;
try
{
unbindResult = binding.Unbind(request, options);
var samlResponse = new Saml2Response(unbindResult.Data, request.StoredRequestState?.MessageId);
var result = ProcessResponse(options, samlResponse, request.StoredRequestState);
if(unbindResult.RelayState != null)
{
result.ClearCookieName = "Kentor." + unbindResult.RelayState;
}
return result;
}
catch (FormatException ex)
{
throw new BadFormatSamlResponseException(
"The SAML Response did not contain valid BASE64 encoded data.", ex);
}
catch (XmlException ex)
{
var newEx = new BadFormatSamlResponseException(
"The SAML response contains incorrect XML", ex);
// Add the payload to the exception
if (unbindResult != null)
{
newEx.Data["Saml2Response"] = unbindResult.Data.OuterXml;
}
throw newEx;
}
catch (Exception ex)
{
if (unbindResult != null)
{
// Add the payload to the existing exception
ex.Data["Saml2Response"] = unbindResult.Data.OuterXml;
}
throw;
}
}
throw new NoSamlResponseFoundException();
}
示例13: Saml2Binding_Get_ReturnsSaml2Artifact_ForArtifactInUrl
public void Saml2Binding_Get_ReturnsSaml2Artifact_ForArtifactInUrl()
{
var r = new HttpRequestData(
"GET",
new Uri("http://example.com/ModulePath/Acs?SAMLart=ABCD"));
Saml2Binding.Get(r).Should().BeOfType<Saml2ArtifactBinding>();
}
示例14: SignInCommand_Run_With_InvalidIdp_ThrowsException
public void SignInCommand_Run_With_InvalidIdp_ThrowsException()
{
var request = new HttpRequestData("GET", new Uri("http://localhost/signin?idp=no-such-idp-in-config"));
Action a = () => new SignInCommand().Run(request, Options.FromConfiguration);
a.ShouldThrow<InvalidOperationException>().WithMessage("Unknown idp");
}
示例15: Run
public CommandResult Run(HttpRequestData request, IOptions options)
{
if(request == null)
{
throw new ArgumentNullException("request");
}
if(options == null)
{
throw new ArgumentNullException("options");
}
var binding = Saml2Binding.Get(request);
if (binding != null)
{
string unpackedPayload = null;
try
{
unpackedPayload = binding.Unbind(request);
var samlResponse = Saml2Response.Read(unpackedPayload);
var relayStates = request.Form.First(x => string.Compare(x.Key, "RelayState", StringComparison.OrdinalIgnoreCase) == 0);
string returnURL = string.Empty;
returnURL = relayStates.Value;
/* foreach(var state in relayStates)
{
returnURL = state;
break;
}
*/
return ProcessResponse(options, samlResponse, returnURL);
}
catch (FormatException ex)
{
throw new BadFormatSamlResponseException(
"The SAML Response did not contain valid BASE64 encoded data.", ex);
}
catch (XmlException ex)
{
var newEx = new BadFormatSamlResponseException(
"The SAML response contains incorrect XML", ex);
// Add the payload to the exception
newEx.Data["Saml2Response"] = unpackedPayload;
throw newEx;
}
catch (Exception ex)
{
// Add the payload to the existing exception
ex.Data["Saml2Response"] = unpackedPayload;
throw;
}
}
throw new NoSamlResponseFoundException();
}