Skip to content

Commit

Permalink
Merge pull request #6 from swiss-ssi-group/fix-photo-type
Browse files Browse the repository at this point in the history
Force photo type in Authenticator app
  • Loading branch information
damienbod committed Jul 28, 2023
2 parents 6f82f6f + 9d1d896 commit 80201ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions IssueVerifiableEmployee/IssueVerifiableEmployee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.9" NoWarn="NU1605" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.13.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IssuerVerifiableEmployee.Persistence;
using ImageMagick;
using IssuerVerifiableEmployee.Persistence;
using Microsoft.Graph;
using Microsoft.Graph.Models;
using Microsoft.IdentityModel.Tokens;
Expand Down Expand Up @@ -118,13 +119,29 @@ public MicrosoftGraphDelegatedClient(GraphServiceClient graphServiceClient)
public async Task<string> GetGraphApiProfilePhoto(string oid)
{
var photo = string.Empty;
byte[] photoByte;

using (var photoStream = await _graphServiceClient.Users[oid].Photo
.Content.GetAsync())
{
byte[] photoByte = ((MemoryStream)photoStream!).ToArray();
photo = Base64UrlEncoder.Encode(photoByte);
photoByte = ((MemoryStream)photoStream!).ToArray();
}

using var imageFromFile = new MagickImage(photoByte);
// Sets the output format to jpeg
imageFromFile.Format = MagickFormat.Jpeg;
var size = new MagickGeometry(400, 400);

// This will resize the image to a fixed size without maintaining the aspect ratio.
// Normally an image will be resized to fit inside the specified size.
//size.IgnoreAspectRatio = true;

imageFromFile.Resize(size);

// Create byte array that contains a jpeg file
var data = imageFromFile.ToByteArray();
photo = Base64UrlEncoder.Encode(data);

return photo;
}

Expand Down

0 comments on commit 80201ba

Please sign in to comment.