this is a great tool, and i can't believe nobody is using it!

Nov 19, 2008 at 3:42 AM
btw, this is how i get an authenticated rtm client

    class RtmHelper
    {
        const string RegPath = "Software\\IronCow\\RTMClient";
        const string RegKey = "RtmAuthToken";

        const string apiKey = "<apikey>";
        const string sharedSecret = "<sharedsecret>";

        static Rtm _rtm = null;
        public static Rtm rtm { get { if (_rtm == null) _rtm = GetAuthenticatedRtm(); return _rtm; } }

        private static Rtm GetAuthenticatedRtm()
        {
            Rtm rtm = new Rtm(apiKey, sharedSecret);
            rtm.AuthToken = GetAuthToken(rtm);
            return rtm;
        }

        private static string GetStoredAuthToken()
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(RegPath);

            if (key == null)
                return null;

            object value;
            if ((value = key.GetValue(RegKey)) != null && value is string)
            {
                return (string)value;
            }
            return null;
        }

        private static string GetAuthToken(Rtm rtm)
        {
            Authentication auth;
            string storedToken = GetStoredAuthToken();
            if (!string.IsNullOrEmpty(storedToken) && rtm.CheckToken(storedToken, out auth))
            {
                return storedToken;
            }
            else
            {
                string frob = rtm.GetFrob();
                string url = rtm.GetAuthenticationUrl(frob, AuthenticationPermissions.Delete);
                Process.Start(url);
                MessageBox.Show("Please authorize this application.");
                storedToken = rtm.GetToken(frob);
                SetStoredAuthToken(storedToken);
                return storedToken;
            }
        }

        private static void SetStoredAuthToken(string token)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(RegPath, true);

            if (key == null)
            {
                key = Registry.CurrentUser.CreateSubKey(RegPath);
            }

            key.SetValue(RegKey, token);
        }
    }
Coordinator
Dec 1, 2008 at 12:41 AM
Hey, thanks for the code sample. I'll try to integrate it to the source code.
I'll also soon move all the code to be hosted on CodePlex so it's easier for people to submit patches.