public async Task <Data> GetResponse()
            {
                var webServer = new TcpListener(IPAddress.Any, 8000);

                webServer.Start();

                ConnectionService.OpenBrowser(this.ConnectUrl);

                var s = await webServer.AcceptSocketAsync();

                var bReceive = new byte[2048];
                var i        = s.Receive(bReceive, bReceive.Length, 0);

                // Convert Byte to String
                var sBuffer = Encoding.ASCII.GetString(bReceive);

                s.Shutdown(SocketShutdown.Both);
                webServer.Stop();

                var t = sBuffer.Split('?')[1].Split('&')[0].Split('=')[1];

                var token = AuthorizationCode.ProcessCallback(this.apiParameter, t, string.Empty);

                var api = new SpotifyWebApi.SpotifyWebApi(token);

                return(new Data(token, api));
            }
        // GET: /<controller>/
        public IActionResult Index(string code, string state)
        {
            var token = AuthorizationCode.ProcessCallback(_spotifyAuthService.GetAuthParameters(), code);

            //// Use the api with access to personal data.
            _spotifyAuthService.SetToken(token);
            return(RedirectToAction("Index", "Admin"));
        }
Example #3
0
        /// <summary>The get basic data.</summary>
        /// <param name="tokenString">The token string.</param>
        private async void GetBasicData(string tokenString)
        {
            var token = AuthorizationCode.ProcessCallback(this.apiParameter, tokenString, string.Empty);

            this.container.RegisterInstance(token);

            var api = new SpotifyWebApi(token);

            this.container.RegisterInstance <ISpotifyWebApi>(api);

            var profile   = api.UserProfile.GetMe();
            var playLists = api.Playlist.GetMyPlaylists(200);

            var data = new ConnectionData
            {
                Profile   = await profile,
                Playlists = await playLists,
                Api       = api,
                Token     = token
            };

            this.eventAggregator.GetEvent <ConnectionEstablishedEvent>().Publish(data);
        }