Skip to content

Commit 2a028b9

Browse files
committed
Update versions
1 parent 0503fae commit 2a028b9

14 files changed

Lines changed: 18156 additions & 13236 deletions

File tree

.NET Core/Embed for your customers/AppOwnsData/AppOwnsData.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net7.0</TargetFramework>
44
<ApplicationIcon />
55
<OutputType>Exe</OutputType>
66
<StartupObject />
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Identity.Client" Version="4.21.0" />
9+
<PackageReference Include="Microsoft.Identity.Client" Version="4.59.0" />
1010
<PackageReference Include="Microsoft.PowerBI.Api" Version="3.21.0" />
1111
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.76" />
1212
</ItemGroup>

.NET Core/Embed for your customers/AppOwnsData/Controllers/EmbedInfoController.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace AppOwnsData.Controllers
1111
using Microsoft.Extensions.Options;
1212
using System;
1313
using System.Text.Json;
14+
using Microsoft.Rest;
15+
using System.Linq;
16+
using System.Threading.Tasks;
1417

1518
public class EmbedInfoController : Controller
1619
{
@@ -30,7 +33,7 @@ public EmbedInfoController(PbiEmbedService pbiEmbedService, IOptions<AzureAd> az
3033
/// </summary>
3134
/// <returns>JSON containing parameters for embedding</returns>
3235
[HttpGet]
33-
public string GetEmbedInfo()
36+
public async Task<string> GetEmbedInfoAsync()
3437
{
3538
try
3639
{
@@ -42,9 +45,15 @@ public string GetEmbedInfo()
4245
return configValidationResult;
4346
}
4447

45-
EmbedParams embedParams = pbiEmbedService.GetEmbedParams(new Guid(powerBI.Value.WorkspaceId), new Guid(powerBI.Value.ReportId));
48+
EmbedParams embedParams = await pbiEmbedService.GetEmbedParams(new Guid(powerBI.Value.WorkspaceId), new Guid(powerBI.Value.ReportId));
4649
return JsonSerializer.Serialize<EmbedParams>(embedParams);
4750
}
51+
catch (HttpOperationException exc)
52+
{
53+
HttpContext.Response.StatusCode = (int)exc.Response.StatusCode;
54+
var message = string.Format("Status: {0} ({1})\r\nResponse: {2}\r\nRequestId: {3}", exc.Response.StatusCode, (int)exc.Response.StatusCode, exc.Response.Content, exc.Response.Headers["RequestId"].FirstOrDefault());
55+
return message;
56+
}
4857
catch (Exception ex)
4958
{
5059
HttpContext.Response.StatusCode = 500;

.NET Core/Embed for your customers/AppOwnsData/Services/AadService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace AppOwnsData.Services
1111
using System;
1212
using System.Linq;
1313
using System.Security;
14+
using System.Threading.Tasks;
1415

1516
public class AadService
1617
{
@@ -25,18 +26,19 @@ public AadService(IOptions<AzureAd> azureAd)
2526
/// Generates and returns Access token
2627
/// </summary>
2728
/// <returns>AAD token</returns>
28-
public string GetAccessToken()
29+
public async Task<string> GetAccessToken()
2930
{
3031
AuthenticationResult authenticationResult = null;
3132
if (azureAd.Value.AuthenticationMode.Equals("masteruser", StringComparison.InvariantCultureIgnoreCase))
3233
{
3334
// Create a public client to authorize the app with the AAD app
3435
IPublicClientApplication clientApp = PublicClientApplicationBuilder.Create(azureAd.Value.ClientId).WithAuthority(azureAd.Value.AuthorityUrl).Build();
35-
var userAccounts = clientApp.GetAccountsAsync().Result;
36+
var userAccounts = await clientApp.GetAccountsAsync();
37+
3638
try
3739
{
3840
// Retrieve Access token from cache if available
39-
authenticationResult = clientApp.AcquireTokenSilent(azureAd.Value.ScopeBase, userAccounts.FirstOrDefault()).ExecuteAsync().Result;
41+
authenticationResult = await clientApp.AcquireTokenSilent(azureAd.Value.ScopeBase, userAccounts.FirstOrDefault()).ExecuteAsync();
4042
}
4143
catch (MsalUiRequiredException)
4244
{
@@ -45,7 +47,7 @@ public string GetAccessToken()
4547
{
4648
password.AppendChar(key);
4749
}
48-
authenticationResult = clientApp.AcquireTokenByUsernamePassword(azureAd.Value.ScopeBase, azureAd.Value.PbiUsername, password).ExecuteAsync().Result;
50+
authenticationResult = await clientApp.AcquireTokenByUsernamePassword(azureAd.Value.ScopeBase, azureAd.Value.PbiUsername, password).ExecuteAsync();
4951
}
5052
}
5153

@@ -62,7 +64,7 @@ public string GetAccessToken()
6264
.WithAuthority(tenantSpecificUrl)
6365
.Build();
6466
// Make a client call if Access token is not available in cache
65-
authenticationResult = clientApp.AcquireTokenForClient(azureAd.Value.ScopeBase).ExecuteAsync().Result;
67+
authenticationResult = await clientApp.AcquireTokenForClient(azureAd.Value.ScopeBase).ExecuteAsync();
6668
}
6769

6870
return authenticationResult.AccessToken;

.NET Core/Embed for your customers/AppOwnsData/Services/PbiEmbedService.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace AppOwnsData.Services
1313
using System.Collections.Generic;
1414
using System.Linq;
1515
using System.Runtime.InteropServices;
16+
using System.Threading.Tasks;
1617

1718
public class PbiEmbedService
1819
{
@@ -28,19 +29,20 @@ public PbiEmbedService(AadService aadService)
2829
/// Get Power BI client
2930
/// </summary>
3031
/// <returns>Power BI client object</returns>
31-
public PowerBIClient GetPowerBIClient()
32+
public async Task<PowerBIClient> GetPowerBIClient()
3233
{
33-
var tokenCredentials = new TokenCredentials(aadService.GetAccessToken(), "Bearer");
34+
var accessToken = await aadService.GetAccessToken();
35+
var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
3436
return new PowerBIClient(new Uri(powerBiApiUrl ), tokenCredentials);
3537
}
3638

3739
/// <summary>
3840
/// Get embed params for a report
3941
/// </summary>
4042
/// <returns>Wrapper object containing Embed token, Embed URL, Report Id, and Report name for single report</returns>
41-
public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Guid additionalDatasetId)
43+
public async Task<EmbedParams> GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Guid additionalDatasetId)
4244
{
43-
PowerBIClient pbiClient = this.GetPowerBIClient();
45+
PowerBIClient pbiClient = await this.GetPowerBIClient();
4446

4547
// Get report info
4648
var pbiReport = pbiClient.Reports.GetReportInGroup(workspaceId, reportId);
@@ -55,7 +57,7 @@ public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Gu
5557
if (isRDLReport)
5658
{
5759
// Get Embed token for RDL Report
58-
embedToken = GetEmbedTokenForRDLReport(workspaceId, reportId);
60+
embedToken = await GetEmbedTokenForRDLReport(workspaceId, reportId);
5961
}
6062
else
6163
{
@@ -72,7 +74,7 @@ public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Gu
7274
}
7375

7476
// Get Embed token multiple resources
75-
embedToken = GetEmbedToken(reportId, datasetIds, workspaceId);
77+
embedToken = await GetEmbedToken(reportId, datasetIds, workspaceId);
7678
}
7779

7880
// Add report data for embedding
@@ -99,11 +101,11 @@ public EmbedParams GetEmbedParams(Guid workspaceId, Guid reportId, [Optional] Gu
99101
/// </summary>
100102
/// <returns>Wrapper object containing Embed token, Embed URL, Report Id, and Report name for multiple reports</returns>
101103
/// <remarks>This function is not supported for RDL Report</remakrs>
102-
public EmbedParams GetEmbedParams(Guid workspaceId, IList<Guid> reportIds, [Optional] IList<Guid> additionalDatasetIds)
104+
public async Task<EmbedParams> GetEmbedParams(Guid workspaceId, IList<Guid> reportIds, [Optional] IList<Guid> additionalDatasetIds)
103105
{
104106
// Note: This method is an example and is not consumed in this sample app
105107

106-
PowerBIClient pbiClient = this.GetPowerBIClient();
108+
PowerBIClient pbiClient = await this.GetPowerBIClient();
107109

108110
// Create mapping for reports and Embed URLs
109111
var embedReports = new List<EmbedReport>();
@@ -130,7 +132,7 @@ public EmbedParams GetEmbedParams(Guid workspaceId, IList<Guid> reportIds, [Opti
130132
}
131133

132134
// Get Embed token multiple resources
133-
var embedToken = GetEmbedToken(reportIds, datasetIds, workspaceId);
135+
var embedToken = await GetEmbedToken(reportIds, datasetIds, workspaceId);
134136

135137
// Capture embed params
136138
var embedParams = new EmbedParams
@@ -148,9 +150,9 @@ public EmbedParams GetEmbedParams(Guid workspaceId, IList<Guid> reportIds, [Opti
148150
/// </summary>
149151
/// <returns>Embed token</returns>
150152
/// <remarks>This function is not supported for RDL Report</remakrs>
151-
public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
153+
public async Task<EmbedToken> GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
152154
{
153-
PowerBIClient pbiClient = this.GetPowerBIClient();
155+
PowerBIClient pbiClient = await this.GetPowerBIClient();
154156

155157
// Create a request for getting Embed token
156158
// This method works only with new Power BI V2 workspace experience
@@ -174,11 +176,11 @@ public EmbedToken GetEmbedToken(Guid reportId, IList<Guid> datasetIds, [Optional
174176
/// </summary>
175177
/// <returns>Embed token</returns>
176178
/// <remarks>This function is not supported for RDL Report</remakrs>
177-
public EmbedToken GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
179+
public async Task<EmbedToken> GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [Optional] Guid targetWorkspaceId)
178180
{
179181
// Note: This method is an example and is not consumed in this sample app
180182

181-
PowerBIClient pbiClient = this.GetPowerBIClient();
183+
PowerBIClient pbiClient = await this.GetPowerBIClient();
182184

183185
// Convert report Ids to required types
184186
var reports = reportIds.Select(reportId => new GenerateTokenRequestV2Report(reportId)).ToList();
@@ -208,11 +210,11 @@ public EmbedToken GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [
208210
/// </summary>
209211
/// <returns>Embed token</returns>
210212
/// <remarks>This function is not supported for RDL Report</remakrs>
211-
public EmbedToken GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [Optional] IList<Guid> targetWorkspaceIds)
213+
public async Task<EmbedToken> GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [Optional] IList<Guid> targetWorkspaceIds)
212214
{
213215
// Note: This method is an example and is not consumed in this sample app
214216

215-
PowerBIClient pbiClient = this.GetPowerBIClient();
217+
PowerBIClient pbiClient = await this.GetPowerBIClient();
216218

217219
// Convert report Ids to required types
218220
var reports = reportIds.Select(reportId => new GenerateTokenRequestV2Report(reportId)).ToList();
@@ -248,9 +250,9 @@ public EmbedToken GetEmbedToken(IList<Guid> reportIds, IList<Guid> datasetIds, [
248250
/// Get Embed token for RDL Report
249251
/// </summary>
250252
/// <returns>Embed token</returns>
251-
public EmbedToken GetEmbedTokenForRDLReport(Guid targetWorkspaceId, Guid reportId, string accessLevel = "view")
253+
public async Task<EmbedToken> GetEmbedTokenForRDLReport(Guid targetWorkspaceId, Guid reportId, string accessLevel = "view")
252254
{
253-
PowerBIClient pbiClient = this.GetPowerBIClient();
255+
PowerBIClient pbiClient = await this.GetPowerBIClient();
254256

255257
// Generate token request for RDL Report
256258
var generateTokenRequestParameters = new GenerateTokenRequest(

.NET Core/Embed for your organization/UserOwnsData/UserOwnsData.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net7.0</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.1.0" />
6+
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="2.15.3" />
77
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.0.96" />
8-
<PackageReference Include="Microsoft.Identity.Web" Version="1.1.0" />
8+
<PackageReference Include="Microsoft.Identity.Web" Version="2.17.1" />
99
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.1.0" />
1010
<PackageReference Include="Microsoft.PowerBI.Api" Version="3.16.0" />
1111
</ItemGroup>

0 commit comments

Comments
 (0)