Closed alexanderbecher closed 3 months ago
Hello @alexanderbecher : To clarify, when you say it's "working without UI", you're still using the broker but just with a silent, non-UI flow, right? And the program just locks up as though it's waiting for you to interact with a pop-up window?
When using the WAM broker, what should happen is that a login window pops up asking for the user's credentials. It isn't a browser window (like the normal non-broker interactive flow), and it may be popping up behind something else or on a different screen if you have multiple monitors.
The code looks correct, and since the non-UI flow is working my best guess is that a different window handle is needed. I'm not too familiar with the SWT API, but there may be either a parent or child window for the one you're using that would give better behavior.
You can always try to provide a different window handle like:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdesktopwindow or https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow
to see if the pop-up appears (just for debugging)
Hi @Avery-Dunn , yes I meant non Ui with broker. @bgavrilMS I've tried it with
HWND foregroundWindow = com.sun.jna.platform.win32.User32.INSTANCE.GetDesktopWindow();
long nativeValue = com.sun.jna.Pointer.nativeValue(foregroundWindow.getPointer());
this doesn't work from my SWT example, it still locks up and show no browser window. However when I try this with a Swing example it opens the browser window:
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.sun.jna.platform.win32.WinDef.HWND;
public class SwingExample {
public static void main(String[] args) {
JFrame frame = new JFrame("TestWindow");
frame.setVisible(true);
frame.setSize(500, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
JButton button = new JButton("Interactive auth");
panel.add(button);
button.addActionListener(e -> {
System.out.println("test");
HWND foregroundWindow = com.sun.jna.platform.win32.User32.INSTANCE.GetDesktopWindow();
long nativeValue = com.sun.jna.Pointer.nativeValue(foregroundWindow.getPointer());
WamSWTExample wamSWTExample = new WamSWTExample();
try {
wamSWTExample.authenticate(nativeValue);
} catch (IOException e1) {
e1.printStackTrace();
}
});
}
}
Workaround is to use system browser instead of broker.
Ok, I've managed to get it running. You just need another thread that's not the UIThread:
new Thread(() -> {
try {
authenticate(handle);
} catch (IOException e1) {
e1.printStackTrace();
}
}).start();
Library version used
1.15.0
Java version
17
Scenario
PublicClient (AcquireTokenInteractive, AcquireTokenByUsernamePassword)
Is this a new or an existing app?
This is a new app or experiment
Issue description and reproduction steps
I'm trying to call acquireToken with the broker from a SWT UI. This just locks up the program and never shows a browser window. Same code is working without UI. I thin I've provided the correct window handle but it doesn't work. Cant't figure out where and why it locks up. Log from unsuccessful attempt:
Am I doing something wrong?
Relevant code snippets
Expected behavior
No response
Identity provider
Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)
Regression
No response
Solution and workarounds
No response