private static async Task CheckAuthenticationToken() { // Load a user from JSON var userJson = File.ReadAllText("myRtmUser.json"); var user = Rtm.GetUserFactory().LoadFromJson(userJson); var tokenVerifier = Rtm.GetAuthFactory().CreateTokenVerifier(); try { if (await tokenVerifier.VerifyAsync(user.Token).ConfigureAwait(false)) { Console.WriteLine("Token is still valid."); } else { // Token is expired or otherwise invalid. you'll need to create a new authorization URL // and instruct the user to reauthorize your app. Console.WriteLine("Token is expired or invalid."); } } catch (RtmException ex) { // Some other API error was returned. Console.WriteLine($"RTM Error Code: {ex.ErrorCode}"); Console.WriteLine($"RTM Error Message: {ex.Message}"); } }
private static async Task AuthenticateNewDesktopUser() { // Get an authentication URL for the user. This example will request authorization for READ permissions. try { var desktopAuthenticator = Rtm.GetAuthFactory().CreateDesktopAuthenticator(); var authUrl = await desktopAuthenticator.GetAuthenticationUrlAsync(PermissionLevel.Read).ConfigureAwait(false); // Instruct the user to navigate to the URL and authorize your application. They can continue using // your application after authentication in the web browser is complete. Console.WriteLine($"Step 1: Please navigate to the following URL using a web browser: {authUrl}"); Console.WriteLine("Step 2: Follow the instructions from Remember the Milk to authorize this application to access your RTM account."); Console.WriteLine("Step 3: Press [Enter] when finished"); Console.ReadLine(); var rtmUser = await desktopAuthenticator.GetAutheticatedUserAsync().ConfigureAwait(false); // Save the user data to a file or database. var userJson = rtmUser.ToJson(); File.WriteAllText("myRtmUser.json", userJson); } catch (RtmException ex) { // Read the exception details. There may be an issue with your API Key or Shared Secret, or the user may not // have followed the instructions for authentication. Console.WriteLine($"RTM Error Code: {ex.ErrorCode} -- RTM Error Message: {ex.Message}"); } }
public void GetAuthFactory_ApiIsInitialized_CreatesAuthFactory() { Rtm.Init("test", "test"); var actual = Rtm.GetAuthFactory(); Assert.IsInstanceOf <AuthFactory>(actual); }
public void GetAuthFactory_ApiNotInitialized_ThrowsInvalidOperationException() { Assert.Throws <InvalidOperationException>(() => Rtm.GetAuthFactory()); }