Пример #1
0
        public async Task <TokenDto> GetToken(BaseTokenSettings baseTokenSettings,
                                              string baseTokenUrl, string tokenPath,
                                              CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!baseTokenSettings.TokenNeeded)
            {
                return(null);
            }

            var clientCredentials = Credentials.BuildCredentialsDictionary(baseTokenSettings);

            var builder = new UriBuilder(new Uri(baseTokenUrl))
            {
                Path = tokenPath
            };

            var response = await _httpClient.PostAsync(builder.Uri, new FormUrlEncodedContent(clientCredentials), cancellationToken);

            if (response.IsSuccessStatusCode)
            {
                var data = await response.Content.ReadAsStringAsync();

                return(JsonConverter.ConvertFromJson <TokenDto>(data));
            }

            return(null);
        }