private void btnAdminUserToggleToopherEnabled_Click(object sender, EventArgs e) { try { if (adminUserIsKnown) { ToopherSettings settings = new ToopherSettings(); Toopher.ToopherAPI api = new Toopher.ToopherAPI(settings.ToopherConsumerKey, settings.ToopherConsumerSecret, baseUrl: settings.ToopherBaseUrl); api.SetToopherEnabledForUser(adminUserName, !adminUserEnabled); } } finally { loadUserPairingStatus(); } }
private void btnSaveSettings_Click(object sender, EventArgs e) { ToopherSettings settings = new ToopherSettings(); settings.ToopherConsumerKey = tbApiKey.Text; settings.ToopherConsumerSecret = tbApiSecret.Text; settings.ToopherBaseUrl = tbApiUrl.Text; settings.AllowInlinePairing = cbAllowInlinePairing.Checked; settings.IsDefaultTile = cbSetDefaultCP.Checked; settings.DebugMode = cbDebugMode.Checked; FormDirty = false; }
private static void RegisterAndEnableCredentialProvider() { Toopher.CredentialProvider.Registration.CredProviderManager cpManager = Toopher.CredentialProvider.Registration.CredProviderManager.GetManager(); ToopherSettings tSettings = new ToopherSettings(); tSettings.ToopherAuthExePath = ConfigureSubOptions.DefaultAuthExePath(); cpManager.CpInfo.OpMode = Toopher.CredentialProvider.Registration.OperationMode.INSTALL; cpManager.ExecuteDefaultAction(); cpManager.CpInfo.OpMode = Toopher.CredentialProvider.Registration.OperationMode.ENABLE; cpManager.ExecuteDefaultAction(); }
private void loadUserPairingStatus() { if (this.InvokeRequired) { this.Invoke((Action) delegate { loadUserPairingStatus(); }); } else { adminUserName = tbAdminUsername.Text.ToLower(); ToopherSettings settings = new ToopherSettings(); Toopher.ToopherAPI api = new Toopher.ToopherAPI(settings.ToopherConsumerKey, settings.ToopherConsumerSecret, baseUrl: settings.ToopherBaseUrl); adminUserIsKnown = false; adminUserPaired = false; adminUserEnabled = false; try { IDictionary <string, object> userData = api.SearchForUser(adminUserName); adminUserPairings = api.GetUserPairings(adminUserName); adminUserPaired = adminUserPairings.Any((p) => p.enabled && !(p["deactivated"].ToString().ToLower() == "true")); if (userData.ContainsKey("disable_toopher_auth")) { adminUserEnabled = userData["disable_toopher_auth"].ToString().ToLower() != "true"; } else { adminUserEnabled = true; } adminUserIsKnown = true; } catch (Toopher.RequestError err) { adminUserIsKnown = false; if (err.Message == "No users with name = " + adminUserName) { // effectively the same as a UserUnknownError - ignore } else { pnlAdminUserStatus.Visible = false; MetroFramework.MetroMessageBox.Show(this, "Error retrieving user data: " + err.Message); } } pnlAdminUserStatus.Visible = true; pnlAdminUserStatus.Enabled = true; updatePairedStatusGuiElements(); } }
private void btnAdminPairUnpairUser_Click(object sender, EventArgs e) { ToopherSettings settings = new ToopherSettings(); Toopher.ToopherAPI api = new Toopher.ToopherAPI(settings.ToopherConsumerKey, settings.ToopherConsumerSecret, baseUrl: settings.ToopherBaseUrl); if (adminUserPaired) { try { pnlAdminUserStatus.Enabled = false; foreach (var pairing in adminUserPairings) { api.DeactivatePairing(pairing.id); } } finally { loadUserPairingStatus(); } } else { PromptForm f = new PromptForm("Enter a Toopher Pairing Phrase"); f.ShowDialog(); string pairingPhrase = f.tbUserInput.Text.ToLower(); LogUI logUI = new LogUI("Pairing with Toopher"); logUI.Show(); Action pairingTask = () => { try { Toopher.PairingStatus pairing = api.Pair(pairingPhrase, adminUserName); while (pairing.pending && !pairing.enabled) { Thread.Sleep(200); logUI.OnLog("checking pairing status..."); pairing = api.GetPairingStatus(pairing.id); } logUI.OnLog("Pairing Result: " + (pairing.enabled ? "Enabled" : "Denied")); } finally { logUI.OnDone(); loadUserPairingStatus(); } }; new Task(pairingTask).Start(); } }
public AuthenticationJob(string userName, string terminalIdentifier, bool start = false) { this.userName = userName.ToLower(); this.terminalIdentifier = terminalIdentifier; this.IsRunning = false; this.IsDone = false; this.IsCancelled = false; toopherSettings = new ToopherSettings(); String baseUrl = null; if (!string.IsNullOrEmpty(toopherSettings.ToopherBaseUrl)) { baseUrl = toopherSettings.ToopherBaseUrl; } this.api = new ToopherAPI(toopherSettings.ToopherConsumerKey, toopherSettings.ToopherConsumerSecret, baseUrl: baseUrl); if (start) { Start(); } }
private void LoadConfig() { ToopherSettings settings = new ToopherSettings(); tbApiKey.Text = settings.ToopherConsumerKey; tbApiSecret.Text = settings.ToopherConsumerSecret; string configuredUrl = settings.ToopherBaseUrl; if (String.IsNullOrEmpty(configuredUrl)) { configuredUrl = Toopher.ToopherAPI.DEFAULT_BASE_URL; } tbApiUrl.Text = configuredUrl; cbAllowInlinePairing.Checked = settings.AllowInlinePairing; cbSetDefaultCP.Checked = settings.IsDefaultTile; cbDebugMode.Checked = settings.DebugMode; FormDirty = false; }
public AuthenticationStatusUI(AuthenticationJob theJob) { this.job = theJob; settings = new ToopherSettings(); debugMode = settings.DebugMode; InitializeComponent(); debugTextBox.Visible = debugMode; job.InfoStatus += updateTitle; job.DebugStatus += updateStatus; job.Done += jobDone; job.PromptUser += promptUser; inputPanel.Visible = false; if (!job.IsRunning) { job.Start(); } doLayout(); }
static int Main(String[] args) { ToopherSettings settings = new ToopherSettings(); if (!settings.IsConfigured) { MessageBox.Show("Toopher CredentialProvider has not been configured. Toopher Authentication is not currently active. Please contact your administrator."); return(AuthenticationJob.SUCCESS); } string userName = string.Empty; if (args.Length > 0) { userName = args[0]; } else { userName = WinApiMethods.getTerminalInfoString(WinApiMethods.WTS_INFO_CLASS.WTSUserName); } if (string.IsNullOrEmpty(userName)) { return(AuthenticationJob.SUCCESS); } AuthenticationJob job = new AuthenticationJob(userName, WinApiMethods.buildTerminalIdentifier(), start: false); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AuthenticationStatusUI form = new AuthenticationStatusUI(job); Application.Run(form); int result = job.GetAuthenticationResult(); return(result); }
static void Main(string[] args) { Options options = new Options(); String invokedVerb = ""; Object invokedVerbInstance = null; if (!CommandLine.Parser.Default.ParseArguments(args, options, (verb, subOptions) => { invokedVerb = verb; invokedVerbInstance = subOptions; })) { RunGui(); } if (invokedVerbInstance is GuiSubOptions) { RunGui(); } else if (invokedVerbInstance is GetConfigSubOptions) { ToopherSettings cLib = new ToopherSettings(); Console.WriteLine("ToopherBaseUrl = " + cLib.ToopherBaseUrl ?? "(not configured)"); Console.WriteLine("ToopherConsumerKey = " + cLib.ToopherConsumerKey ?? "(not configured)"); Console.WriteLine("ToopherConsumerSecret = " + cLib.ToopherConsumerSecret ?? "(not configured)"); Console.WriteLine("ToopherAuthExe = " + cLib.ToopherAuthExePath ?? "(not configured)"); Console.WriteLine("IsDefault = " + (cLib.IsDefaultTile ? "True" : "False")); Console.WriteLine("AllowInlinePairing = " + (cLib.AllowInlinePairing ? "True" : "False")); Console.WriteLine("DebugMode = " + (cLib.DebugMode ? "True" : "False")); } else if (invokedVerbInstance is ConfigureSubOptions) { ConfigureSubOptions o = invokedVerbInstance as ConfigureSubOptions; ToopherSettings cLib = new ToopherSettings(); if (!string.IsNullOrEmpty(o.Key)) { cLib.ToopherConsumerKey = o.Key; } if (!string.IsNullOrEmpty(o.Secret)) { cLib.ToopherConsumerSecret = o.Secret; } if (!string.IsNullOrEmpty(o.BaseUrl)) { cLib.ToopherBaseUrl = o.BaseUrl; } if (!string.IsNullOrEmpty(o.ToopherAuthExePath)) { cLib.ToopherAuthExePath = o.ToopherAuthExePath; } else { // make sure ToopherAuthExePath gets a default value if necessary if (string.IsNullOrEmpty(cLib.ToopherAuthExePath)) { cLib.ToopherAuthExePath = ConfigureSubOptions.DefaultAuthExePath(); } } if (o.SetDefault) { cLib.IsDefaultTile = true; } if (o.UnsetDefault) { cLib.IsDefaultTile = false; } if (o.AllowInlinePairing) { cLib.AllowInlinePairing = true; } if (o.NoInlinePairing) { cLib.AllowInlinePairing = false; } if (o.EnableDebugMode) { cLib.DebugMode = true; } if (o.DisableDebugMode) { cLib.DebugMode = false; } } else if (invokedVerbInstance is InstallSubOptions) { InstallUtil.DoInstall(); } else if (invokedVerbInstance is UninstallSubOptions) { InstallUtil.DoUninstall(); } }