IdentityServer4客户端获取Token的方法

var httpClient = new HttpClient();
            var disco = httpClient.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest
            {
                Address = "http://localhost:5000",
                Policy =
                {
                     RequireHttps=false
                }
            }).Result;
            if (disco.IsError)
            {
                throw new Exception(disco.Error);
            }
            var tokenResponse = httpClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
            {
                Address = disco.TokenEndpoint,
                ClientId = "aa",
                ClientSecret = "bb",
                Scope = "cc"
            });
            string token = tokenResponse.Result.AccessToken;
            Console.Write(token);

 

posted @ 2019-06-19 17:38  星星c#  阅读(2842)  评论(2编辑  收藏  举报