本文整理汇总了C#中IdentityModel.Client.TokenClient类的典型用法代码示例。如果您正苦于以下问题:C# TokenClient类的具体用法?C# TokenClient怎么用?C# TokenClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenClient类属于IdentityModel.Client命名空间,在下文中一共展示了TokenClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var tokenClient = new TokenClient(
"http://localhost:18942/connect/token",
"test",
"secret");
//This responds with the token for the "api" scope, based on the username/password above
var response = tokenClient.RequestClientCredentialsAsync("api1").Result;
//Test area to show api/values is protected
//Should return that the request is unauthorized
try
{
var unTokenedClient = new HttpClient();
var unTokenedClientResponse = unTokenedClient.GetAsync("http://localhost:19806/api/values").Result;
Console.WriteLine("Un-tokened response: {0}", unTokenedClientResponse.StatusCode);
}
catch (Exception ex)
{
Console.WriteLine("Exception of: {0} while calling api without token.", ex.Message);
}
//Now we make the same request with the token received by the auth service.
var client = new HttpClient();
client.SetBearerToken(response.AccessToken);
var apiResponse = client.GetAsync("http://localhost:19806/identity").Result;
var callApiResponse = client.GetAsync("http://localhost:19806/api/values").Result;
Console.WriteLine("Tokened response: {0}", callApiResponse.StatusCode);
Console.WriteLine(callApiResponse.Content.ReadAsStringAsync().Result);
Console.Read();
}
开发者ID:dkaminski,项目名称:IdentityServer3.Samples,代码行数:34,代码来源:Program.cs
示例2: 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
示例3: Valid_Client_Multiple_Scopes
public async Task Valid_Client_Multiple_Scopes()
{
var client = new TokenClient(
TokenEndpoint,
"client",
"secret",
innerHttpMessageHandler: _handler);
var response = await client.RequestClientCredentialsAsync("api1 api2");
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(6);
payload.Should().Contain("iss", "https://idsrv4");
payload.Should().Contain("aud", "https://idsrv4/resources");
payload.Should().Contain("client_id", "client");
var scopes = payload["scope"] as JArray;
scopes.Count().Should().Be(2);
scopes.First().ToString().Should().Be("api1");
scopes.Skip(1).First().ToString().Should().Be("api2");
}
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:28,代码来源:ClientCredentialsClient.cs
示例4: Token_endpoint_supports_client_authentication_with_basic_authentication_with_POST
public async Task Token_endpoint_supports_client_authentication_with_basic_authentication_with_POST()
{
await _pipeline.LoginAsync("bob");
var nonce = Guid.NewGuid().ToString();
_pipeline.BrowserClient.AllowAutoRedirect = false;
var url = _pipeline.CreateAuthorizeUrl(
clientId: "code_pipeline.Client",
responseType: "code",
scope: "openid",
redirectUri: "https://code_pipeline.Client/callback?foo=bar&baz=quux",
nonce: nonce);
var response = await _pipeline.BrowserClient.GetAsync(url);
var authorization = _pipeline.ParseAuthorizationResponseUrl(response.Headers.Location.ToString());
authorization.Code.Should().NotBeNull();
var code = authorization.Code;
// backchannel client
var wrapper = new MessageHandlerWrapper(_pipeline.Handler);
var tokenClient = new TokenClient(MockAuthorizationPipeline.TokenEndpoint, "code_pipeline.Client", "secret", wrapper);
var tokenResult = await tokenClient.RequestAuthorizationCodeAsync(code, "https://code_pipeline.Client/callback?foo=bar&baz=quux");
tokenResult.IsError.Should().BeFalse();
tokenResult.IsHttpError.Should().BeFalse();
tokenResult.TokenType.Should().Be("Bearer");
tokenResult.AccessToken.Should().NotBeNull();
tokenResult.ExpiresIn.Should().BeGreaterThan(0);
tokenResult.IdentityToken.Should().NotBeNull();
wrapper.Response.Headers.CacheControl.NoCache.Should().BeTrue();
wrapper.Response.Headers.CacheControl.NoStore.Should().BeTrue();
}
开发者ID:RightNowMinistries,项目名称:IdentityServer4,代码行数:35,代码来源:ClientAuthenticationTests.cs
示例5: RequestAccessTokenClientCredentials
/// <summary>
/// request ID server for a token using the ClientId and secret
/// </summary>
/// <returns>An access token in string format</returns>
private static string RequestAccessTokenClientCredentials(string clientId,string secret)
{
// did we store the token before?
var cookie = HttpContext.Current.Request.Cookies.Get("TripGalleryCookie");
if (cookie != null && cookie["access_token"] != null)
{
return cookie["access_token"];
}
// no token found - get one
// create an oAuth2 Client
var oAuth2Client = new TokenClient(
TripGallery.Constants.TripGallerySTSTokenEndpoint,
clientId,
secret);
// ask for a token, containing the gallerymanagement scope
var tokenResponse = oAuth2Client.RequestClientCredentialsAsync("gallerymanagement").Result;
// decode & write out the token, so we can see what's in it
// TokenHelper.DecodeAndWrite(tokenResponse.AccessToken);
// we save the token in a cookie for use later on
HttpContext.Current.Response.Cookies["TripGalleryCookie"]["access_token"] = tokenResponse.AccessToken;
// return the token
return tokenResponse.AccessToken;
}
开发者ID:francis04j,项目名称:TripGallery,代码行数:33,代码来源:GalleryHttpClient.cs
示例6: Valid_User_IdentityScopes
public async Task Valid_User_IdentityScopes()
{
var client = new TokenClient(
TokenEndpoint,
"roclient",
"secret",
innerHttpMessageHandler: _handler);
var response = await client.RequestResourceOwnerPasswordAsync("bob", "bob", "openid email api1");
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://idsrv3");
payload.Should().Contain("aud", "https://idsrv3/resources");
payload.Should().Contain("client_id", "roclient");
payload.Should().Contain("sub", "88421113");
payload.Should().Contain("idp", "idsrv");
var amr = payload["amr"] as JArray;
amr.Count().Should().Be(1);
amr.First().ToString().Should().Be("password");
var scopes = payload["scope"] as JArray;
scopes.Count().Should().Be(3);
scopes.First().ToString().Should().Be("api1");
scopes.Skip(1).First().ToString().Should().Be("email");
scopes.Skip(2).First().ToString().Should().Be("openid");
}
开发者ID:Rolosoft,项目名称:IdentityServer3,代码行数:35,代码来源:ResourceOwnerClient.cs
示例7: GetToken
public async Task<ActionResult> GetToken()
{
var client = new TokenClient(
Constants.TokenEndpoint,
"codeclient",
"secret");
var code = Request.QueryString["code"];
var tempState = await GetTempStateAsync();
Request.GetOwinContext().Authentication.SignOut("TempState");
var response = await client.RequestAuthorizationCodeAsync(
code,
"https://localhost:44312/callback");
await ValidateResponseAndSignInAsync(response, tempState.Item2);
if (!string.IsNullOrEmpty(response.IdentityToken))
{
ViewBag.IdentityTokenParsed = ParseJwt(response.IdentityToken);
}
if (!string.IsNullOrEmpty(response.AccessToken))
{
ViewBag.AccessTokenParsed = ParseJwt(response.AccessToken);
}
return View("Token", response);
}
开发者ID:RobGibbens,项目名称:IdentityServer3.Samples,代码行数:28,代码来源:CallbackController.cs
示例8: RequestAccessTokenClientCredentials
private static string RequestAccessTokenClientCredentials()
{
//did we store the token before?
var cookie = HttpContext.Current.Request.Cookies.Get("tripGalleryCookie");
if (cookie != null && cookie["access_token"] != null)
{
return cookie["access_token"];
}
var tokenClient = new TokenClient(
TripGallery.Constants.TripGallerySTSTokenEndpoint,
"tripgalleryclientcredentials",
TripGallery.Constants.TripGalleryClientSecret
);
var tokenResponse = tokenClient.RequestClientCredentialsAsync("gallerymanagement").Result;
//just to debug
TokenHelper.DecodeAndWrite(tokenResponse.AccessToken);
//save token in a cookie
HttpContext.Current.Response.Cookies["TripGalleryCookie"]["access_token"] = tokenResponse.AccessToken;
return tokenResponse.AccessToken;
}
开发者ID:thekane,项目名称:identity-server-3-samples,代码行数:33,代码来源:TripGalleryHttpClient.cs
示例9: GetTokenAsync
/// <summary>
/// Busca o token de acesso no IdentityServer para ser utilizado na API.
/// </summary>
/// <returns></returns>
private async Task<TokenResponse> GetTokenAsync()
{
var client = new TokenClient("https://localhost:44302/identity/connect/token"
, "mvc_service"
, "secret");
return await client.RequestClientCredentialsAsync("gac_erp_appservice");
}
开发者ID:gacalves,项目名称:GAC_ERP,代码行数:11,代码来源:CallApiController.cs
示例10: Main
static void Main(string[] args)
{
_tokenClient = new TokenClient(
Constants.TokenEndpoint,
"roclient",
"secret");
var response = RequestToken();
ShowResponse(response);
Console.ReadLine();
var refresh_token = response.RefreshToken;
while (true)
{
response = RefreshToken(refresh_token);
ShowResponse(response);
Console.ReadLine();
CallService(response.AccessToken);
if (response.RefreshToken != refresh_token)
{
refresh_token = response.RefreshToken;
}
}
}
开发者ID:ryanmar,项目名称:IdentityServer3.Samples,代码行数:28,代码来源:Program.cs
示例11: RequestToken
private async static Task<string> RequestToken()
{
var tokenClient = new TokenClient("https://localhost:44302/connect/token", "ConsoleClient", "secret");
var response = await tokenClient.RequestClientCredentialsAsync("Api");
return response.AccessToken;
}
开发者ID:robinvanderknaap,项目名称:SkaeleAuthorizationServer,代码行数:8,代码来源:Program.cs
示例12: GetToken
static TokenResponse GetToken(string tokenUrl, string clientId, string secret, string scope, string username = null, string password = null)
{
var client = new TokenClient(tokenUrl, clientId, secret);
if (string.IsNullOrWhiteSpace(username)||string.IsNullOrWhiteSpace(password))
return client.RequestClientCredentialsAsync(scope).Result;
else
return client.RequestResourceOwnerPasswordAsync(username, password, scope).Result;
}
开发者ID:mequanta,项目名称:Janitor-old,代码行数:8,代码来源:Program.cs
示例13: GetClientToken
public static TokenResponse GetClientToken()
{
var client = new TokenClient("https://localhost:44333/connect/token", "carbon",
"21B5F798-BE55-42BC-8AA8-0025B903DC3B");
//return client.RequestClientCredentialsAsync("LeagueComparer").Result;
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "LeagueComparer").Result;
}
开发者ID:NasC0,项目名称:LeagueComparer,代码行数:8,代码来源:Program.cs
示例14: GetClientToken
static TokenResponse GetClientToken()
{
var client = new TokenClient("https://localhost:44333/connect/token",
"freightshare1",
"IIPiBTywUcK5Qv0kvmVXbSiax5wBStDMGTAIA0T/RSM=");
return client.RequestClientCredentialsAsync("api1").Result;
}
开发者ID:okusnadi,项目名称:oauth2-simple,代码行数:8,代码来源:Program.cs
示例15: GetClientToken
static TokenResponse GetClientToken()
{
var client = new TokenClient(
"https://100.105.80.38:13855/connect/token",
"silicon",
"F621F470-9731-4A25-80EF-67A6F7C5F4B8");
return client.RequestClientCredentialsAsync("api1").Result;
}
开发者ID:tonyeung,项目名称:IdSvr3AndKentorAuthServices,代码行数:8,代码来源:Program.cs
示例16: GetToken
static TokenResponse GetToken()
{
var client = new TokenClient(
"http://localhost:44333/connect/token",
"ConsoleApplication",
"F621F470-9731-4A25-80EF-67A6F7C5F4B8");
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "WebApi1").Result;
}
开发者ID:camainc,项目名称:IdentityServer3.Samples,代码行数:9,代码来源:Program.cs
示例17: RequestToken
static TokenResponse RequestToken()
{
var client = new TokenClient(
Constants.TokenEndpoint,
"client",
"secret");
return client.RequestClientCredentialsAsync("read write").Result;
}
开发者ID:ryanmar,项目名称:IdentityServer3.Samples,代码行数:9,代码来源:Program.cs
示例18: GetToken
static TokenResponse GetToken()
{
var client = new TokenClient(
"https://localhost:44300/connect/token",
"test",
"secret");
return client.RequestClientCredentialsAsync("api1").Result;
}
开发者ID:MichaelPetrinolis,项目名称:IdentityServer3.Samples,代码行数:9,代码来源:Program.cs
示例19: GetTokenAsync
private async Task<TokenResponse> GetTokenAsync()
{
var client = new TokenClient(IdConstants.IdHost +
"identity/connect/token",
"mvc_service",
"secret");
return await client.RequestClientCredentialsAsync("sampleApi");
}
开发者ID:glennsills,项目名称:IdentityServer3.Examples,代码行数:9,代码来源:CallApiController.cs
示例20: GetUserToken
static TokenResponse GetUserToken()
{
var client = new TokenClient(
"https://localhost:44333/connect/token",
"carbon",
"21B5F798-BE55-42BC-8AA8-0025B903DC3B");
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "api1").Result;
}
开发者ID:ryanmar,项目名称:IdentityServer3.Samples,代码行数:9,代码来源:Program.cs
注:本文中的IdentityModel.Client.TokenClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论