コード例 #1
0
ファイル: GrooveTest.cs プロジェクト: Losses/DarkPlayer
        public void TestNonEmptyCredentials()
        {
            var requestAuthData = new AuthRequest(AppId, AppKey, AppScope, AppGrantType);
            var result          = requestAuthData.ToDictionary();

            Assert.AreEqual(AppScope, result["scope"]);
        }
コード例 #2
0
        /// <summary>
        /// Authenticate client to Xbox Music(Groove Music) service asynchronously.
        /// </summary>
        /// <returns>Task represents the asynchronous operation.</returns>
        internal static async Task <bool> AuthenticateAsync()
        {
            var requestAuthData = new AuthRequest(AppId, AppKey, AppScope, AppGrantType);

            using (var httpClient = new HttpClient())
                using (var hcFormContent = new FormUrlEncodedContent(requestAuthData.ToDictionary()))
                    using (var hcResponse = await httpClient.PostAsync(new Uri(AppServiceAuthEndpoint), hcFormContent))
                    {
                        try
                        {
                            if (hcResponse.IsSuccessStatusCode)
                            {
                                var strResponseContent = await hcResponse.Content.ReadAsStringAsync();

                                var responseEntity = JsonConvert.DeserializeObject <AzureAuthKey>(strResponseContent);

                                ValidIn            = TimeSpan.FromSeconds(responseEntity.ExpiresInSecs);
                                LastTimeGetAuthKey = DateTimeOffset.Now;
                                AuthKey            = responseEntity.AccessToken;

                                return(true);
                            }
                        }
                        catch (HttpRequestException)
                        {
                            // Ignore network errors
                        }
                    }

            return(false);
        }
コード例 #3
0
ファイル: GrooveTest.cs プロジェクト: Losses/DarkPlayer
 public void TestEmptyCredentials()
 {
     Assert.ThrowsException <InvalidOperationException>(() =>
     {
         var authRequest = new AuthRequest();
         var result      = authRequest.ToDictionary();
     });
 }