From 002ec986c769d1e5cac062988b63307919b90f05 Mon Sep 17 00:00:00 2001 From: Martin Lingstuyl Date: Wed, 26 Sep 2018 09:53:12 +0200 Subject: [PATCH] Set PromptBehavior to Auto if token flow is initiated with 'prompt=' as part of extraQueryParameters. --- src/android/CordovaAdalPlugin.java | 4 +++- src/ios/CordovaAdalPlugin.m | 2 +- src/windows/ADALProxy.js | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/android/CordovaAdalPlugin.java b/src/android/CordovaAdalPlugin.java index 3d7dc8b..37b9264 100644 --- a/src/android/CordovaAdalPlugin.java +++ b/src/android/CordovaAdalPlugin.java @@ -40,6 +40,8 @@ public class CordovaAdalPlugin extends CordovaPlugin { private static final PromptBehavior SHOW_PROMPT_ALWAYS = PromptBehavior.Always; + private static final PromptBehavior SHOW_PROMPT_AUTO = PromptBehavior.Auto; + private static final int GET_ACCOUNTS_PERMISSION_REQ_CODE = 0; private static final String PERMISSION_DENIED_ERROR = "Permissions denied"; @@ -207,7 +209,7 @@ private void acquireTokenAsync(String authority, boolean validateAuthority, Stri clientId, redirectUrl, userId, - SHOW_PROMPT_ALWAYS, + (extraQueryParams != null && extraQueryParams.contains("prompt=")) ? SHOW_PROMPT_AUTO : SHOW_PROMPT_ALWAYS, extraQueryParams, new DefaultAuthenticationCallback(callbackContext)); } diff --git a/src/ios/CordovaAdalPlugin.m b/src/ios/CordovaAdalPlugin.m index 4f3bd4e..2c9fcdc 100644 --- a/src/ios/CordovaAdalPlugin.m +++ b/src/ios/CordovaAdalPlugin.m @@ -63,7 +63,7 @@ - (void)acquireTokenAsync:(CDVInvokedUrlCommand *)command acquireTokenWithResource:resourceId clientId:clientId redirectUri:redirectUri - promptBehavior:AD_PROMPT_ALWAYS + promptBehavior: (extraQueryParameters && [extraQueryParameters containsString: @"prompt="]) ? AD_PROMPT_AUTO : AD_PROMPT_ALWAYS userId:userId extraQueryParameters:extraQueryParameters completionBlock:^(ADAuthenticationResult *result) { diff --git a/src/windows/ADALProxy.js b/src/windows/ADALProxy.js index 5755f0d..4c3b93e 100644 --- a/src/windows/ADALProxy.js +++ b/src/windows/ADALProxy.js @@ -133,6 +133,7 @@ var ADALProxy = { var userId = args[5]; var extraQueryParameters = args[6]; var userIdentifier; + var defaultPromptBehavior = extraQueryParameters != undefined && extraQueryParameters.indexOf('prompt=') > -1 ? Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.auto : Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.always; ADALProxy.getOrCreateCtx(authority, validateAuthority).then(function (context) { userIdentifier = getUserIdentifier(context, userId); @@ -179,13 +180,13 @@ var ADALProxy = { // Try to SSO first context.acquireTokenAsync(resourceUrl, clientId, Windows.Security.Authentication.Web.WebAuthenticationBroker.getCurrentApplicationCallbackUri(), Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.never, userIdentifier, extraQueryParameters).then(function (res) { handleAuthResult(win, function() { - context.acquireTokenAsync(resourceUrl, clientId, Windows.Security.Authentication.Web.WebAuthenticationBroker.getCurrentApplicationCallbackUri(), Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.always, userIdentifier, extraQueryParameters).then(function (res) { + context.acquireTokenAsync(resourceUrl, clientId, Windows.Security.Authentication.Web.WebAuthenticationBroker.getCurrentApplicationCallbackUri(), defaultPromptBehavior, userIdentifier, extraQueryParameters).then(function (res) { handleAuthResult(win, fail, res); }, fail); }, res); }, fail); } else { - context.acquireTokenAsync(resourceUrl, clientId, redirectUrl, Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.always, userIdentifier, extraQueryParameters).then(function (res) { + context.acquireTokenAsync(resourceUrl, clientId, redirectUrl, defaultPromptBehavior, userIdentifier, extraQueryParameters).then(function (res) { handleAuthResult(win, fail, res); }, fail); }