当前位置: 首页>>代码示例>>C#>>正文


C# TokenClient.RequestCustomGrantAsync方法代码示例

本文整理汇总了C#中IdentityModel.Client.TokenClient.RequestCustomGrantAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TokenClient.RequestCustomGrantAsync方法的具体用法?C# TokenClient.RequestCustomGrantAsync怎么用?C# TokenClient.RequestCustomGrantAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IdentityModel.Client.TokenClient的用法示例。


在下文中一共展示了TokenClient.RequestCustomGrantAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Valid_Client

        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");
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:35,代码来源:CustomGrantClient.cs

示例2: Valid_Client_Missing_Grant_Specific_Data

        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");
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:13,代码来源:CustomGrantClient.cs

示例3: RequestToken

        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;
        }
开发者ID:RobGibbens,项目名称:IdentityServer3.Samples,代码行数:14,代码来源:Program.cs

示例4: Main

        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);
        }
开发者ID:camainc,项目名称:IdentityServer3.Samples,代码行数:15,代码来源:Program.cs

示例5: Main

        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);
        }
开发者ID:RobGibbens,项目名称:IdentityServer3.Samples,代码行数:16,代码来源:Program.cs

示例6: Get

        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;
        }
开发者ID:RobGibbens,项目名称:IdentityServer3.Samples,代码行数:22,代码来源:TestController.cs

示例7: Valid_Client_Unsupported_Grant

        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");
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:18,代码来源:CustomGrantClient.cs


注:本文中的IdentityModel.Client.TokenClient.RequestCustomGrantAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。