Skip to content

Commit f0290fa

Browse files
committed
WebControl with new AuthenticationFactory
1 parent d21e844 commit f0290fa

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

‎SpotifyAPI.Example/WebControl.cs‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.Linq;
99
using System.Net;
10+
using System.Threading.Tasks;
1011
using System.Windows.Forms;
1112
using Image = System.Drawing.Image;
1213

@@ -26,14 +27,7 @@ public WebControl()
2627
InitializeComponent();
2728

2829
_savedTracks = new List<FullTrack>();
29-
_auth = new ImplicitGrantAuth
30-
{
31-
RedirectUri = "http://localhost:8000",
32-
ClientId = "26d287105e31491889f3cd293d85bfea",
33-
Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead,
34-
State = "XSS"
35-
};
36-
_auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;
30+
3731
}
3832

3933
private void _auth_OnResponseReceivedEvent(Token token, string state)
@@ -57,7 +51,7 @@ private void _auth_OnResponseReceivedEvent(Token token, string state)
5751
AccessToken = token.AccessToken,
5852
TokenType = token.TokenType
5953
};
60-
InitialSetup();
54+
6155
}
6256

6357
private async void InitialSetup()
@@ -129,8 +123,32 @@ private List<SimplePlaylist> GetPlaylists()
129123

130124
private void authButton_Click(object sender, EventArgs e)
131125
{
132-
_auth.StartHttpServer(8000);
133-
_auth.DoAuth();
126+
Task.Run(() => RunAuthentication());
127+
}
128+
129+
private async void RunAuthentication()
130+
{
131+
AuthenticationFactory authenticationFactory = new AuthenticationFactory(
132+
"http://localhost",
133+
8000,
134+
"26d287105e31491889f3cd293d85bfea",
135+
Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead |
136+
Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead,
137+
TimeSpan.FromSeconds(20));
138+
139+
try
140+
{
141+
_spotify = await authenticationFactory.GetWebApi();
142+
}
143+
catch (Exception ex)
144+
{
145+
MessageBox.Show(ex.Message);
146+
}
147+
148+
if (_spotify == null)
149+
return;
150+
151+
InitialSetup();
134152
}
135153
}
136154
}

0 commit comments

Comments
 (0)