diff --git a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml
index 4a3e5419..ed55381f 100644
--- a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml
+++ b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml
@@ -1123,6 +1123,7 @@
+
@@ -1135,26 +1136,40 @@
LostFocus="SharePointSiteUrlTextBox_LostFocus"
TextAlignment="Left" />
+
+
+
+
+
+
+
+
+
+
+ TextAlignment="Left" Width="50"/>
-
+
-
+
-
+
@@ -1220,15 +1235,9 @@
-
-
-
-
-
-
-
+
diff --git a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs
index 900f5d34..538f8070 100644
--- a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs
+++ b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs
@@ -61,6 +61,7 @@ private enum PropertyType
private bool _enableExperimentalFeatures;
private bool _firstInit = true;
private static string _adalToken = null;
+ private static InteractiveAuthenticationProvider _interactiveProvider;
public SearchPresetList SearchPresets { get; set; }
private string PresetFolderPath { get; set; }
@@ -506,29 +507,36 @@ async Task AdalLogin(bool forcePrompt)
const string clientId = "9bc3ab49-b65d-410a-85ad-de819febfddc";
const string redirectUri = "https://oauth.spops.microsoft.com/";
- if (forcePrompt || IsExpired(_adalToken, spUri.Host))
- {
- string tenant = spUri.Host.Replace("sharepoint", "onmicrosoft")
+ string tenant = spUri.Host.Replace("sharepoint", "onmicrosoft")
.Replace("-df", "")
.Replace("-admin", "");
- InteractiveAuthenticationProvider interactiveProvider = new InteractiveAuthenticationProvider(clientId, tenant, new Uri(redirectUri));
- _adalToken = await interactiveProvider.GetAccessTokenAsync(resourceUri);
+ if(!string.IsNullOrWhiteSpace(TenantIdTextBox.Text))
+ {
+ tenant = TenantIdTextBox.Text.Trim();
}
- _searchQueryRequest.Token = _searchSuggestionsRequest.Token = "Bearer " + _adalToken;
- }
- static bool IsExpired(string token, string host)
- {
- if (string.IsNullOrWhiteSpace(token))
+ if (_interactiveProvider == null || _interactiveProvider.TenantId != tenant)
{
- return true;
+ _interactiveProvider = new InteractiveAuthenticationProvider(clientId, tenant, new Uri(redirectUri));
}
- var jwtToken = new JwtSecurityToken(token);
- if (jwtToken.Audiences.First().Contains(host) == false) return true;
- return jwtToken.ValidTo < DateTime.UtcNow;
+
+ _adalToken = await _interactiveProvider.GetAccessTokenAsync(resourceUri);
+
+ _searchQueryRequest.Token = _searchSuggestionsRequest.Token = "Bearer " + _adalToken;
}
+ //static bool IsExpired(string token, string host)
+ //{
+ // if (string.IsNullOrWhiteSpace(token))
+ // {
+ // return true;
+ // }
+ // var jwtToken = new JwtSecurityToken(token);
+ // if (jwtToken.Audiences.First().Contains(host) == false) return true;
+ // return jwtToken.ValidTo < DateTime.UtcNow;
+ //}
+
#endregion
#region Event Handlers for Controls on the Search Query Tab