private WindowsFormsWebAuthenticationDialog GetWebAuthenticationDialog(int totalWaitMilliseconds) { WindowsFormsWebAuthenticationDialog webAuthenticationDialog = null; const int EachWaitMilliseconds = 200; do { try { webAuthenticationDialog = Enumerable.OfType <WindowsFormsWebAuthenticationDialog>(Application.OpenForms).Single(); } catch (InvalidOperationException) { Verify.Fail("Unable to find auth dialog"); } if (webAuthenticationDialog == null) { Thread.Sleep(EachWaitMilliseconds); totalWaitMilliseconds -= EachWaitMilliseconds; } }while (totalWaitMilliseconds > 0 && webAuthenticationDialog == null); return(webAuthenticationDialog); }
public static async Task <DataStore> GetUserTokenFromPopup() { #if DEBUG AuthenticationContext context = new AuthenticationContext("https://login.windows.net/" + Credential.Instance.AAD.TenantId); var url = context.GetAuthorizationRequestUrlAsync(Constants.AzureManagementCoreApi, Constants.MicrosoftClientId, new Uri("https://unittest/redirect.html"), UserIdentifier.AnyUser, "").Result; WindowsFormsWebAuthenticationDialog form = new WindowsFormsWebAuthenticationDialog(null); form.WebBrowser.Navigated += delegate(object sender, WebBrowserNavigatedEventArgs args) { if (args.Url.ToString().StartsWith("https://unittest/redirect.html")) { string tempcode = args.Url.ToString(); tempcode = tempcode.Substring(tempcode.IndexOf("code=") + 5); code = tempcode.Substring(0, tempcode.IndexOf("&")); form.Close(); } ; }; form.WebBrowser.Navigate(url); form.ShowBrowser(); while (string.IsNullOrEmpty(code)) { await Task.Delay(5000); } #endif DataStore datastore = new DataStore(); datastore.AddToDataStore("code", code, DataStoreType.Private); datastore.AddToDataStore("AADTenant", "common", DataStoreType.Private); datastore.AddToDataStore("AADRedirect", "https://unittest/redirect.html"); var result = await TestManager.ExecuteActionAsync("Microsoft-GetAzureToken", datastore); return(result.DataStore); }
public static async Task <string> GetToken(string clientId, string redirectUri) { var url = $"https://www.facebook.com/v2.10/dialog/oauth?client_id={clientId}&redirect_uri={redirectUri}&response_type=code&granted_scopes=manage_pages,publish_pages"; var code = string.Empty; WindowsFormsWebAuthenticationDialog form = new WindowsFormsWebAuthenticationDialog(null); form.WebBrowser.Navigated += delegate(object sender, WebBrowserNavigatedEventArgs args) { if (args.Url.ToString().StartsWith("https://localhost")) { string tempcode = args.Url.ToString(); tempcode = tempcode.Substring(tempcode.IndexOf("code=") + 5); code = tempcode; form.Close(); } ; }; form.WebBrowser.Navigate(url); form.ShowBrowser(); while (string.IsNullOrEmpty(code)) { await Task.Delay(5000); } return(code); }
protected override string OnAuthenticate() { string result; using (this.dialog = new WindowsFormsWebAuthenticationDialog(this.OwnerWindow)) { result = this.dialog.AuthenticateAAD(this.RequestUri, this.CallbackUri); } return(result); }
protected override AuthorizationResult OnAuthenticate() { AuthorizationResult result; using (var dialog = new WindowsFormsWebAuthenticationDialog(this.OwnerWindow)) { result = dialog.AuthenticateAAD(this.RequestUri, this.CallbackUri); } return(result); }
protected override AuthorizationResult OnAuthenticate() { AuthorizationResult result; using (this.dialog = new WindowsFormsWebAuthenticationDialog(this.OwnerWindow)) { result = this.dialog.AuthenticateAAD(this.RequestUri, this.CallbackUri); } return result; }
private void UiAbortEventHandler(object sender, ElapsedEventArgs e, Timer uiSupply) { Log.Comment("Test execution timeout"); WindowsFormsWebAuthenticationDialog webAuthenticationDialog = this.GetWebAuthenticationDialog(1000); if (webAuthenticationDialog != null) { ((Form)((WindowsFormsWebAuthenticationDialog)webAuthenticationDialog).WebBrowser.Parent.Parent).Close(); } uiSupply.Stop(); }
protected override AuthorizationResult OnAuthenticate() { AuthorizationResult result; using (_dialog = new WindowsFormsWebAuthenticationDialog(OwnerWindow) { RequestContext = RequestContext }) { result = _dialog.AuthenticateAAD(RequestUri, CallbackUri); } return(result); }
private void UiSupply(WindowsFormsWebAuthenticationDialog webAuthenticationDialog) { if (webAuthenticationDialog != null) { WebBrowser webBrowser = ((WindowsFormsWebAuthenticationDialog)webAuthenticationDialog).WebBrowser; DialogHandler handler = new DialogHandler(); handler.EnterInput(userName, password); UISupplier supplier = new UISupplier(); UISupplier.Results result = supplier.SupplyUIStep(webBrowser, userName, password); if (result == UISupplier.Results.Error) { ((Form)webBrowser.Parent.Parent).Close(); } } }
private void UiSupplyEventHandler(object sender, ElapsedEventArgs e) { WindowsFormsWebAuthenticationDialog webAuthenticationDialog = this.GetWebAuthenticationDialog(5000); webAuthenticationDialog.BeginInvoke(new UiSupplyDelegate(UiSupply), webAuthenticationDialog); }