// ReSharper disable once UnusedParameter.Local
        public static void AuthInit()
        {
            initFinished = false;
            _clientId    = string.IsNullOrEmpty(_clientId) ? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID") : _clientId;
            _secretId    = string.IsNullOrEmpty(_secretId) ? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID") : _secretId;
            Console.WriteLine("### Spotify API Duplicate checker ###");

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002", Scope.UserTopRead | Scope.UserReadRecentlyPlayed | Scope.PlaylistReadPrivate | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.PlaylistReadCollaborative);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();
            int counter = 0;

            Console.Write("Waiting for API: ");
            while (api == null)
            {
                counter++;
                Console.Write(counter % 3 == 0 ? "." : "\n.");
                Thread.Sleep(400);
            }
            Console.Write("API loaded");
            initFinished = true;
            //PrintUsefulData();
            //Console.ReadLine();
            //auth.Stop(0);
        }
Beispiel #2
0
        private void connectBtn_Click(object sender2, EventArgs e)
        {
            String clientId     = clientIdTB.Text;
            String clientSecret = clientSecretTB.Text;

            if (clientId.Length > 0 && clientSecret.Length > 0)
            {
                AuthorizationCodeAuth auth = new AuthorizationCodeAuth(
                    clientId,
                    clientSecret,
                    "http://localhost:4002",
                    "http://localhost:4002",
                    Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.UserLibraryModify
                    );

                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    Token token = await auth.ExchangeCode(payload.Code);

                    SpotifyAPI = new SpotifyWebAPI()
                    {
                        TokenType   = token.TokenType,
                        AccessToken = token.AccessToken
                    };
                };
                auth.Start(); // Starts an internal HTTP Server
                auth.OpenBrowser();
            }
            else
            {
                messageLbl.Text = "Need both client secret and client Id. These can be found on your spotify developer page (free to create account).";
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            this.settings           = Settings.Load();
            this.WindowScale.ScaleX = this.settings.WindowScale;
            this.WindowScale.ScaleY = this.settings.WindowScale;
            this.Left    = this.settings.WindowPositionX;
            this.Top     = this.settings.WindowPositionY;
            this.Topmost = this.settings.AlwaysOnTop;

            this.Controls.Opacity = 0.0;
            this.PinOn.Visibility = this.Topmost ? Visibility.Visible : Visibility.Collapsed;

            this.auth = new AuthorizationCodeAuth(
                Keys.ClientId,
                Keys.ClientSecret,
                "http://localhost:4002",
                "http://localhost:4002",
                Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState | Scope.UserReadCurrentlyPlaying);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();
        }
Beispiel #4
0
        public SpotifyLoad()
        {
            auth = new AuthorizationCodeAuth(
                _clientId,
                _clientSecret,
                "http://localhost:4002",
                "http://localhost:4002",
                Scope.UserReadCurrentlyPlaying | Scope.UserModifyPlaybackState
                );

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                token = await auth.ExchangeCode(payload.Code);

                api = new SpotifyWebAPI()
                {
                    TokenType   = token.TokenType,
                    AccessToken = token.AccessToken
                };
                Thread t = new Thread(spotifyDataLoop);
                t.Start();
            };
            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();
        }
Beispiel #5
0
        public async void Init()
        {
            var _clientId = "4dab4bc197084c7db90f8201c5990abe";
            var _secretId = "e5f5c68a50ff48068eb1bfea84cc57a4";

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);

            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                SpotifyWebAPI api = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
                // Do requests with API client

                profile = await api.GetPrivateProfileAsync();

                if (!profile.HasError())
                {
                    Console.WriteLine(profile.DisplayName);
                }
            };
        }
        private static async Task <SpotifyWebAPI> AuthSpotifyApi()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(
                    config.GetSection("SpotifyApi:ClientId").Value,
                    config.GetSection("SpotifyApi:ClientSecret").Value,
                    "http://localhost:6410",
                    "http://localhost:6410",
                    SpotifyAPI.Web.Enums.Scope.PlaylistReadCollaborative);

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                _spotifyWeb = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
                // Do requests with API client
            };
            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();

            return(_spotifyWeb);
        }
Beispiel #7
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            Environment.SetEnvironmentVariable("SPOTIFY_CLIENT_ID", "1f943e38b30c4a378c284f1ba0bafbf9");
            Environment.SetEnvironmentVariable("SPOTIFY_SECRET_ID", "7c100ccbb9714e13948a788b943636e8");

            _clientId = string.IsNullOrEmpty(_clientId)
                ? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
                : _clientId;

            _secretId = string.IsNullOrEmpty(_secretId)
                ? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
                : _secretId;

            Console.WriteLine("####### Spotify API Example #######");
            Console.WriteLine("This example uses AuthorizationCodeAuth.");
            Console.WriteLine(
                "Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                                                   Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.AppRemoteControl | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.UserReadPrivate | Scope.UserReadEmail | Scope.Streaming
                                                                   | Scope.UserModifyPlaybackState | Scope.UserReadPlaybackState | Scope.UserReadRecentlyPlayed);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();


            while (!end)
            {
            }

            //Thread.Sleep(1000000000);
            //Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #8
0
 public void RunAuthentication()
 {
     try
     {
         auth = new AuthorizationCodeAuth(
             "7fa845408d634311aff87a53a3b08f12",
             // TODO: THIS IS BAD!!
             "65c8dc48c66b494c90a9bf93d12765a1",
             "http://localhost:8000",
             "http://localhost:8000",
             Scope.UserReadPrivate | Scope.PlaylistReadPrivate | Scope.UserLibraryRead |
             Scope.UserFollowRead | Scope.UserTopRead | Scope.PlaylistModifyPublic
             );
         //This will be called, if the user cancled/accept the auth-request
         auth.AuthReceived += Auth_AuthReceived;
         //a local HTTP Server will be started (Needed for the response)
         auth.Start();
         //This will open the spotify auth-page. The user can decline/accept the request
         auth.OpenBrowser();
     }
     catch (Exception e)
     {
         Logger.Error("RunAuthentication() failed.", e);
     }
 }
Beispiel #9
0
        private static string _secretId = ""; //"";

        static void Main(string[] args)
        {
            _clientId = string.IsNullOrEmpty(_clientId)
                ? System.Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
                : _clientId;

            _secretId = string.IsNullOrEmpty(_secretId)
                ? System.Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
                : _secretId;

            Console.WriteLine("####### Spotify API Example #######");
            Console.WriteLine("This example uses AuthorizationCodeAuth.");
            Console.WriteLine(
                "Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");


            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();

            Console.ReadLine();
        }
Beispiel #10
0
        public SpotifyAPI(string clientId, string secretId, string redirectUrl = "http://localhost:4002", Boolean authed = false)
        {
            _clientId = clientId;
            _secretId = secretId;

            if (!authed)
            {
                System.Diagnostics.Debug.WriteLine("Authorizing for the first time");
                auth = new AuthorizationCodeAuth(
                    _clientId,
                    _secretId,
                    redirectUrl,
                    redirectUrl,
                    Scope.UserReadPrivate | Scope.UserReadCurrentlyPlaying | Scope.UserTopRead | Scope.Streaming | Scope.UserModifyPlaybackState | Scope.UserLibraryModify | Scope.UserReadPlaybackState | Scope.PlaylistReadPrivate | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic | Scope.UserLibraryRead
                    );

                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    token = await auth.ExchangeCode(payload.Code);

                    api = new SpotifyWebAPI()
                    {
                        TokenType   = token.TokenType,
                        AccessToken = token.AccessToken
                    };
                    App.Current.Properties["TokenType"]   = api.TokenType;
                    App.Current.Properties["AccessToken"] = api.AccessToken;
                };
                auth.Start();
                auth.OpenBrowser();
                authed = true;
            }
        }
        public async Task ConnectWebApi(bool keepRefreshToken = true)
        {
            _securityStore = SecurityStore.Load(pluginDirectory);

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(_securityStore.ClientId, _securityStore.ClientSecret, "http://localhost:4002", "http://localhost:4002",
                                                                   Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState | Scope.Streaming | Scope.UserFollowModify);


            if (_securityStore.HasRefreshToken && keepRefreshToken)
            {
                Token token = await auth.RefreshToken(_securityStore.RefreshToken);

                _spotifyApi = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
            }
            else
            {
                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    Token token = await auth.ExchangeCode(payload.Code);

                    _securityStore.RefreshToken = token.RefreshToken;
                    _securityStore.Save(pluginDirectory);
                    _spotifyApi = new SpotifyWebAPI()
                    {
                        TokenType = token.TokenType, AccessToken = token.AccessToken
                    };
                };
                auth.Start();
                auth.OpenBrowser();
            }
        }
Beispiel #12
0
 private void iniciarModoStream()
 {
     try
     {
         Log.Instance.ImprimirMensaje("Intentando conectar cuenta de Spotify", TipoMensaje.Info, "Spotify.iniciarModoStream()");
         Programa.HayInternet(true);
         Stopwatch crono = Stopwatch.StartNew();
         auth = new AuthorizationCodeAuth(
             clavePublica,
             clavePrivada,
             "http://localhost:4002/",
             "http://localhost:4002/",
             Scope.UserReadEmail | Scope.UserReadPrivate | Scope.Streaming | Scope.UserReadPlaybackState
             );
         auth.AuthReceived += (sender, payload) =>
         {
             auth.Stop();
             Token token = auth.ExchangeCode(payload.Code).Result;
             tokenActual = token;
             _spotify    = new SpotifyWebAPI()
             {
                 TokenType   = token.TokenType,
                 AccessToken = token.AccessToken
             };
             crono.Stop();
             if (_spotify.AccessToken != null)
             {
                 cuentaLista     = true;
                 cuentaVinculada = true;
                 Programa.config.AppSettings.Settings["VinculadoConSpotify"].Value = "true";
                 Log.Instance.ImprimirMensaje("Conectado sin errores como " + _spotify.GetPrivateProfile().DisplayName, TipoMensaje.Correcto, crono);
             }
             else
             {
                 cuentaLista     = false;
                 cuentaVinculada = false;
                 Log.Instance.ImprimirMensaje("Se ha conectado pero el token es nulo", TipoMensaje.Error, crono);
                 Programa.config.AppSettings.Settings["VinculadoConSpotify"].Value = "false";
             }
             CodigoRefresco = token.RefreshToken;
             Programa.tareaRefrescoToken = new Thread(Programa.Refresco);
             Programa.tareaRefrescoToken.Start();
         };
         auth.Start();
         auth.OpenBrowser();
     }
     catch (NullReferenceException)
     {
         Programa.HayInternet(false);
         Console.WriteLine("Algo fue mal");
         System.Windows.Forms.MessageBox.Show(Programa.textosLocal.GetString("error_internet"));
     }
     catch (HttpRequestException)
     {
         Programa.HayInternet(false);
         Console.WriteLine("No tienes internet");
         System.Windows.Forms.MessageBox.Show(Programa.textosLocal.GetString("error_internet"));
     }
 }
Beispiel #13
0
 public void Connect()
 {
     auth = new AuthorizationCodeAuth(_clientId, _secretId, _localAddress, _localAddress, Scope.UserReadPlaybackState);
     auth.AuthReceived += Auth_AuthReceived;
     auth.Start();
     //string uri = auth.GetUri();
     auth.OpenBrowser();
 }
Beispiel #14
0
        // ReSharper disable once UnusedParameter.Local
        public static void Main(string[] args)
        {
            _clientId = string.IsNullOrEmpty(_clientId) ?
                        Environment.GetEnvironmentVariable("SPOTIFACE_CLIENT_ID") :
                        _clientId;

            _secretId = string.IsNullOrEmpty(_secretId) ?
                        Environment.GetEnvironmentVariable("SPOTIFACE_SECRET") :
                        _secretId;

            var auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://*****:*****@"..\..\..\..\..\src\"), "video_emotion_color_demo.py");

                    while (true)
                    {
                        using (ZFrame reply = socket.ReceiveFrame())
                        {
                            emotionStack.Add(reply.ReadString());
                            Console.WriteLine("RECIEVED {0}", emotionStack[emotionStack.Count - 1]);
                        }
                        socket.Send(new ZFrame("Thanks"));

                        PlaybackContext playbackContext   = _spotify.GetPlayback();
                        var             isReadyForNewSong = !playbackContext.IsPlaying || playbackContext.ProgressMs >= (playbackContext.Item.DurationMs - CHANGE_SONG_BUFFER_MS);
                        Console.WriteLine("{0} ms before next song!", playbackContext.Item.DurationMs - CHANGE_SONG_BUFFER_MS - playbackContext.ProgressMs);
                        if (isReadyForNewSong)
                        {
                            Console.WriteLine("READY FOR A NEW SONG");
                            string mostCommon = emotionStack.GroupBy(v => v).OrderByDescending(g => g.Count()).First().Key;
                            if (mostCommon != lastMostCommon)
                            {
                                Console.WriteLine("Most common since last time was {0}", mostCommon);
                                lastMostCommon = mostCommon;
                                _spotify.ResumePlayback(contextUri: _playlistMap[mostCommon], offset: 0, positionMs: 0);
                                _spotify.SetShuffle(true);
                                emotionStack.Clear();
                            }
                        }
                    }
                }
        }
        internal SpotifyAuthentication()
        {
            bool initialized = false;
            var  client_id   = "7b2f38e47869431caeda389929a1908e";
            var  secret_id   = "c3a86330ef844c16be6cb46d5e285a45";

            _authenFactory = new AuthorizationCodeAuth(
                client_id,
                secret_id,
                "http://localhost:8800",
                "http://localhost:8800",
                Scope.UserReadCurrentlyPlaying |
                Scope.UserModifyPlaybackState |
                Scope.AppRemoteControl |
                Scope.UserReadPlaybackState
                );
            _authenFactory.AuthReceived += async(s, p) =>
            {
                var ath = (AuthorizationCodeAuth)s;
                ath.Stop();

                var token = await ath.ExchangeCode(p.Code);

                _refreshToken = token.RefreshToken;
                if (_client == null)
                {
                    _client = new SpotifyWebAPI()
                    {
                        AccessToken = token.AccessToken,
                        TokenType   = "Bearer"
                    };
                }
                else
                {
                    _client.AccessToken = token.AccessToken;
                }
                if (!initialized)
                {
                    ClientReady?.Invoke(this, _client);
                }
                initialized = true;
            };
            _authenFactory.Start();
            _authenFactory.OpenBrowser();
            _refreshTokenWorker          = new Timer();
            _refreshTokenWorker.Interval = 30 * (1000 * 60);
            _refreshTokenWorker.Elapsed += async(s, e) =>
            {
                var token = await _authenFactory.RefreshToken(_refreshToken);

                _client.AccessToken = token.AccessToken;
            };
            _refreshTokenWorker.Start();
        }
        SpotifyConfiguration()
        {
            bool initialized = false;
            var  client_id   = "7b2f38e47869431caeda389929a1908e";
            var  secret_id   = "c3a86330ef844c16be6cb46d5e285a45";

            AuthenFactory = new AuthorizationCodeAuth(
                client_id,
                secret_id,
                "http://localhost:8888",
                "http://localhost:8888",
                SpotifyAPI.Web.Enums.Scope.AppRemoteControl
                );
            AuthenFactory.AuthReceived += async(s, p) =>
            {
                var ath = (AuthorizationCodeAuth)s;
                ath.Stop();

                var token = await ath.ExchangeCode(p.Code);

                initialized  = true;
                RefreshToken = token.RefreshToken;
                if (Client == null)
                {
                    Client = new SpotifyWebAPI()
                    {
                        AccessToken = token.AccessToken,
                        TokenType   = "Bearer"
                    };
                }
                else
                {
                    Client.AccessToken = token.AccessToken;
                }
                IsAvailable = true;
            };
            AuthenFactory.Start();
            AuthenFactory.OpenBrowser();
            while (!initialized)
            {
                System.Threading.Thread.Sleep(1000);
            }
            AuthenFactory.Stop();
            _refreshTokenWorker          = new Timer();
            _refreshTokenWorker.Interval = 30 * (1000 * 60);
            _refreshTokenWorker.Elapsed += async(s, e) =>
            {
                var token = await AuthenFactory.RefreshToken(RefreshToken);

                Client.AccessToken = token.AccessToken;
            };
            _refreshTokenWorker.Start();
        }
        public void RetrieveAuthCode(AuthCodeReceivedDelegate OnAuthCodeReceived)
        {
            this.OnAuthCodeReceived = OnAuthCodeReceived;
            string ClientId = Environment.GetEnvironmentVariable("SPLACK_SPOTIFY_CLIENT_ID");
            string SecretId = Environment.GetEnvironmentVariable("SPLACK_SPOTIFY_SECRET_ID");

            AuthorizationCodeAuth Auth = new AuthorizationCodeAuth(ClientId, SecretId, "http://localhost:4002", "http://localhost:4002", Scope.UserReadCurrentlyPlaying);

            Auth.AuthReceived += AuthOnAuthReceived;
            Auth.Start();
            Auth.OpenBrowser();
        }
Beispiel #18
0
        public SpotifyAPI(string clientId, string secretId, string redirectUrl = SPOTIFY_API_DEFAULT_REDIRECT_URL)
        {
            _lastFmApi = new LastFMAPI();

            if (!string.IsNullOrEmpty(clientId) && !string.IsNullOrEmpty(secretId))
            {
                _auth = new AuthorizationCodeAuth(clientId, secretId, redirectUrl, redirectUrl,
                                                  Scope.Streaming | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying |
                                                  Scope.UserReadRecentlyPlayed | Scope.UserReadPlaybackState);
                _auth.AuthReceived += AuthOnAuthReceived;
                _auth.Start();
            }
        }
Beispiel #19
0
        public SpotifyAPI(string clientId, string secretId, string redirectUrl = "http://localhost:4002")
        {
            _clientId = clientId;
            _secretId = secretId;

            if (!string.IsNullOrEmpty(_clientId) && !string.IsNullOrEmpty(_secretId))
            {
                var auth = new AuthorizationCodeAuth(_clientId, _secretId, redirectUrl, redirectUrl,
                                                     Scope.Streaming | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying | Scope.UserReadRecentlyPlayed | Scope.UserReadPlaybackState);
                auth.AuthReceived += AuthOnAuthReceived;
                auth.Start();
                auth.OpenBrowser();
            }
        }
        public static void Run(List <string> trackNames)
        {
            tracks = trackNames;

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(Credentials.SP_id,
                                                                   Credentials.SP_key, "http://localhost:4002", "http://localhost:4002", Scope.PlaylistModifyPrivate);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();

            Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new PlaylistMapper());
            });

            var serviceProvider = new ServiceCollection()
                                  .AddAutoMapper(typeof(Program))
                                  .AddSingleton <IValidator, Validator>()
                                  .AddSingleton <IProcessFactory, ProcessFactory>()
                                  .AddSingleton <IAPIProcess, ApiProcess>()
                                  .AddSingleton <SpotifyWebAPI>()
                                  .AddTransient <IProcess, GetPlaylistProcess>()
                                  .AddTransient <IProcess, ClearPlaylistProcess>()
                                  .AddTransient <IProcess, ReorderProcess>()
                                  .AddTransient <IServiceCollection, ServiceCollection>()
                                  .BuildServiceProvider();

            string _clientId = "eca82f597115423cac9d1125e0fb97c4";
            string _secretId = "17a6e5916bb3424eb50f29e4816521a4";

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(
                _clientId,
                _secretId,
                "http://localhost:4200",
                "http://localhost:4200",
                Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic
                );


            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                var apiProcess = serviceProvider.GetService <IAPIProcess>();

                ClearPlaylistRequest request = new ClearPlaylistRequest {
                    PlaylistUri = "6KPMCEavSTefLEx5JH3edt", Token = token
                };

                IResponseMessage responseMessage = apiProcess.RunCommand <ClearPlaylistRequest>(request);
            };
            auth.Start(); // Starts an internal HTTP Server
            auth.OpenBrowser();

            Console.ReadLine();
        }
Beispiel #22
0
        /// <summary>
        /// Connectes to the WebHelper with your ClientId
        /// </summary>
        /// <param name="clientId">Custom client id</param>
        protected virtual void ConnectSpotifyWebHelper(AuthorizationCodeAuth auth, int port = 8000)
        {
            if (!IsConnected)
            {
                auth.Start();
                auth.OpenBrowser();

                if (m_timeoutRoutine == null)
                {
                    m_timeoutRoutine = StartCoroutine(AwaitConnectionTimeout(ConnectionTimeout, auth));
                }

                Analysis.Log("Awaiting authentification completion in browser", Analysis.LogLevel.Vital);
            }
        }
Beispiel #23
0
        private void AuthorizeSpotifyToken()
        {
            AuthorizationCodeAuth auth = this.CreateAuthorization();

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                this.CreateTokenFile(token);
                this.isAuthenticated = true;
            };

            auth.Start();
            auth.OpenBrowser();
        }
Beispiel #24
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            SetApiKeys();

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();
            Timer t = new Timer(TimerCallbackAsync, null, 0, 5000);

            Console.ReadLine();
            auth.Stop(0);
        }
Beispiel #25
0
        private static string _secretId = "3605d0cde2d74c07822299c0359f840f"; //"";


        // ReSharper disable once UnusedParameter.Local
        static public void Main()
        {
            //_clientId = string.IsNullOrEmpty(_clientId)
            //    ? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
            //    : _clientId;

            //_secretId = string.IsNullOrEmpty(_secretId)
            //    ? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
            //    : _secretId;


            //MainWindow mainMenu = new MainWindow();

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState);

            //Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead |
            //Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead | Scope.PlaylistReadCollaborative |
            //Scope.UserRead+RecentlyPlayed | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState)



            Console.WriteLine("Hello, open Spotify please and start a Playback");

            Console.WriteLine("Put the Emotic Epoc+ on your head please and open Emotiv App");
            Console.WriteLine("Select your Emotiv epoc+ device and follow the instructions given by the application ");
            Console.WriteLine("you must be 100 % of connection for the application work properly  ");
            Console.WriteLine("Press Enter when you are ready");
            Console.ReadLine();



            auth.AuthReceived += AuthOnAuthReceived;

            auth.Start();



            auth.OpenBrowser();

            Thread.Sleep(20000);
            Console.ReadLine();


            auth.Stop(0);
        }
Beispiel #26
0
        /// <summary>
        /// Authorize with the Spotify Web API to retrieve a Refresh Token.
        /// This token is then to be used for any subsequent calls to <see cref="RunStatus(Status)"/>
        /// </summary>
        /// <param name="opts_">CLI arguments</param>
        /// <returns>1 for errors, 0 otherwise</returns>
        static int RunAuthorize(Authorize opts_)
        {
            SysConsole.WriteLine("Authorizing with SpotifyWebAPI");

            Token token = null;
            var   auth  = new AuthorizationCodeAuth(opts_.ClientId, opts_.ClientSecret, "http://localhost:" + opts_.Port, "http://localhost:" + opts_.Port, Scope.UserReadPrivate);

            auth.AuthReceived += (object sender_, AuthorizationCode payload_) =>
            {
                auth.Stop();
                var exchange = auth.ExchangeCode(payload_.Code);
                exchange.Wait(10000);

                if (!exchange.IsCompleted)
                {
                    throw new Exception("Timeout during authorization process!");
                }

                token = exchange.Result;
            };

            SysConsole.WriteLine("Starting authorization process");
            auth.Start();
            auth.OpenBrowser();

            SysConsole.Write("Waiting for authorzation to complete...");
            while (token == null)
            {
                SysConsole.Write(".");
                Task.Delay(500).Wait();
            }

            string settings = "ClientId=" + opts_.ClientId + "\r\n";

            settings += "ClientSecret=" + opts_.ClientSecret + "\r\n";
            settings += "RefreshToken=" + token.RefreshToken + "\r\n";
            Clipboard.SetText(settings);

            SysConsole.WriteLine("");
            SysConsole.WriteLine("Token received. Set the following settings in your web parser parent measure:");
            SysConsole.WriteLine("---");
            SysConsole.WriteLine(settings);
            SysConsole.WriteLine("---");
            SysConsole.WriteLine("(the settings have been copied to your clipboard as well)");

            return(0);
        }
Beispiel #27
0
        public static async void DoAuthAsync()
        {
            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(
                clientId,
                clientSecret,
                // "https://concert-companion.appspot.com",
                // "https://concert-companion.appspot.com",
                "concert-companion:/",
                // "http://localhost:4002",
                "http://localhost:4002",
                Scope.UserFollowRead | Scope.UserReadPrivate | Scope.UserTopRead | Scope.UserReadEmail | Scope.PlaylistReadCollaborative
                );

            auth.AuthReceived += async(sender, payload) =>
            {
                auth.Stop();
                Token token = await auth.ExchangeCode(payload.Code);

                SpotifyWebAPI api = new SpotifyWebAPI()
                {
                    TokenType   = token.TokenType,
                    AccessToken = token.AccessToken
                };

                PrivateProfile      profile     = api.GetPrivateProfile();
                Paging <FullArtist> artists     = api.GetUsersTopArtists();
                UserProfile         userProfile = new UserProfile()
                {
                    Id         = profile.Id,
                    Name       = profile.DisplayName,
                    Email      = profile.Email,
                    TopArtists = artists.Items.Select(artist => new Artist()
                    {
                        Id = artist.Id, Name = artist.Name
                    }).ToList()
                };

                SaveUser(userProfile);

                // Do requests with API client
            };
            Console.WriteLine("Starting the server");
            auth.Start(); // Starts an internal HTTP Server
            Console.WriteLine("Opening the browser");
            auth.OpenBrowser();
        }
        private static void AuthSpotify()
        {
            s_SpotifyAuth.AuthReceived += async(_, payload) =>
            {
                s_SpotifyAuth.Stop();
                var token = await s_SpotifyAuth.ExchangeCode(payload.Code);

                s_SpotifyAPI = new SpotifyWebAPI()
                {
                    TokenType   = token.TokenType,
                    AccessToken = token.AccessToken
                };
                s_SpotifyToken     = token;
                s_SpotifyConnected = true;
            };
            s_SpotifyAuth.Start();
            s_SpotifyAuth.OpenBrowser();
        }
Beispiel #29
0
        private void OpenAuthenticationDialog(bool refresh = false)
        {
            if (_connectionDialogOpened)
            {
                return;
            }

            if (refresh)
            {
                _auth.Stop();
                _token = null;
                _auth.Start();
            }

            _auth.ShowDialog = true;
            _auth.OpenBrowser();
            _connectionDialogOpened = true;
        }
Beispiel #30
0
        public void AuthWebApi()
        {
            _clientId = string.IsNullOrEmpty(_clientId)
                ? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
                : _clientId;

            _secretId = string.IsNullOrEmpty(_secretId)
                ? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
                : _secretId;

            AuthorizationCodeAuth auth =
                new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
                                          Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);

            auth.AuthReceived += AuthOnAuthReceived;
            auth.Start();
            auth.OpenBrowser();
        }