Esempio n. 1
0
        private static string _secretId = ""; //"";

        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            _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)");

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

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

            Console.ReadLine();
            auth.Stop(0);
        }
Esempio n. 2
0
        public bool PostValues(WebServer server, HttpListenerContext context)
        {
            Dictionary <string, object> formParams = context.RequestFormDataDictionary();

            string state = (string)formParams["state"];

            AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer <AuthorizationCode> authServer);

            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)authServer;

            auth.ClientId = (string)formParams["clientId"];
            auth.SecretId = (string)formParams["secretId"];

            string uri = auth.GetUri();

            return(context.Redirect(uri, false));
        }
        public async Task <bool> PostValues()
        {
            Dictionary <string, object> formParams = await this.RequestFormDataDictionaryAsync();

            string state = (string)formParams["state"];

            AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer <AuthorizationCode> authServer);

            AuthorizationCodeAuth auth = (AuthorizationCodeAuth)authServer;

            auth.ClientId = (string)formParams["clientId"];
            auth.SecretId = (string)formParams["secretId"];

            string uri = auth.GetUri();

            return(this.Redirect(uri, false));
        }