Ejemplo n.º 1
0
        protected override void Authorize()
        {
            WindowThreadOptions <WebView> windowThreadOptions = new WindowThreadOptions <WebView>
            {
                WindowInitialization = window =>
                {
                    window.Title        = "Spotify Authorization";
                    window.AllowedHosts = new List <string> {
                        "accounts.spotify.com", "localhost", string.Empty
                    };
                    window.SetSize(new Size(475, 512));
                },
                BeforeWindowShownAction = window =>
                {
                    window.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                    {
                        AuthorizationCodeFlow.Authorize(url => window.NavigateTo(url), this.Scopes, this.State, this.ShowDialog, "en");
                    }));
                },
                OnWindowClosingAction = window => this.abortAuthEvent.Set()
            };

            this.webViewWindowThread = ThreadManager.Instance.CreateWindowThread(ApartmentState.STA, windowThreadOptions);
            this.webViewWindowThread.IsBackground = true;
            this.webViewWindowThread.ThreadName   = $"{nameof(ToastifyWebAuth)}_{nameof(WebView)}_Thread";
            this.webViewWindowThread.Start();
        }
Ejemplo n.º 2
0
        protected override void Authorize()
        {
            //WindowThreadOptions<WebView> windowThreadOptions = new WindowThreadOptions<WebView>
            //{
            //    WindowInitialization = window =>
            //    {
            //        window.Title = "Spotify Authorization";
            //        // TODO: AllowedHosts
            //        //window.AllowedHosts = new List<string> { "accounts.spotify.com", "localhost", string.Empty };
            //        window.SetSize(new Size(475, 512));
            //    },
            //    BeforeWindowShownAction = window =>
            //    {
            //        window.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
            //        {
            //            AuthorizationCodeFlow.Authorize(url => window.NavigateTo(url), this.Scopes, this.State, this.ShowDialog, "en");
            //        }));
            //    },
            //    OnWindowClosingAction = window => this.abortAuthEvent.Set()
            //};

            //this.webViewWindowThread = ThreadManager.Instance.CreateWindowThread(ApartmentState.STA, windowThreadOptions);
            //this.webViewWindowThread.IsBackground = true;
            //this.webViewWindowThread.ThreadName = $"{nameof(ToastifyWebAuth)}_{nameof(WebView)}_Thread";
            //this.webViewWindowThread.Start();

            AuthorizationCodeFlow.Authorize(url =>
            {
                string spotifyLoginUrl = Convert.ToBase64String(Encoding.UTF8.GetBytes(url));
                string toastifyAuthUrl = "https://aleab.github.io/toastify/spotify/authorize";
                toastifyAuthUrl        = $"{toastifyAuthUrl}?toastifyPort={this.authHttpServer.Port}&redirectUrl={Uri.EscapeDataString(spotifyLoginUrl)}";
                Process.Start(toastifyAuthUrl);
            }, this.Scopes, this.State, this.ShowDialog, "en");
        }