Skip to content

Commit 302a0b2

Browse files
committed
Issue 447
1 parent 60eb345 commit 302a0b2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenByInteractiveFlowSupplier.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ private void updateRedirectUrl() {
108108
}
109109

110110
private void openDefaultSystemBrowser(URL url) {
111+
String os = System.getProperty("os.name").toLowerCase();
112+
if (os.contains("windows")) {
113+
openDefaultSystemBrowserInWindows(url);
114+
} else if (os.contains("mac")) { // mac os
115+
openDefaultSystemBrowserInMac(url);
116+
} else if(os.contains("nux") || os.contains("nix")) { //linux or unix os
117+
openDefaultSystemBrowserInLinux(url);
118+
}
119+
}
120+
121+
private static void openDefaultSystemBrowserInWindows(URL url){
111122
try {
112123
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
113124
Desktop.getDesktop().browse(url.toURI());
@@ -121,6 +132,24 @@ private void openDefaultSystemBrowser(URL url) {
121132
}
122133
}
123134

135+
private static void openDefaultSystemBrowserInMac(URL url){
136+
Runtime runtime = Runtime.getRuntime();
137+
try {
138+
runtime.exec("open " + url);
139+
} catch (IOException e) {
140+
throw new RuntimeException(e);
141+
}
142+
}
143+
144+
private static void openDefaultSystemBrowserInLinux(URL url){
145+
Runtime runtime = Runtime.getRuntime();
146+
try {
147+
runtime.exec("xdg-open " + url);
148+
} catch (IOException e) {
149+
throw new RuntimeException(e);
150+
}
151+
}
152+
124153
private AuthorizationResult getAuthorizationResultFromHttpListener() {
125154
AuthorizationResult result = null;
126155
try {

0 commit comments

Comments
 (0)