Esempio n. 1
0
        private async Task AuthenticateAsync()
        {
            var response = await _httpService.PostAsync("transmission/rpc", null);

            IEnumerable <string> headers;

            if (response.Headers.TryGetValues("X-Transmission-Session-Id", out headers))
            {
                _accessToken = headers.First();
                _httpService.AddHeader("X-Transmission-Session-Id", _accessToken);

                AuthenticationSuccessfull?.Invoke(this, new AuthenticationResult
                {
                    AccessToken = _accessToken,
                });
            }
        }
Esempio n. 2
0
        private async Task AuthenticateAsync()
        {
            if (string.IsNullOrWhiteSpace(_refreshToken))
            {
                var postClientIdForDeviceCodeResponse = await PostClientIdForDeviceCodeAsync(_clientId);

                PostDeviceCodeForAccessTokenResponse postDeviceCodeForAccessTokenResponse = null;

                AuthenticationInformationsAvailable?.Invoke(this, new AuthenticationInformations
                {
                    AuthenticationUrl = postClientIdForDeviceCodeResponse.verification_url,
                    DeviceCode        = postClientIdForDeviceCodeResponse.user_code
                });

                while (postDeviceCodeForAccessTokenResponse == null)
                {
                    await Task.Delay(TimeHelper.FromSecondsToMilliseconds(postClientIdForDeviceCodeResponse.interval));

                    try
                    {
                        postDeviceCodeForAccessTokenResponse = await PostDeviceCodeForAccessTokenAsync(postClientIdForDeviceCodeResponse.device_code, _clientId, _clientSecret);

                        _accessToken  = postDeviceCodeForAccessTokenResponse.access_token;
                        _refreshToken = postDeviceCodeForAccessTokenResponse.refresh_token;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            else
            {
                var postRefreshTokenForAccessTokenResponse = await PostRefreshTokenForAccessTokenAsync(_refreshToken);

                _accessToken  = postRefreshTokenForAccessTokenResponse.access_token;
                _refreshToken = postRefreshTokenForAccessTokenResponse.refresh_token;
            }

            _httpService.AddHeader("Authorization", $"Bearer {_accessToken}");

            AuthenticationSuccessfull?.Invoke(this, new AuthenticationResult
            {
                AccessToken  = _accessToken,
                RefreshToken = _refreshToken
            });
        }
Esempio n. 3
0
        public async Task AuthenticateAsync()
        {
            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"{_userName}:{_password}"))}");
            httpClient.DefaultRequestHeaders.Add("X-Plex-Client-Identifier", _plexClientIdentifier);
            httpClient.DefaultRequestHeaders.Add("X-Plex-Device-Name", _plexDeviceName);
            httpClient.DefaultRequestHeaders.Add("X-Plex-Product", _plexProduct);
            httpClient.DefaultRequestHeaders.Add("X-Plex-Version", _plexVersion);
            var response = await httpClient.PostAsync(SignInUrl, null);

            var content = await response.Content.ReadAsStringAsync();

            var result = await Serializer.XmlDeserializeAsync <PostAuthenticationResponse.user>(content);

            _accessToken = result.authenticationToken;
            _httpService.AddHeader("X-Plex-Token", _accessToken);

            AuthenticationSuccessfull?.Invoke(this, new AuthenticationResult
            {
                AccessToken = _accessToken,
            });
        }