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


C# TokenClient.RequestClientCredentialsAsync方法代码示例

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


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

示例3: 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

示例4: 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

示例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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: GetClientToken

        //requests the access token using the client credentials
        static TokenResponse GetClientToken()
        {
            var client = new TokenClient(
                "http://localhost:44333/connect/token",
                "silicon",
                "F621F470-9731-4A25-80EF-67A6F7C5F4B8");

            return client.RequestClientCredentialsAsync("api1").Result;
        }
开发者ID:eknowledger,项目名称:IdentityServer3Labs,代码行数:10,代码来源:Program.cs

示例13: 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

示例14: GetTokenAsync

        protected async Task<TokenResponse> GetTokenAsync()
        {
            string _url = Constants.IdentityServerUri + "/connect/token";
            var client = new TokenClient(
                _url,
                Constants.APIClient,
                Constants.IdentitySecret);

            return await client.RequestClientCredentialsAsync("apiAccess");
        }
开发者ID:mcginkel,项目名称:identityServer3Example,代码行数:10,代码来源:BaseController.cs

示例15: RequestToken

        static TokenResponse RequestToken()
        {
            var client = new TokenClient(
                Constants.TokenEndpoint,
                "clientcredentials.client",
                "secret",
                AuthenticationStyle.PostValues);

            return client.RequestClientCredentialsAsync("read write").Result;
        }
开发者ID:RobGibbens,项目名称:IdentityServer3.Samples,代码行数:10,代码来源:Program.cs


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