public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { string _token = string.Empty; try { var ssasQuery = await req.Content.ReadAsAsync <SsasQuery>(); if (ssasQuery.AppId is null) { _token = await ADALHelper.GetMsiTokenAsync(Settings.SSAS.Resource); } else { _token = await ADALHelper.GetAppToken(Settings.AzureAd.AuthorityUrl, Settings.SSAS.Resource, ssasQuery.AppId, ssasQuery.AppSecret); } Server cube_server = new Server(); var connectionStringTemplate = ssasQuery.connectionString; //"Provider=MSOLAP;Data Source=asazure://northeurope.asazure.windows.net/meetup;Initial Catalog=MeteoSampleModel;User ID=;Password={0};Persist Security Info=True;Impersonation Level=Impersonate"; var connectionString = string.Format(CultureInfo.InvariantCulture, connectionStringTemplate, _token); cube_server.Connect(connectionString); var results = cube_server.Execute(ssasQuery.query); cube_server.Disconnect(); foreach (XmlaResult result in results) { foreach (XmlaMessage message in result.Messages) { if (message.GetType().Name == "XmlaError") { return(req.CreateResponse(HttpStatusCode.BadRequest, message)); } } } return(req.CreateResponse(HttpStatusCode.OK, results)); } catch (Exception e) { return(req.CreateResponse(HttpStatusCode.BadRequest, e.InnerException)); } }
/// <summary> /// New instance of the O365ManagementActivityClient class. /// </summary> /// <param name="credentials"></param> public O365ManagementActivityClient() { string _token = string.Empty; if (Settings.AzureAd.UseMSI) { try { _token = ADALHelper.GetMsiTokenAsync(Settings.O365AuditLogs.Resource).Result; } catch (Exception e) { _token = ADALHelper.GetAppToken(Settings.AzureAd.AuthorityUrl, Settings.O365AuditLogs.Resource, Settings.O365AuditLogs.AppId, Settings.O365AuditLogs.AppSecret).Result; } } else { _token = ADALHelper.GetAppToken(Settings.AzureAd.AuthorityUrl, Settings.O365AuditLogs.Resource, Settings.O365AuditLogs.AppId, Settings.O365AuditLogs.AppSecret).Result; } Client = new HttpClient(); Client.BaseAddress = new Uri(Settings.O365AuditLogs.BaseAddress); Client.DefaultRequestHeaders.Clear(); Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token); }