Esempio n. 1
0
        /// <summary>
        /// Acquires a new AuthToken from Azure Access Control.
        /// </summary>
        /// <returns></returns>
        private async Task Authenticate()
        {
            var parameters = new Dictionary<string, string>();
            parameters.Add("client_id", ClientId);
            parameters.Add("client_secret", ClientSecret);
            parameters.Add("scope", "http://music.xboxlive.com");
            parameters.Add("grant_type", "client_credentials");

            var request = new CoreRequest(new Uri("https://datamarket.accesscontrol.windows.net/v2/OAuth2-13"), parameters, "POST");

            var result = await request.Execute();

            TokenResponse = JsonConvert.DeserializeObject<TokenResponse>(result.ToString());
            if (TokenResponse != null)
            {
                TokenResponse.TimeStamp = DateTime.Now;
            }

            //var token = Regex.Match(result, ".*\"access_token\":\"(.*?)\".*", RegexOptions.IgnoreCase).Groups[1].Value;
            //AccessToken = token;
            //TokenLastAcquired = DateTime.Now;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a new <see cref="RestRequest"/> populated with the common values for every request.
        /// </summary>
        /// <param name="resourceUrl"></param>
        /// <returns>A new <see cref="RestRequest"/> populated with the common values for every request</returns>
        private CoreRequest GetPopulatedRequest(string resourceUrl)
        {
            if (string.IsNullOrWhiteSpace(TokenResponse.AccessToken))
            {
                throw new Exception("The Xbox Music Client was unable to obtain an AccessToken from the authentication service.");
            }

            var parameters = new Dictionary<string, string>();

            if (!string.IsNullOrWhiteSpace(Language))
            {
                parameters.Add("language", Language);
            }
            if (!string.IsNullOrWhiteSpace(Country))
            {
                parameters.Add("country", Country);
            }

            var request = new CoreRequest(new Uri(resourceUrl.Replace("{namespace}", "music")), parameters);

            return request;
        }