public static string GetASConnectionString(ActionRequest request, JToken azureToken, string serverUrl) { string connectionString = $"Provider=MSOLAP;Data Source={serverUrl}"; Uri uri = new Uri(serverUrl); string resource = "https://" + uri.Host; var asToken = AzureTokenUtility.GetTokenForResource(request, azureToken, resource); string asAccessToken = AzureUtility.GetAccessToken(asToken); if (!string.IsNullOrEmpty(asAccessToken)) { connectionString += $";Password={asAccessToken};UseADALCache=0"; } try { Server server = new Server(); server.Connect(connectionString); request.DataStore.AddToDataStore("ASConnectionString", connectionString, DataStoreType.Private); return(connectionString); } catch (Exception ex) { throw ex; } }
public static string GetASConnectionString(ActionRequest request, JToken azureToken, string serverUrl) { if (string.IsNullOrEmpty(serverUrl)) { throw new ArgumentNullException(nameof(serverUrl)); } if (!Uri.IsWellFormedUriString(serverUrl, UriKind.Absolute)) { throw new ArgumentException("Invalid URL specified for Analysis Services", nameof(serverUrl)); } string connectionString = $"Provider=MSOLAP;Data Source={serverUrl}"; Uri uri = new Uri(serverUrl); string resource = $"{Uri.UriSchemeHttps}://{uri.Host}"; var asToken = AzureTokenUtility.GetTokenForResourceFromExistingToken("as", request.Info.WebsiteRootUrl, azureToken, resource); string asAccessToken = AzureUtility.GetAccessToken(asToken); if (!string.IsNullOrEmpty(asAccessToken)) { connectionString += $";Password={asAccessToken};UseADALCache=0"; } Server server = null; try { server = new Server(); server.Connect(connectionString); server.Disconnect(true); request.DataStore.AddToDataStore("ASConnectionString", connectionString, DataStoreType.Private); return(connectionString); } catch { throw; } finally { if (server != null) { // In theory, we could end up here with a connected server object if (server.Connected) { try { server.Disconnect(true); } catch { } } server.Dispose(); } } }
public static async Task <DataStore> GetUserTokenFromPopup(string openAuthorizationType = "") { #if DEBUG AuthenticationContext context = new AuthenticationContext("https://login.windows.net/" + "common"); AzureTokenRequestMeta meta = AzureTokenUtility.GetMetaFromOAuthType(openAuthorizationType); var url = context.GetAuthorizationRequestUrlAsync(meta.Resource, meta.ClientId, new Uri("https://unittest/redirect.html"), UserIdentifier.AnyUser, "prompt=consent").Result; WindowsFormsWebAuthenticationDialog form = new WindowsFormsWebAuthenticationDialog(null); form.WebBrowser.Navigated += delegate(object sender, WebBrowserNavigatedEventArgs args) { if (args.Url.ToString().StartsWith("https://unittest/redirect.html")) { string tempcode = args.Url.ToString(); tempcode = tempcode.Substring(tempcode.IndexOf("code=") + 5); code = tempcode.Substring(0, tempcode.IndexOf("&")); form.Close(); } ; }; form.WebBrowser.Navigate(url); form.ShowBrowser(); while (string.IsNullOrEmpty(code)) { await Task.Delay(5000); } #endif DataStore datastore = new DataStore(); datastore.AddToDataStore("code", code, DataStoreType.Private); datastore.AddToDataStore("AADTenant", "common", DataStoreType.Private); datastore.AddToDataStore("AADRedirect", "https://unittest/redirect.html"); datastore.AddToDataStore("oauthType", openAuthorizationType); var result = await TestManager.ExecuteActionAsync("Microsoft-GetAzureToken", datastore); return(result.DataStore); }