/// <summary>
 /// Generates a new Authentication Toklen for AppsService 
 /// with the specified credentials for accessing provisioning feeds on the specified domain.
 /// </summary>
 /// <param name="domain">the domain to access</param>
 /// <param name="adminEmailAddress">the administrator's email address</param>
 /// <param name="adminPassword">the administrator's password</param>
 /// <returns>the newly generated authentication token</returns>
 public static String GetNewAuthenticationToken(string domain, string adminEmailAddress, string adminPassword)
 {
     Service service = new Service(AppsNameTable.GAppsService,"apps-"+domain);
     service.setUserCredentials(adminEmailAddress, adminPassword);
     return service.QueryClientLoginToken();
 }
Example #2
0
 /// <summary>
 /// Login here
 /// </summary>
 /// <param name="onFinish">Delegate for when Login is done.</param>
 /// <param name="email">Users e-mail address</param>
 /// <param name="password">Password</param>
 /// <param name="captcha">Captcha string if required</param>
 /// <param name="status">Status to log in as</param>
 public void Login(LoginFinished onFinish, LoginProgressUpdate onUpdate, string email, string password, string captcha, UserStatus status)
 {
     if(Socket.Connected)
     {
         Thread t = new Thread(() =>
                                   {
                                       //TODO Need to add a method to handle 2-step signin.
                                       _onLoginFinished = onFinish;
                                       String appName = "skylabs-LobbyClient-" + Version;
                                       Service s = new Service("code", appName);
                                       s.setUserCredentials(email, password);
                                       if(captcha != null && _mCaptchaToken != null)
                                       {
                                           onUpdate.Invoke("Verifying captcha");
                                           if(!String.IsNullOrWhiteSpace(captcha) || !String.IsNullOrWhiteSpace(_mCaptchaToken))
                                           {
                                               s.Credentials.CaptchaToken = _mCaptchaToken;
                                               s.Credentials.CaptchaAnswer = captcha;
                                           }
                                       }
                                       try
                                       {
                                           Debug.WriteLine("Querying Google...");
                                           onUpdate.Invoke("Logging into Google...");
                                           string ret = s.QueryClientLoginToken();
                                           onUpdate.Invoke("Sending login token to Server...");
                                           Debug.WriteLine("Received login token.");
                                           SocketMessage sm = new SocketMessage("login");
                                           sm.AddData("email", email);
                                           sm.AddData("token", ret);
                                           sm.AddData("status", status);
                                           WriteMessage(sm);
                                           onUpdate.Invoke("Waiting for server response...");
                                       }
                                       catch(CaptchaRequiredException ce)
                                       {
                                           _mCaptchaToken = ce.Token;
                                           if(OnCaptchaRequired != null) OnCaptchaRequired.Invoke("https://www.google.com/accounts/DisplayUnlockCaptcha", ce.Url);
                                       }
                                       catch(AuthenticationException re)
                                       {
                                           string cu = (string)re.Data["CaptchaUrl"];
                                           onFinish.Invoke(LoginResult.Failure, DateTime.Now, re.Message);
                                       }
                                       catch(WebException)
                                       {
                                           onFinish.Invoke(LoginResult.Failure, DateTime.Now, "Connection problem.");
                                       }
                                       onFinish.Invoke(LoginResult.WaitingForResponse, DateTime.Now, "");
                                   });
         t.Start();
     }
 }