Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force photo type in Authenticator app #6

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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