Exemplo n.º 1
0
 void Authenticate(IOAuth1Authenticator auth, AuthProvider ap, List <Account> accounts)
 {
     if (accounts.Count == 0)
     {
         auth.Completed += (sender, eventArgs) =>
         {
             if (eventArgs.IsAuthenticated)
             {
                 try
                 {
                     AccountStore.Create().Save(eventArgs.Account, ap.name);
                     PerformAuth1TestRequests(ap, eventArgs.Account);
                 }
                 catch (Exception ex)
                 {
                     ErrorText = ex.Message;
                 }
             }
             else
             {
                 ErrorText = "Authenticate: Not Authenticated";
                 return;
             }
         };
         auth.Error += (sender, eventArgs) =>
         {
             ErrorText += "Authenticate: Error:" + eventArgs.Message + "\n";
             for (Exception inner = eventArgs.Exception; inner != null; inner = inner.InnerException)
             {
                 ErrorText += "Message:" + inner.Message + "\n";
             }
             return;
         };
         try
         {
             auth.OAuth1Authenticator(ap.consumerKey, ap.consumerSecret, new Uri(ap.requestTokenUrl), new Uri(ap.authorizeUrl), new Uri(ap.accessTokenUrl), new Uri(ap.callbackUrl), null);
         }
         catch (Exception ex)
         {
             ErrorText += "Authenticate: Exception:";
             for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException)
             {
                 ErrorText += "Message:" + inner.Message + "\n";
             }
         }
     }
     else
     {
         PerformAuth1TestRequests(ap, accounts[0]); // TODO: implement error handling. If error is caused by expired token, renew token.
     }
 }
Exemplo n.º 2
0
 void Authenticate(IOAuth1Authenticator auth, AuthProvider ap, List<Account> accounts)
 {
     if (accounts.Count == 0)
     {
         auth.Completed += (sender, eventArgs) =>
         {
             if (eventArgs.IsAuthenticated)
             {
                 try
                 {
                     AccountStore.Create().Save(eventArgs.Account, ap.name);
                     PerformAuth1TestRequests(ap, eventArgs.Account);
                 }
                 catch (Exception ex)
                 {
                     ErrorText = ex.Message;
                 }
             }
             else
             {
                 ErrorText = "Authenticate: Not Authenticated";
                 return;
             }
         };
         auth.Error += (sender, eventArgs) =>
         {
             ErrorText += "Authenticate: Error:" + eventArgs.Message + "\n";
             for (Exception inner = eventArgs.Exception; inner != null; inner = inner.InnerException)
             {
                 ErrorText += "Message:" + inner.Message + "\n";
             }
             return;
         };
         try
         {
             auth.OAuth1Authenticator(ap.consumerKey, ap.consumerSecret, new Uri(ap.requestTokenUrl), new Uri(ap.authorizeUrl), new Uri(ap.accessTokenUrl), new Uri(ap.callbackUrl), null);
         }
         catch (Exception ex)
         {
             ErrorText += "Authenticate: Exception:";
             for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException)
             {
                 ErrorText += "Message:" + inner.Message + "\n";
             }
         }
     }
     else
         PerformAuth1TestRequests(ap, accounts[0]); // TODO: implement error handling. If error is caused by expired token, renew token.
 }