public async static void AuthenticateSpotifyWeb() { //Check first if we already have a token from Spotify. if (ApplicationData.Default.SpotifyToken != "") { spotWeb = new SpotifyWebAPI(); spotWeb.AccessToken = ApplicationData.Default.SpotifyToken; spotWeb.TokenType = "Bearer"; SpotifyAPI.Web.Models.PrivateProfile pp = spotWeb.GetPrivateProfile(); if (!pp.HasError()) { // success return; } else { //failed, is token invalid ? #if DEBUG MessageBox.Show("Auth from saved token failed."); #endif spotWeb.Dispose(); } } System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => System.Windows.MessageBox.Show("Please sign in, to be able to show your play lists.")), System.Windows.Threading.DispatcherPriority.Normal); WebAPIFactory webApiFactory = new WebAPIFactory( "http://localhost", 8000, "3a922edff6af43e9be7abb98cf217220", Scope.UserReadPrivate | Scope.PlaylistReadPrivate | Scope.UserLibraryRead | Scope.UserReadRecentlyPlayed | Scope.UserTopRead, TimeSpan.FromSeconds(60) ); try { //This will open the user's browser and returns once //the user is authorized. spotWeb = await webApiFactory.GetWebApi(); } catch (Exception ex) { spotWeb = null; MessageBox.Show(ex.Message); } if (spotWeb == null) { return; } Console.WriteLine("Token retreived succesfully from spotify web service."); ApplicationData.Default.SpotifyToken = spotWeb.AccessToken; ApplicationData.Default.Save(); return; }
public static bool isAuthenticated() { if (spotWeb != null) { SpotifyAPI.Web.Models.PrivateProfile pp = spotWeb.GetPrivateProfile(); if (!pp.HasError()) { return(true); } } return(false); }
private void authResponseReceivedEvent(Models.Token token, string state) { mAuth.StopHttpServer(); mSpotify = new SpotifyWebAPI(); if (state != "XSS") { mErrorMessage = "Wrong state received."; return; } if (token.Error != null) { mErrorMessage = token.Error; return; } mSpotify.UseAuth = true; mSpotify.AccessToken = token.AccessToken; mSpotify.TokenType = token.TokenType; mProfile = mSpotify.GetPrivateProfile(); }