public String Connect() { mErrorMessage = null; mAuth = new Auth.ImplicitGrantAuth { RedirectUri = "http://localhost:8000", ClientId = mSpotifyId, Scope = Enums.Scope.UserReadPrivate | Enums.Scope.UserReadEmail | Enums.Scope.PlaylistReadPrivate | Enums.Scope.UserLibraryRead | Enums.Scope.UserReadPrivate | Enums.Scope.UserFollowRead | Enums.Scope.UserReadBirthdate | Enums.Scope.UserTopRead | Enums.Scope.PlaylistModifyPrivate | Enums.Scope.PlaylistModifyPublic, State = "XSS" }; mAuth.OnResponseReceivedEvent += authResponseReceivedEvent; mAuth.StartHttpServer(8000); mAuth.DoAuth(); while (mSpotify == null) { } ; if (mErrorMessage == null) { return("Connection Successful"); } else { return(mErrorMessage); } }
public Task<SpotifyWebAPI> GetWebApi() { var authentication = new ImplicitGrantAuth { RedirectUri = $"{_redirectUrl}:{_listeningPort}", ClientId = _clientId, Scope = _scope, State = _xss }; AutoResetEvent authenticationWaitFlag = new AutoResetEvent(false); SpotifyWebAPI spotifyWebApi = null; authentication.OnResponseReceivedEvent += (token, state) => { spotifyWebApi = HandleSpotifyResponse(state, token); authenticationWaitFlag.Set(); }; try { authentication.StartHttpServer(_listeningPort); authentication.DoAuth(); authenticationWaitFlag.WaitOne(_timeout); if (spotifyWebApi == null) throw new TimeoutException($"No valid response received for the last {_timeout.TotalSeconds} seconds"); } finally { authentication.StopHttpServer(); } return Task.FromResult(spotifyWebApi); }
public WebControl() { InitializeComponent(); _savedTracks = new List<FullTrack>(); _auth = new ImplicitGrantAuth { RedirectUri = "http://localhost:8000", ClientId = "26d287105e31491889f3cd293d85bfea", Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate, State = "XSS" }; _auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent; }
private void StartAuthentication() { _authentication = new ImplicitGrantAuth { RedirectUri = $"http://localhost:{PORT}", ClientId = CLIENTID, Scope = Scope.PlaylistReadPrivate | Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic, State = _state, }; _authentication.OnResponseReceivedEvent += _authentication_OnResponseReceivedEvent; _authentication.StartHttpServer(PORT); _authentication.DoAuth(); }
public SBForm() { InitializeComponent(); using (SHA1Managed sha1 = new SHA1Managed()) { Random rnd = new Random(); byte[] bytes = new byte[20]; rnd.NextBytes(bytes); hash = Convert.ToBase64String(sha1.ComputeHash(bytes)); } auth = new ImplicitGrantAuth() { RedirectUri = "http://localhost:8000", ClientId = "698a1270914a45a9871fbe96c5dd12e0", Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate, State = hash }; auth.OnResponseReceivedEvent += Auth_OnResponseReceivedEvent; }
public Task <SpotifyWebAPI> GetWebApi() { var authentication = new ImplicitGrantAuth { RedirectUri = $"{_redirectUrl}:{_listeningPort}", ClientId = _clientId, Scope = _scope, State = _xss }; AutoResetEvent authenticationWaitFlag = new AutoResetEvent(false); SpotifyWebAPI spotifyWebApi = null; authentication.OnResponseReceivedEvent += (token, state) => { spotifyWebApi = HandleSpotifyResponse(state, token); authenticationWaitFlag.Set(); }; try { authentication.StartHttpServer(_listeningPort); authentication.DoAuth(); authenticationWaitFlag.WaitOne(_timeout); if (spotifyWebApi == null) { throw new TimeoutException($"No valid response received for the last {_timeout.TotalSeconds} seconds"); } } finally { authentication.StopHttpServer(); } return(Task.FromResult(spotifyWebApi)); }
public Task <bool> GetAuth() { string state = Request.QueryString["state"]; SpotifyAuthServer <Token> auth = ImplicitGrantAuth.GetByState(state); if (auth == null) { return(HttpContext.StringResponseAsync( $"Failed - Unable to find auth request with state \"{state}\" - Please retry")); } Token token; string error = Request.QueryString["error"]; if (error == null) { string accessToken = Request.QueryString["access_token"]; string tokenType = Request.QueryString["token_type"]; string expiresIn = Request.QueryString["expires_in"]; token = new Token { AccessToken = accessToken, ExpiresIn = double.Parse(expiresIn), TokenType = tokenType }; } else { token = new Token { Error = error }; } Task.Factory.StartNew(() => auth.TriggerAuth(token)); return(HttpContext.HtmlResponseAsync("<html><script type=\"text/javascript\">window.close();</script>OK - This window can be closed now</html>")); }
public string GetAuthUrl() { _auth = new ImplicitGrantAuth { RedirectUri = "http://localhost/", ClientId = "7e169a49e74049aeb4980008368dd51d", Scope = Scope.PlaylistReadCollaborative, State = "XSS" }; return _auth.GetUri(); }
private void connectWeb() { try { _auth = new ImplicitGrantAuth { RedirectUri = "http://localhost:88/", ClientId = "7e169a49e74049aeb4980008368dd51d", Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.PlaylistReadCollaborative, State = "XSS" }; _auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent; _auth.StartHttpServer(); _auth.DoAuth(); } catch (Exception e) { Console.WriteLine(e); } }