public async Task ChallengeSettingState(string userState, string challenge) { var queryValues = new ExpectedQueryValues(DefaultAuthority); var stateDataFormat = new AuthenticationPropertiesFormaterKeyValue(); var properties = new AuthenticationProperties(); if (challenge == ChallengeWithProperties) { properties.Items.Add("item1", Guid.NewGuid().ToString()); } var server = CreateServer(options => { SetOptions(options, DefaultParameters(new string[] { OpenIdConnectParameterNames.State }), queryValues, stateDataFormat); options.AutomaticChallenge = challenge.Equals(ChallengeWithOutContext); options.Events = new OpenIdConnectEvents() { OnRedirectToAuthenticationEndpoint = context => { context.ProtocolMessage.State = userState; context.ProtocolMessage.RedirectUri = queryValues.RedirectUri; return(Task.FromResult <object>(null)); } }; }, null, properties); var transaction = await SendAsync(server, DefaultHost + challenge); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); if (challenge != ChallengeWithProperties) { if (userState != null) { properties.Items.Add(OpenIdConnectDefaults.UserstatePropertiesKey, userState); } properties.Items.Add(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey, queryValues.RedirectUri); } queryValues.State = stateDataFormat.Protect(properties); queryValues.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, DefaultParameters(new string[] { OpenIdConnectParameterNames.State })); }
public async Task ChallengeWillSetDefaults() { var stateDataFormat = new AuthenticationPropertiesFormaterKeyValue(); var queryValues = ExpectedQueryValues.Defaults(DefaultAuthority); queryValues.State = OpenIdConnectAuthenticationDefaults.AuthenticationPropertiesKey + "=" + stateDataFormat.Protect(new AuthenticationProperties()); var server = CreateServer(options => { SetOptions(options, DefaultParameters(), queryValues); }); var transaction = await SendAsync(server, DefaultHost + Challenge); transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect); queryValues.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, DefaultParameters()); }