public void FinishedAuth() { rtmAuth = rtm.AuthGetToken(frob); if (rtmAuth != null) { Preferences prefs = Application.Preferences; prefs.Set(Preferences.AuthTokenKey, rtmAuth.Token); if (rtmAuth.User != null) { prefs.Set(Preferences.UserNameKey, rtmAuth.User.Username); prefs.Set(Preferences.UserIdKey, rtmAuth.User.UserId); } } string authToken = Application.Preferences.Get(Preferences.AuthTokenKey); if (authToken != null) { Logger.Debug("Found AuthToken, checking credentials..."); try { rtm = new Rtm(apiKey, sharedSecret, authToken); rtmAuth = rtm.AuthCheckToken(authToken); timeline = rtm.TimelineCreate(); Logger.Debug("RTM Auth Token is valid!"); Logger.Debug("Setting configured status to true"); configured = true; Refresh(); } catch (Exception e) { rtm = null; rtmAuth = null; Logger.Error("Exception authenticating, reverting" + e.Message); } } }
public void Initialize() { // ************************************* // AUTHENTICATION to Remember The Milk // ************************************* string authToken = Application.Preferences.Get(Preferences.AuthTokenKey); if (authToken != null) { Logger.Debug("Found AuthToken, checking credentials..."); try { rtm = new Rtm(apiKey, sharedSecret, authToken); rtmAuth = rtm.AuthCheckToken(authToken); timeline = rtm.TimelineCreate(); Logger.Debug("RTM Auth Token is valid!"); Logger.Debug("Setting configured status to true"); configured = true; } catch (RtmNet.RtmApiException e) { Application.Preferences.Set(Preferences.AuthTokenKey, null); Application.Preferences.Set(Preferences.UserIdKey, null); Application.Preferences.Set(Preferences.UserNameKey, null); rtm = null; rtmAuth = null; Logger.Error("Exception authenticating, reverting" + e.Message); } catch (RtmNet.RtmWebException e) { rtm = null; rtmAuth = null; Logger.Error("Not connected to RTM, maybe proxy: #{0}", e.Message); } catch (System.Net.WebException e) { rtm = null; rtmAuth = null; Logger.Error("Problem connecting to internet: #{0}", e.Message); } } if (rtm == null) { rtm = new Rtm(apiKey, sharedSecret); } StartThread(); }
/// <summary> /// Initializes the connection to RTM server. /// Verify the stored token with RTM server and if valid also creates the timeline. /// </summary> /// <returns> /// A <see cref="System.Boolean"/>, true if the connection is successfully established, /// false if there is a problem during verfication or timeline creation. /// </returns> static bool TryConnect() { if (!Services.Network.IsConnected) { return(false); } if (!String.IsNullOrEmpty(RTMPreferences.Token)) { Auth auth; try { auth = rtm.AuthCheckToken(RTMPreferences.Token); } catch (RtmException e) { Log <RTM> .Error(AddinManager.CurrentLocalizer.GetString("Token verification failed."), e.Message); return(false); } rtm.AuthToken = auth.Token; username = auth.User.Username; try { timeline = rtm.TimelineCreate(); } catch (RtmException e) { Log <RTM> .Error(AddinManager.CurrentLocalizer.GetString("Remember The Milk timeline creation failed."), e.Message); return(false); } return(true); } else { Log <RTM> .Error(AddinManager.CurrentLocalizer.GetString("Not authorized to use a Remember The Milk account.")); return(false); } }