public String Connect()
        {
            mErrorMessage = null;
            mAuth         = new Auth.ImplicitGrantAuth
            {
                RedirectUri = "http://localhost:8000",
                ClientId    = mSpotifyId,
                Scope       = Enums.Scope.UserReadPrivate | Enums.Scope.UserReadEmail | Enums.Scope.PlaylistReadPrivate | Enums.Scope.UserLibraryRead | Enums.Scope.UserReadPrivate | Enums.Scope.UserFollowRead | Enums.Scope.UserReadBirthdate | Enums.Scope.UserTopRead | Enums.Scope.PlaylistModifyPrivate | Enums.Scope.PlaylistModifyPublic,
                State       = "XSS"
            };
            mAuth.OnResponseReceivedEvent += authResponseReceivedEvent;

            mAuth.StartHttpServer(8000);
            mAuth.DoAuth();

            while (mSpotify == null)
            {
            }
            ;

            if (mErrorMessage == null)
            {
                return("Connection Successful");
            }
            else
            {
                return(mErrorMessage);
            }
        }
Пример #2
0
        public Task<SpotifyWebAPI> GetWebApi()
        {
            var authentication = new ImplicitGrantAuth
            {
                RedirectUri = $"{_redirectUrl}:{_listeningPort}",
                ClientId = _clientId,
                Scope = _scope,
                State = _xss
            };

            AutoResetEvent authenticationWaitFlag = new AutoResetEvent(false);
            SpotifyWebAPI spotifyWebApi = null;
            authentication.OnResponseReceivedEvent += (token, state) =>
            {
                spotifyWebApi = HandleSpotifyResponse(state, token);
                authenticationWaitFlag.Set();
            };

            try
            {
                authentication.StartHttpServer(_listeningPort);

                authentication.DoAuth();

                authenticationWaitFlag.WaitOne(_timeout);
                if (spotifyWebApi == null)
                    throw new TimeoutException($"No valid response received for the last {_timeout.TotalSeconds} seconds");
            }
            finally
            {
                authentication.StopHttpServer();
            }

            return Task.FromResult(spotifyWebApi);
        }
Пример #3
0
        public Task <SpotifyWebAPI> GetWebApi()
        {
            authentication = authentication ?? new ImplicitGrantAuth
            {
                RedirectUri = new UriBuilder(_redirectUrl)
                {
                    Port = _listeningPort
                }.Uri.OriginalString.TrimEnd('/'),
                ClientId = _clientId,
                Scope    = _scope,
                State    = _xss
            };

            AutoResetEvent         authenticationWaitFlag = new AutoResetEvent(false);
            SpotifyWebAPI          spotifyWebApi          = null;
            SpotifyWebApiException spotifyWebApiException = null;

            authentication.OnResponseReceivedEvent += (token, state) =>
            {
                try
                {
                    spotifyWebApi = HandleSpotifyResponse(state, token);
                }
                catch (SpotifyWebApiException s)
                {
                    spotifyWebApiException = s;
                }
                authenticationWaitFlag.Set();
            };

            try
            {
                authentication.StartHttpServer(_listeningPort);

                authentication.DoAuth();

                authenticationWaitFlag.WaitOne(_timeout);
                if (spotifyWebApiException != null)
                {
                    throw new SpotifyWebApiException(spotifyWebApiException.Message);
                }
                if (spotifyWebApi == null)
                {
                    throw new TimeoutException($"No valid response received for the last {_timeout.TotalSeconds} seconds");
                }
            }
            finally
            {
                authentication.StopHttpServer();
            }

            return(Task.FromResult(spotifyWebApi));
        }
Пример #4
0
        private void StartAuthentication()
        {
            _authentication = new ImplicitGrantAuth
            {
                RedirectUri = $"http://localhost:{PORT}",
                ClientId = CLIENTID,
                Scope = Scope.PlaylistReadPrivate | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic,
                State = _state,
            };
            _authentication.OnResponseReceivedEvent += _authentication_OnResponseReceivedEvent;

            _authentication.StartHttpServer(PORT);
            _authentication.DoAuth();
        }
Пример #5
0
        public Task <SpotifyWebAPI> GetWebApi()
        {
            var authentication = new ImplicitGrantAuth
            {
                RedirectUri = $"{_redirectUrl}:{_listeningPort}",
                ClientId    = _clientId,
                Scope       = _scope,
                State       = _xss
            };

            AutoResetEvent authenticationWaitFlag = new AutoResetEvent(false);
            SpotifyWebAPI  spotifyWebApi          = null;

            authentication.OnResponseReceivedEvent += (token, state) =>
            {
                spotifyWebApi = HandleSpotifyResponse(state, token);
                authenticationWaitFlag.Set();
            };

            try
            {
                authentication.StartHttpServer(_listeningPort);

                authentication.DoAuth();

                authenticationWaitFlag.WaitOne(_timeout);
                if (spotifyWebApi == null)
                {
                    throw new TimeoutException($"No valid response received for the last {_timeout.TotalSeconds} seconds");
                }
            }
            finally
            {
                authentication.StopHttpServer();
            }

            return(Task.FromResult(spotifyWebApi));
        }
        private void connectWeb()
        {
            try
            {
                _auth = new ImplicitGrantAuth
                {
                    RedirectUri = "http://localhost:88/",
                    ClientId = "7e169a49e74049aeb4980008368dd51d",
                    Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.PlaylistReadCollaborative,
                    State = "XSS"
                };
                _auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;


                _auth.StartHttpServer();
                _auth.DoAuth();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }