From 25ff0b4db9f6d5ebe2b2c0f7780e285ec5b91b1a Mon Sep 17 00:00:00 2001 From: konczdev Date: Sat, 15 Feb 2025 07:57:24 +0100 Subject: [PATCH] [Win32] Add SSO support for SWT Browser using Edge backend Introduces a new system property to enable Single Sign-On: - org.eclipse.swt.browser.Edge.allowSingleSignOnUsingOSPrimaryAccount This allows SWT Browser to use the logged-in Windows account for SSO with Azure AD resources and Microsoft account-enabled websites when using the Edge backend. --- .../win32/org/eclipse/swt/browser/Edge.java | 9 +++++++++ bundles/org.eclipse.swt/Readme.WebView2.md | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java index ddc76473035..e4a20c1ab20 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java @@ -50,6 +50,7 @@ class Edge extends WebBrowser { // System.getProperty() keys static final String BROWSER_DIR_PROP = "org.eclipse.swt.browser.EdgeDir"; static final String BROWSER_ARGS_PROP = "org.eclipse.swt.browser.EdgeArgs"; + static final String ALLOW_SINGLE_SIGN_ON_USING_OS_PRIMARY_ACCOUNT_PROP = "org.eclipse.swt.browser.Edge.allowSingleSignOnUsingOSPrimaryAccount"; static final String DATA_DIR_PROP = "org.eclipse.swt.browser.EdgeDataDir"; static final String LANGUAGE_PROP = "org.eclipse.swt.browser.EdgeLanguage"; static final String VERSIONT_PROP = "org.eclipse.swt.browser.EdgeVersion"; @@ -563,6 +564,9 @@ WebViewEnvironment createEnvironment() { String browserDir = System.getProperty(BROWSER_DIR_PROP); String browserArgs = System.getProperty(BROWSER_ARGS_PROP); String language = System.getProperty(LANGUAGE_PROP); + + boolean allowSSO = Boolean.getBoolean(ALLOW_SINGLE_SIGN_ON_USING_OS_PRIMARY_ACCOUNT_PROP); + String dataDir = getDataDir(display); // Initialize options @@ -580,6 +584,11 @@ WebViewEnvironment createEnvironment() { options.put_Language(pLanguage); } + if (allowSSO) { + int[] pAllowSSO = new int[]{1}; + options.put_AllowSingleSignOnUsingOSPrimaryAccount(pAllowSSO); + } + // Create the environment char[] pBrowserDir = stringToWstr(browserDir); char[] pDataDir = stringToWstr(dataDir); diff --git a/bundles/org.eclipse.swt/Readme.WebView2.md b/bundles/org.eclipse.swt/Readme.WebView2.md index 55b52d210cf..2dfe451c431 100644 --- a/bundles/org.eclipse.swt/Readme.WebView2.md +++ b/bundles/org.eclipse.swt/Readme.WebView2.md @@ -67,6 +67,10 @@ language+country code that defines the browser UI language and preferred language for HTTP requests (`Accept-Languages` header). Example values: `en`, `ja`, `en-GB`, `de-AT`. +The property `org.eclipse.swt.browser.Edge.allowSingleSignOnUsingOSPrimaryAccount` enables Single Sign-On with Azure Active Directory (AAD) resources using the logged-in Windows account. This also enables SSO with websites using Microsoft accounts associated with the Windows login. Setting this property to true enables this feature. The default value is false. + +See also: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2environmentoptions.allowsinglesignonusingosprimaryaccount + _Note_: All of the properties described above must be set before the first instance of the `Browser` with `SWT.EDGE` style is created.