public async Task Valid_Client()
        {
            var client = new TokenClient(
                TokenEndpoint,
                "client.custom",
                "secret",
                innerHttpMessageHandler: _handler);

            var customParameters = new Dictionary<string, string>
                {
                    { "custom_credential", "custom credential"}
                };

            var response = await client.RequestCustomGrantAsync("custom", "api1", customParameters);

            response.IsError.Should().Be(false);
            response.ExpiresIn.Should().Be(3600);
            response.TokenType.Should().Be("Bearer");
            response.IdentityToken.Should().BeNull();
            response.RefreshToken.Should().BeNull();

            var payload = GetPayload(response);

            payload.Count().Should().Be(10);
            payload.Should().Contain("iss", "https://idsrv4");
            payload.Should().Contain("aud", "https://idsrv4/resources");
            payload.Should().Contain("client_id", "client.custom");
            payload.Should().Contain("scope", "api1");
            payload.Should().Contain("sub", "818727");
            payload.Should().Contain("idp", "idsrv");

            var amr = payload["amr"] as JArray;
            amr.Count().Should().Be(1);
            amr.First().ToString().Should().Be("custom");
        }
        public async Task Valid_Client_Missing_Grant_Specific_Data()
        {
            var client = new TokenClient(
                TokenEndpoint,
                "client.custom",
                "secret",
                innerHttpMessageHandler: _handler);

            var response = await client.RequestCustomGrantAsync("custom", "api1");

            response.IsError.Should().Be(true);
            response.Error.Should().Be("invalid_custom_credential");
        }
        static TokenResponse RequestToken()
        {
            var client = new TokenClient(
                Constants.TokenEndpoint,
                "customgrant.client",
                "secret");

            var customParameters = new Dictionary<string, string>
                {
                    { "custom_credential", "custom credential"}
                };

            return client.RequestCustomGrantAsync("custom", "read write", customParameters).Result;
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var client = new TokenClient(
                "https://localhost:44333/core/connect/token",
                "client",
                "secret");

            var customParams = new Dictionary<string, string>
            {
                { "some_custom_parameter", "some_value" }
            };

            var result = client.RequestCustomGrantAsync("custom", "read", customParams).Result;
            ShowResponse(result);
        }
        static void Main(string[] args)
        {
            var client = new TokenClient(
                "http://localhost:3333/core/connect/token",
                "client",
                "secret");

            var result = client.RequestCustomGrantAsync("legacy_account_store", "read", new Dictionary<string, string>
                {
                    { "account_store", "foo" },
                    { "legacy_id", "bob" },
                    { "legacy_secret", "bob" }
                }).Result;

            ShowResponse(result);
        }
        public string Get()
        {
            TokenClient tokenClient = new TokenClient(
                "http://localhost:44333/connect/token",
                "WebApi1",
                "4B79A70F-3919-435C-B46C-571068F7AF37"
            );

            var caller = User as ClaimsPrincipal;

            var customParams = new Dictionary<string, string>
            {
                { "token", caller.FindFirst("token").Value }
            };

            var tokenResponse = tokenClient.RequestCustomGrantAsync("act-as", "WebApi2", customParams).Result;

            HttpClient client = new HttpClient();
            client.SetBearerToken(tokenResponse.AccessToken);

            return client.GetStringAsync("http://localhost:44335/test").Result;
        }
        public async Task Valid_Client_Unsupported_Grant()
        {
            var client = new TokenClient(
                TokenEndpoint,
                "client.custom",
                "secret",
                innerHttpMessageHandler: _handler);

            var customParameters = new Dictionary<string, string>
                {
                    { "custom_credential", "custom credential"}
                };

            var response = await client.RequestCustomGrantAsync("invalid", "api1", customParameters);

            response.IsError.Should().Be(true);
            response.Error.Should().Be("unsupported_grant_type");
        }