Example #1
0
        private async Task AuthenticateAsync()
        {
            SetRequestTokenForSessionIdResponse postRequestTokenForSessionIdResponse = null;

            if (string.IsNullOrWhiteSpace(_sessionId))
            {
                var requestTokenResponse = await GetRequestTokenAsync();

                AuthenticationInformationsAvailable?.Invoke(this, new AuthenticationInformations
                {
                    AuthenticationUrl = $"https://www.themoviedb.org/authenticate/{requestTokenResponse.request_token}"
                });

                while (postRequestTokenForSessionIdResponse == null)
                {
                    try
                    {
                        postRequestTokenForSessionIdResponse = await SetRequestTokenForSessionIdAsync(new SetRequestTokenForSessionIdBody { request_token = requestTokenResponse.request_token });

                        _sessionId = postRequestTokenForSessionIdResponse.session_id;
                    }
                    catch (Exception)
                    {
                        await Task.Delay(2000);
                    }
                }
            }

            _httpService.AddQueryParameters($"&session_id={_sessionId}");

            AuthenticationSuccessfull?.Invoke(this, new AuthenticationResult
            {
                SessionId = _sessionId
            });
        }
Example #2
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,
                });
            }
        }
Example #3
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
            });
        }
Example #4
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,
            });
        }