Beispiel #1
0
        private void pageRoot_Loaded_1(object sender, RoutedEventArgs e)
        {
            if (MediaControl.IsPlaying)
            {
                BG1.Begin();
                id3            = Playlist.NowPlaying[0];
                SongTitle.Text = id3.Title;
                Artist.Text    = id3.Artist;
            }
            else
            {
                SongTitle.Text = "Play a song now!";
                Artist.Text    = "Swipe up from bottom for more options!";
            }

            if (Security._vault.RetrieveAll().Count != 0)
            {
                Scrobble.SetValue(AutomationProperties.NameProperty, "Last.fm Signout");
                PasswordCredential rt = Security._vault.Retrieve("Session Key", "user");
                rt.RetrievePassword();
                Globalv.session_key = rt.Password;
            }

            /*
             * if (Globalv.session_key != null)
             *  LoginBtn.Content = "Logoff";
             * else
             *  LoginBtn.Content = "Login";
             */
        }
Beispiel #2
0
        private async void Scrobble_Click_1(object sender, RoutedEventArgs e)
        {
            if (Security._vault.RetrieveAll().Count == 0)
            {
                Globalv.session_key = null;
                Scrobble.SetValue(AutomationProperties.NameProperty, "Last.fm Connect");
                justLoggedOut = false;
            }
            else
            {
                PasswordCredential rt = Security._vault.Retrieve("Session Key", "user");
                rt.RetrievePassword();
                Globalv.session_key = rt.Password;
                //sign out

                Security._vault.Remove(rt);
                Globalv.session_key = null;
                Scrobble.SetValue(AutomationProperties.NameProperty, "Last.fm Connect");
                justLoggedOut = true;
            }
            if (Globalv.session_key == null && justLoggedOut == false)
            {
                String lfmURL = "https://www.last.fm/api/auth/?api_key=" + Globalv.lfm_api_key + "&cb=" + EndUri;

                System.Uri StartUri = new Uri(lfmURL);

                WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
                    WebAuthenticationOptions.None,
                    StartUri,
                    EndUri);

                if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    //get and save lfm session key
                    string[] responseData = WebAuthenticationResult.ResponseData.ToString().Split('?');
                    string   token        = responseData[1].Substring(6);

                    HttpClient            cli        = new HttpClient();
                    string                getsk_sig  = "api_key" + Globalv.lfm_api_key + "methodauth.getSessiontoken" + token + "0e6e780c3cfa3faedf0c58d5aa6de92f";
                    HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm("MD5");
                    CryptographicHash     objHash    = objAlgProv.CreateHash();
                    IBuffer               buffSig    = CryptographicBuffer.ConvertStringToBinary(getsk_sig, BinaryStringEncoding.Utf8);
                    objHash.Append(buffSig);
                    IBuffer buffSighash = objHash.GetValueAndReset();

                    string api_sig = CryptographicBuffer.EncodeToHexString(buffSighash);

                    string get_sk         = @"http://ws.audioscrobbler.com/2.0/?method=auth.getSession&api_key=" + Globalv.lfm_api_key + "&api_sig=" + api_sig + "&token=" + token;
                    HttpResponseMessage r = await cli.GetAsync(get_sk);

                    string xml_resp = await r.Content.ReadAsStringAsync();

                    using (XmlReader rd = XmlReader.Create(new StringReader(xml_resp)))
                    {
                        rd.ReadToFollowing("key");

                        Globalv.session_key = rd.ReadElementContentAsString();
                        var c = new PasswordCredential("Session Key", "user", Globalv.session_key);
                        Mu3.Security._vault.Add(c);

                        justLoggedOut = false;
                        Scrobble.SetValue(AutomationProperties.NameProperty, "Last.fm Signout");

                        /*
                         * PasswordCredential rt = Security._vault.Retrieve("Session Key", "user");
                         * rt.RetrievePassword();
                         * MessageDialog m = new MessageDialog(rt.Password);
                         * await m.ShowAsync();
                         */
                    }
                    //MessageDialog m1 = new MessageDialog(Globalv.session_key);
                    //await m1.ShowAsync();
                }
                else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
                {
                    MessageDialog m = new MessageDialog("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString());
                    await m.ShowAsync();
                }
                else
                {
                    MessageDialog m = new MessageDialog("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString());
                    await m.ShowAsync();
                }
            }
        }