コード例 #1
0
        public async Task <AuthResponse> GetToken()
        {
            var request = new AuthRequest {
                ApiKey = this._apiKey
            };
            var response = await this.SendAsync(request.Request(this._apiKey.Host));

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

                _authentication = JsonSerializer.Deserialize <AuthResponse>(body);

                _validMax = DateTime.Now.AddSeconds(_authentication.ValidFor);

                return(_authentication);
            }

            throw new UnauthorizedAccessException(response.ToString());
        }