From cb9dc6d8a8f66fb36ed6a57ed666fda89883b814 Mon Sep 17 00:00:00 2001 From: damienbod Date: Thu, 7 Dec 2023 08:58:19 +0100 Subject: [PATCH 1/7] .NET 8 --- .../Client/BlazorBffAzureAD.Client.csproj | 10 +++++----- .../Server/BlazorBffAzureAD.Server.csproj | 12 ++++++------ .../Shared/BlazorBffAzureAD.Shared.csproj | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/content/BlazorBffAzureAD/Client/BlazorBffAzureAD.Client.csproj b/content/BlazorBffAzureAD/Client/BlazorBffAzureAD.Client.csproj index d8b1e6e..2f6d209 100644 --- a/content/BlazorBffAzureAD/Client/BlazorBffAzureAD.Client.csproj +++ b/content/BlazorBffAzureAD/Client/BlazorBffAzureAD.Client.csproj @@ -1,17 +1,17 @@  - net7.0 + net8.0 true enable enable - - - - + + + + diff --git a/content/BlazorBffAzureAD/Server/BlazorBffAzureAD.Server.csproj b/content/BlazorBffAzureAD/Server/BlazorBffAzureAD.Server.csproj index aa804d0..c372595 100644 --- a/content/BlazorBffAzureAD/Server/BlazorBffAzureAD.Server.csproj +++ b/content/BlazorBffAzureAD/Server/BlazorBffAzureAD.Server.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable @@ -12,11 +12,11 @@ - - - - - + + + + + diff --git a/content/BlazorBffAzureAD/Shared/BlazorBffAzureAD.Shared.csproj b/content/BlazorBffAzureAD/Shared/BlazorBffAzureAD.Shared.csproj index b7c572e..4fe5d59 100644 --- a/content/BlazorBffAzureAD/Shared/BlazorBffAzureAD.Shared.csproj +++ b/content/BlazorBffAzureAD/Shared/BlazorBffAzureAD.Shared.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable From 6dc8dfb6ed67254d7bb1d3aca370bd7a5b5241af Mon Sep 17 00:00:00 2001 From: damienbod Date: Thu, 7 Dec 2023 09:01:49 +0100 Subject: [PATCH 2/7] fix Graph photo streaming --- .../BlazorBffAzureAD/Server/Services/MsGraphService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs b/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs index 65a5fe6..d6372b4 100644 --- a/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs +++ b/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs @@ -25,6 +25,9 @@ public async Task GetGraphApiProfilePhoto() try { var photo = string.Empty; + byte[] photoByte; + var streamPhoto = new MemoryStream(); + // Get user photo using (var photoStream = await _graphServiceClient .Me @@ -32,10 +35,12 @@ public async Task GetGraphApiProfilePhoto() .Content .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read"))) { - byte[] photoByte = ((MemoryStream)photoStream!).ToArray(); - photo = Base64UrlEncoder.Encode(photoByte); + photoStream!.CopyTo(streamPhoto); + photoByte = streamPhoto!.ToArray(); } + photo = Base64UrlEncoder.Encode(photoByte); + return photo; } catch From 793a802701612923949227ee93e746d73b8ada08 Mon Sep 17 00:00:00 2001 From: damienbod Date: Thu, 7 Dec 2023 09:12:29 +0100 Subject: [PATCH 3/7] update namespaces --- .../Server/Services/MsGraphService.cs | 73 +++++++++---------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs b/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs index d6372b4..cd2d28c 100644 --- a/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs +++ b/content/BlazorBffAzureAD/Server/Services/MsGraphService.cs @@ -3,50 +3,49 @@ using Microsoft.Identity.Web; using Microsoft.IdentityModel.Tokens; -namespace BlazorBffAzureAD.Server.Services +namespace BlazorBffAzureAD.Server.Services; + +public class MsGraphService { - public class MsGraphService - { - private readonly GraphServiceClient _graphServiceClient; + private readonly GraphServiceClient _graphServiceClient; - public MsGraphService(GraphServiceClient graphServiceClient) - { - _graphServiceClient = graphServiceClient; - } + public MsGraphService(GraphServiceClient graphServiceClient) + { + _graphServiceClient = graphServiceClient; + } - public async Task GetGraphApiUser() - { - return await _graphServiceClient.Me - .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read")); - } + public async Task GetGraphApiUser() + { + return await _graphServiceClient.Me + .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read")); + } - public async Task GetGraphApiProfilePhoto() + public async Task GetGraphApiProfilePhoto() + { + try { - try - { - var photo = string.Empty; - byte[] photoByte; - var streamPhoto = new MemoryStream(); - - // Get user photo - using (var photoStream = await _graphServiceClient - .Me - .Photo - .Content - .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read"))) - { - photoStream!.CopyTo(streamPhoto); - photoByte = streamPhoto!.ToArray(); - } - - photo = Base64UrlEncoder.Encode(photoByte); - - return photo; - } - catch + var photo = string.Empty; + byte[] photoByte; + var streamPhoto = new MemoryStream(); + + // Get user photo + using (var photoStream = await _graphServiceClient + .Me + .Photo + .Content + .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read"))) { - return string.Empty; + photoStream!.CopyTo(streamPhoto); + photoByte = streamPhoto!.ToArray(); } + + photo = Base64UrlEncoder.Encode(photoByte); + + return photo; + } + catch + { + return string.Empty; } } } From 1338e7a60b62a24c5f1b5f44a006ea22f13803ab Mon Sep 17 00:00:00 2001 From: damienbod Date: Thu, 7 Dec 2023 09:13:20 +0100 Subject: [PATCH 4/7] Microsoft Entra ID --- content/BlazorBffAzureAD/Client/Pages/Index.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/BlazorBffAzureAD/Client/Pages/Index.razor b/content/BlazorBffAzureAD/Client/Pages/Index.razor index 77b37b0..bbb3a09 100644 --- a/content/BlazorBffAzureAD/Client/Pages/Index.razor +++ b/content/BlazorBffAzureAD/Client/Pages/Index.razor @@ -1,3 +1,3 @@ @page "/" -

Azure AD using cookies

+

Microsoft Entra ID using cookies

From c8eae4a356984ea5947e27389c40c62a62137a17 Mon Sep 17 00:00:00 2001 From: damienbod Date: Thu, 7 Dec 2023 09:15:15 +0100 Subject: [PATCH 5/7] Microsoft Entra ID --- content/BlazorBffAzureAD/Client/Shared/NavMenu.razor | 2 +- content/BlazorBffAzureAD/Server/Pages/_Host.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/content/BlazorBffAzureAD/Client/Shared/NavMenu.razor b/content/BlazorBffAzureAD/Client/Shared/NavMenu.razor index 806c120..5392274 100644 --- a/content/BlazorBffAzureAD/Client/Shared/NavMenu.razor +++ b/content/BlazorBffAzureAD/Client/Shared/NavMenu.razor @@ -1,5 +1,5 @@