/// <summary>Initializes the connection.</summary>
        /// <param name="clientId">The client id.</param>
        /// <param name="clientSecret">The client secret.</param>
        public void TryInitializeConnection(string clientId, string clientSecret)
        {
            if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret))
            {
                return;
            }

            this.apiParameter = new AuthParameters
            {
                Scopes = Scope.All,

                ClientId     = clientId,
                ClientSecret = clientSecret,

                RedirectUri = "http://localhost:8000",
                ShowDialog  = false              // Set to true to login each time.
            };

            var url = AuthorizationCode.GetUrl(this.apiParameter, "test");

            var connectUrl = new Uri(url);

            this.eventAggregator.GetEvent <ConnectionUriChangedEvent>().Publish(connectUrl);

            if (!this.isAwaiting)
            {
                this.AwaitResponse();
            }
        }
            public ConnectionService()
            {
                this.apiParameter = this.GetApiParameter();
                var url = AuthorizationCode.GetUrl(this.apiParameter, "test");

                this.ConnectUrl = url;
            }
 public void GetUrlTest()
 {
     var code = AuthorizationCode.GetUrl(
         new AuthParameters
         {
             Scopes = Scope.PlaylistModifyPrivate | Scope.UserLibraryRead,
             RedirectUri = "test",
             ClientId = "test",
             ShowDialog = true,
             ClientSecret = "tests"
         },
         "test");
 }
Exemple #4
0
        public async Task <Token> GetToken()
        {
            var state = Guid.NewGuid().ToString(); // Save this state because you must check it later



            var url = AuthorizationCode.GetUrl(this.parameters, state);

            Console.WriteLine("Opening url...");
            Console.WriteLine(url);

            var ps = new ProcessStartInfo(url)
            {
                UseShellExecute = true,
                Verb            = "open"
            };

            Process.Start(ps);

            var queryString = await this.StartServerAndRetrieveAuthCode();

            // The retrieved callback:
            var retrievedState = queryString["state"];
            var retrievedCode  = queryString["code"];
            var retrievedError = queryString["error"];

            if (retrievedError != null)
            {
                throw new Exception(retrievedError);
            }

            if (state != retrievedState)
            {
                throw new Exception("State did not match!");
            }

            var token = await AuthorizationCode.ProcessCallbackAsync(this.parameters, retrievedCode);

            return(token);
        }
Exemple #5
0
        public IActionResult FetchToken()
        {
            var url = AuthorizationCode.GetUrl(_spotifyAuthService.GetAuthParameters(), "");

            return(Redirect(url));
        }