private static void AddMachineTokenCookie(CookieContainer cookies, CompanionCredentials credentials)
 {
     if (cookies != null && credentials.machineToken != null)
     {
         var machineTokenCookie = new Cookie();
         machineTokenCookie.Domain = "companion.orerve.net";
         machineTokenCookie.Path   = "/";
         machineTokenCookie.Name   = "mtk";
         machineTokenCookie.Value  = credentials.machineToken;
         machineTokenCookie.Secure = true;
         // The expiry is embedded in the cookie value
         if (credentials.machineToken.IndexOf("%7C") == -1)
         {
             machineTokenCookie.Expires = DateTime.Now.AddDays(7);
         }
         else
         {
             string   expiryseconds  = credentials.machineToken.Substring(0, credentials.machineToken.IndexOf("%7C"));
             DateTime expiryDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
             try
             {
                 expiryDateTime             = expiryDateTime.AddSeconds(Convert.ToInt64(expiryseconds));
                 machineTokenCookie.Expires = expiryDateTime;
             }
             catch (Exception)
             {
                 Trace.WriteLine("Failed to handle machine token expiry seconds " + expiryseconds);
                 machineTokenCookie.Expires = DateTime.Now.AddDays(7);
             }
         }
         cookies.Add(machineTokenCookie);
     }
 }
Example #2
0
        static public void DeleteCredentials(string cmdrname)
        {
            CompanionCredentials c = CompanionCredentials.FromFile(cmdrname);

            if (c != null)
            {
                c.Clear();
                c.ToFile();
            }
        }
 public void LoginAs(string cmdrname, string emailadr, string password)      // Restart from afresh with new Credentials file
 {
     if (NeedLogin)
     {
         Credentials = new CompanionCredentials(cmdrname, emailadr, password);         // NOW ready for LOGIN
         Login();
     }
     else
     {
         throw new CompanionAppIllegalStateException("Service in incorrect state to login");
     }
 }
Example #4
0
        static public State CredentialState(string cmdrname)
        {
            CompanionCredentials c = CompanionCredentials.FromFile(cmdrname);

            if (c != null && c.IsComplete)
            {
                return(c.Confirmed ? State.CONFIRMED : State.NEEDS_CONFIRMATION);
            }
            else
            {
                return(State.NO_CREDENTIALS);
            }
        }
 private static void AddCompanionAppCookie(CookieContainer cookies, CompanionCredentials credentials)
 {
     if (cookies != null && credentials.appId != null)
     {
         var appCookie = new Cookie();
         appCookie.Domain = "companion.orerve.net";
         appCookie.Path   = "/";
         appCookie.Name   = "CompanionApp";
         appCookie.Value  = credentials.appId;
         appCookie.Secure = false;
         cookies.Add(appCookie);
     }
 }
        ///<summary>Log in.  Throws an exception if it fails</summary>

        public void LoginAs(string cmdrname)                          // login with previous credientials stored
        {
            if (NeedLogin)
            {
                Credentials = CompanionCredentials.FromFile(cmdrname);      // if file name missing, will not be complete for login

                if (Credentials != null)
                {
                    NeedLogin = false;
                }
                else
                {
                    throw new CompanionAppException("No stored credentials");
                }
            }
            else
            {
                throw new CompanionAppIllegalStateException("Service in incorrect state to login");
            }
        }
Example #7
0
        public static CompanionCredentials FromFile(string cmdrname = null)
        {
            string filename = Path.Combine(EDDConfig.Options.AppDataDirectory, "credentials" + cmdrname.SafeFileString() + ".json");

            try
            {
                if (File.Exists(filename))
                {
                    string credentialsData           = File.ReadAllText(filename);
                    CompanionCredentials credentials = new CompanionCredentials();
                    credentials = JsonConvert.DeserializeObject <CompanionCredentials>(credentialsData);
                    return(credentials);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Failed to read companion credentials" + ex.Message);
            }

            return(null);
        }
 public void Logout()
 {
     NeedLogin   = true;
     Credentials = null;
 }