コード例 #1
0
        public async Task ChallengeWillSetDefaults()
        {
            var stateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
            var queryValues = ExpectedQueryValues.Defaults(DefaultAuthority);
            queryValues.State = OpenIdConnectDefaults.AuthenticationPropertiesKey + "=" + stateDataFormat.Protect(new AuthenticationProperties());
            var server = CreateServer(GetOptions(DefaultParameters(), queryValues));

            var transaction = await SendAsync(server, DefaultHost + Challenge);
            Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode);
            queryValues.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, DefaultParameters());
        }
コード例 #2
0
        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 }));
        }