public SpotifyUserAccessToken(Token oSpotifyToken) { this._Code = oSpotifyToken.AccessToken; this._TokenType = oSpotifyToken.TokenType; this._ExpiresIn = oSpotifyToken.ExpiresIn; this._TokenDate = oSpotifyToken.CreateDate; }
private void OnAuthorizationRecieved(object sender, AuthorizationCode payload) { AuthorizationCodeAuth auth = sender as AuthorizationCodeAuth; auth.Stop(); SAPIModels.Token token = auth.ExchangeCode(payload.Code).Result; Analysis.Log($"Gained the initial Spotify authorization at '{token.CreateDate}", Analysis.LogLevel.Vital); Configure(token, auth); }
private SpotifyWebAPI ApiFromToken(SpotifyAPI.Web.Models.Token token) { var spotifyWebAPI = new SpotifyWebAPI() { UseAuth = true, AccessToken = token.AccessToken, TokenType = token.TokenType }; return(spotifyWebAPI); }
protected override void GotAuth(SAPIModels.Token token, AuthorizationCodeAuth auth) { base.GotAuth(token, auth); if (string.IsNullOrEmpty(m_refreshToken) && !string.IsNullOrEmpty(token.RefreshToken)) { m_refreshToken = token.RefreshToken; } if (ReuseAuthTokens && auth != null && token != null) { EventManager.QueueEvent(new RunRefreshToken(auth, (float)token.ExpiresIn, token.CreateDate, m_refreshToken)); } }
private static async void AuthOnAuthReceived(object sender, AuthorizationCode payload) { AuthorizationCodeAuth auth = (AuthorizationCodeAuth)sender; auth.Stop(); SpotifyAPI.Web.Models.Token token = await auth.ExchangeCode(payload); SpotifyWebAPI api = new SpotifyWebAPI { AccessToken = token.AccessToken, TokenType = token.TokenType }; PrintUsefulData(api); }
private async Task RefreshTokenAndConfigure(AuthorizationCodeAuth auth, string refreshToken) { SAPIModels.Token token = await auth.RefreshToken(refreshToken); // Inject RefreshToken back into after each re-auth token.RefreshToken = m_refreshToken; if (token != null && token.Error == null) { m_refreshTokenRoutine = null; Analysis.Log($"Obtained a new authorization token at '{token.CreateDate}'", Analysis.LogLevel.Vital); Configure(token, auth); } else { string errorMsg = token != null ? $"Error - {token.Error}" : "Token is null"; Analysis.LogError($"Unable to refresh authorization token - {errorMsg}", Analysis.LogLevel.Vital); } }
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(); }
public SpotifyUser(PrivateProfile oPrivateProfile, string sAuthCode, Token oToken) { this._SpotifyID = oPrivateProfile.Id; this._Name = oPrivateProfile.Id; this._ID = SpotifyAccessLayer.GetObjectIDForSpotifyID(this._SpotifyID); string sAccessCode = oToken.AccessToken; string sRefreshCode = oToken.RefreshToken; string sAccessTokenType = oToken.TokenType; int iAccessExpiresIn = oToken.ExpiresIn; DateTime dtToken = oToken.CreateDate.ToUniversalTime(); DateTime dtAuth = oToken.CreateDate.ToUniversalTime(); this._UserAuth = new SpotifyUserAuth(sAuthCode, dtAuth); SaveUserAndAuthToDatabase(); this._RefreshToken = new SpotifyUserRefreshToken(sRefreshCode, dtToken); SaveRefreshTokenToDatebase(); this._AccessToken = new SpotifyUserAccessToken(sAccessCode, sAccessTokenType, iAccessExpiresIn, dtToken); SaveAccessTokenToDatabase(); this._UserGuid = SpotifyAccessLayer.GetUserGuidForUserID(this._ID); }
void _auth_OnResponseReceivedEvent(Token token, string state) { _auth.StopHttpServer(); if (state != "XSS") { MessageBox.Show("Wrong state received.", "SpotifyWeb API Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (token.Error != null) { MessageBox.Show("Error: " + token.Error, "SpotifyWeb API Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _spotify = new SpotifyWebAPI { UseAuth = true, AccessToken = token.AccessToken, TokenType = token.TokenType }; InitialSetup(); }
private void _authentication_OnResponseReceivedEvent(Token token, string state) { _authentication.StopHttpServer(); try { if (state != _state) throw new InvalidOperationException($"{nameof(SpotifyService)} - Wrong state received"); if (token.Error != null) throw new InvalidOperationException($"{nameof(SpotifyService)} - Error: {token.Error}"); Settings.Default.Token = token.AccessToken; Settings.Default.TokenType = token.TokenType; Settings.Default.TokenExpirationDate = DateTime.Now + TimeSpan.FromSeconds(token.ExpiresIn); Settings.Default.Save(); InitSpotifyWebAPI(); } finally { _authenticationSemaphore.Release(); } }
private void HttpServerOnOnAuth(AuthEventArgs e) { Token t = new Token() { AccessToken = e.Code, TokenType = e.TokenType, ExpiresIn = e.ExpiresIn, Error = e.Error }; if (OnResponseReceivedEvent != null) OnResponseReceivedEvent(t, e.State); }
public SpotifyUser AddSpotifyUser(PrivateProfile oPrivateProfile, string sAuthCode, Token oToken) { SpotifyUser oSpotifyUser = new SpotifyUser(oPrivateProfile, sAuthCode, oToken); return oSpotifyUser; }
private SpotifyWebAPI HandleSpotifyResponse(string state, Token token) { if (state != _xss) throw new SpotifyWebApiException($"Wrong state '{state}' received."); if (token.Error != null) throw new SpotifyWebApiException($"Error: {token.Error}"); var spotifyWebApi = new SpotifyWebAPI { UseAuth = true, AccessToken = token.AccessToken, TokenType = token.TokenType }; return spotifyWebApi; }
void _auth_OnResponseReceivedEvent(Token token, string state) { _auth.StopHttpServer(); if (state != "XSS") { return; } if (token.Error != null) { return; } _spotify = new SpotifyAPI.Web.SpotifyWebAPI { UseAuth = true, AccessToken = token.AccessToken, TokenType = token.TokenType }; check = false; }
public void UpdateUserWithToken(Token oToken) { this._RefreshToken = new SpotifyUserRefreshToken(oToken); SaveRefreshTokenToDatebase(); this._AccessToken = new SpotifyUserAccessToken(oToken); SaveAccessTokenToDatabase(); }
private void handleAccessToken(string accessToken) { var token = new Token() { //TokenType = AccessToken = accessToken, TokenType = "Bearer" }; authenticate(token); }
private void authenticate(Token token) { _spotifyWeb = new SpotifyWebAPI { UseAuth = true, AccessToken = token.AccessToken, TokenType = token.TokenType }; ConnectedWeb = true; }
public SpotifyUserRefreshToken(Token oSpotifyToken) { this._Code = oSpotifyToken.RefreshToken; this._TokenDate = oSpotifyToken.CreateDate.ToUniversalTime(); }