public void Missing_default_parameters_can_be_set_by_extra_parameters()
        {
            var options = new OidcClientOptions
            {
                ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
                Flow         = OidcClientOptions.AuthenticationFlow.Hybrid
            };

            var extra = new Dictionary <string, string>
            {
                { "client_id", "client_id2" },
                { "scope", "openid extra" },
                { "redirect_uri", "http://redirect2" }
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", extra);

            parameters.Should().Contain("client_id", "client_id2");
            parameters.Should().Contain("scope", "openid extra");
            parameters.Should().Contain("redirect_uri", "http://redirect2");

            parameters.Should().Contain("response_type", "code id_token");
            parameters.Should().Contain("response_mode", "form_post");

            parameters.Should().Contain("state", "state");
            parameters.Should().Contain("nonce", "nonce");
            parameters.Should().Contain("code_challenge", "code_challenge");
        }
        public void Missing_default_parameters_can_be_set_by_extra_parameters()
        {
            var options = new OidcClientOptions();

            var frontChannel = new Parameters
            {
                { "resource", "urn:resource1" },
                { "resource", "urn:resource2" },

                { "client_id", "client_id2" },
                { "scope", "openid extra" },
                { "redirect_uri", "http://redirect2" }
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", frontChannel);

            parameters.Should().HaveCount(10);
            parameters.GetValues("client_id").Single().Should().Be("client_id2");
            parameters.GetValues("scope").Single().Should().Be("openid extra");
            parameters.GetValues("redirect_uri").Single().Should().Be("http://redirect2");
            parameters.GetValues("response_type").Single().Should().Be("code");
            parameters.GetValues("state").Single().Should().Be("state");
            parameters.GetValues("nonce").Single().Should().Be("nonce");
            parameters.GetValues("code_challenge").Single().Should().Be("code_challenge");
            parameters.GetValues("code_challenge_method").Single().Should().Be("S256");

            var resources = parameters.GetValues("resource").ToList();

            resources.Should().HaveCount(2);
            resources[0].Should().Be("urn:resource1");
            resources[1].Should().Be("urn:resource2");
        }
        public void Default_parameters_should_be_used_for_authorize_request()
        {
            var options = new OidcClientOptions
            {
                ClientId    = "client_id",
                Scope       = "openid",
                RedirectUri = "http://redirect",

                ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
                Flow         = OidcClientOptions.AuthenticationFlow.Hybrid
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", null);

            parameters.Should().Contain("client_id", "client_id");
            parameters.Should().Contain("scope", "openid");
            parameters.Should().Contain("redirect_uri", "http://redirect");

            parameters.Should().Contain("response_type", "code id_token");
            parameters.Should().Contain("response_mode", "form_post");

            parameters.Should().Contain("state", "state");
            parameters.Should().Contain("nonce", "nonce");
            parameters.Should().Contain("code_challenge", "code_challenge");
        }
        public void Default_parameters_should_be_used_for_authorize_request()
        {
            var options = new OidcClientOptions
            {
                ClientId    = "client_id",
                Scope       = "openid",
                Resource    = { "urn:resource1", "urn:resource2" },
                RedirectUri = "http://redirect"
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", null);

            parameters.Should().HaveCount(10);
            parameters.GetValues("client_id").Single().Should().Be("client_id");
            parameters.GetValues("scope").Single().Should().Be("openid");
            parameters.GetValues("resource").First().Should().Be("urn:resource1");
            parameters.GetValues("resource").Skip(1).First().Should().Be("urn:resource2");
            parameters.GetValues("redirect_uri").Single().Should().Be("http://redirect");
            parameters.GetValues("response_type").Single().Should().Be("code");
            parameters.GetValues("state").Single().Should().Be("state");
            parameters.GetValues("nonce").Single().Should().Be("nonce");
            parameters.GetValues("code_challenge").Single().Should().Be("code_challenge");
            parameters.GetValues("code_challenge_method").Single().Should().Be("S256");
        }
示例#5
0
        public void Extra_parameters_should_override_default_parameters()
        {
            var options = new OidcClientOptions
            {
                ClientId    = "client_id",
                Scope       = "openid",
                RedirectUri = "http://redirect"
            };

            var frontChannel = new FrontChannelParameters
            {
                Extra = new Parameters
                {
                    { "client_id", "client_id2" },
                    { "scope", "openid extra" },
                    { "redirect_uri", "http://redirect2" }
                }
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", frontChannel);

            parameters.Should().Contain("client_id", "client_id2");
            parameters.Should().Contain("scope", "openid extra");
            parameters.Should().Contain("redirect_uri", "http://redirect2");
            parameters.Should().Contain("response_type", "code");
            parameters.Should().Contain("state", "state");
            parameters.Should().Contain("nonce", "nonce");
            parameters.Should().Contain("code_challenge", "code_challenge");
        }
        public void extra_parameters_should_override_default_parameters()
        {
            var options = new OidcClientOptions
            {
                ClientId    = "client_id",
                Scope       = "openid",
                RedirectUri = "http://redirect",

                ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
                Flow         = OidcClientOptions.AuthenticationFlow.Hybrid
            };

            var extra = new
            {
                client_id    = "client_id2",
                scope        = "openid extra",
                redirect_uri = "http://redirect2"
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", extra);

            parameters.Should().Contain("client_id", "client_id2");
            parameters.Should().Contain("scope", "openid extra");
            parameters.Should().Contain("redirect_uri", "http://redirect2");

            parameters.Should().Contain("response_type", "code id_token");
            parameters.Should().Contain("response_mode", "form_post");

            parameters.Should().Contain("state", "state");
            parameters.Should().Contain("nonce", "nonce");
            parameters.Should().Contain("code_challenge", "code_challenge");
        }
        public void Default_parameters_should_be_used_for_authorize_request()
        {
            var options = new OidcClientOptions
            {
                ClientId    = "client_id",
                Scope       = "openid",
                RedirectUri = "http://redirect"
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", null);

            parameters.Should().Contain("client_id", "client_id");
            parameters.Should().Contain("scope", "openid");
            parameters.Should().Contain("redirect_uri", "http://redirect");
            parameters.Should().Contain("response_type", "code");
            parameters.Should().Contain("state", "state");
            parameters.Should().Contain("nonce", "nonce");
            parameters.Should().Contain("code_challenge", "code_challenge");
        }
        public void Missing_default_parameters_can_be_set_by_extra_parameters()
        {
            var options = new OidcClientOptions();

            var extra = new Dictionary <string, string>
            {
                { "client_id", "client_id2" },
                { "scope", "openid extra" },
                { "redirect_uri", "http://redirect2" }
            };

            var client     = new AuthorizeClient(options);
            var parameters = client.CreateAuthorizeParameters("state", "nonce", "code_challenge", extra);

            parameters.Should().Contain("client_id", "client_id2");
            parameters.Should().Contain("scope", "openid extra");
            parameters.Should().Contain("redirect_uri", "http://redirect2");
            parameters.Should().Contain("response_type", "code");
            parameters.Should().Contain("state", "state");
            parameters.Should().Contain("nonce", "nonce");
            parameters.Should().Contain("code_challenge", "code_challenge");
        }