本文整理汇总了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");
}
示例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");
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}