コード例 #1
0
        /// <summary>
        /// Acquires a new AuthToken from Azure Access Control.
        /// </summary>
        /// <returns></returns>
        private async Task Authenticate()
        {
            var client = new RestClient
            {
                BaseUrl = "https://datamarket.accesscontrol.windows.net",
                UserAgent = UserAgent,
            };
            var request = new RestRequest("v2/OAuth2-13", HttpMethod.Post)
            {
                ContentType = ContentTypes.FormUrlEncoded,
                ReturnRawString = true,
            };
            request.AddParameter("client_id", ClientId);
            request.AddParameter("client_secret", ClientSecret);
            request.AddParameter("scope", "http://music.xboxlive.com");
            request.AddParameter("grant_type", "client_credentials");

            var result = await client.ExecuteAsync<string>(request);

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

            //var token = Regex.Match(result, ".*\"access_token\":\"(.*?)\".*", RegexOptions.IgnoreCase).Groups[1].Value;
            //AccessToken = token;
            //TokenLastAcquired = DateTime.Now;
        }
コード例 #2
0
ファイル: MusicClient.cs プロジェクト: kostyatab/meridian
        /// <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;
        }