public void Connect() { if (IsConnected) { _client.AddWarningLog("Connect: already connected"); return; } do { if (!_client.VerificationCode.IsEmpty() && _reqToken != null) { try { _client.AddDebugLog("getting access token with code {0}", _client.VerificationCode); AccessToken = Api.GetAccessToken(_reqToken, _client.VerificationCode); SetConnectionState(true); return; } catch (ETradeException) { _client.VerificationCode = null; throw; } } if (AccessToken != null) { try { AccessToken = Api.RenewAccessToken(AccessToken); _client.AddDebugLog("renew of access token successful"); SetConnectionState(true); return; } catch (Exception e) { _client.AddWarningLog("unable to renew access token: {0}", e); AccessToken = null; } } _client.AddDebugLog("getting request token"); _reqToken = Api.GetRequestToken(); _client.VerificationCode = null; _client.AddDebugLog("starting authorization"); AuthorizationAction(Api.GetAuthorizeUrl(_reqToken)); } while (!_client.VerificationCode.IsEmpty()); }
private void SetConnectionState(bool isConnected) { _client.VerificationCode = null; _reqToken = null; if (IsConnected == isConnected) return; _client.AddDebugLog("Etrade: {0}", isConnected ? "connected" : "disconnected"); if (isConnected) { Api.SetAuthenticator(AccessToken); _reconnecting = false; } else { Api.SetAuthenticator(null); } IsConnected = isConnected; ConnectionStateChanged.SafeInvoke(); }
public string GetAuthorizeUrl(OAuthToken requestToken) { return("https://us.etrade.com/e/t/etws/authorize?key={0}&token={1}".Put(ConsumerKey, requestToken.Token)); }
public void SetAuthenticator(OAuthToken accessToken) { _authenticator = accessToken == null ? null : OAuth1Authenticator.ForProtectedResource(ConsumerKey, ConsumerSecret.To <string>(), accessToken.Token, accessToken.Secret); }