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

Base64 decode image attribute #166

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Kinsteen
Copy link

Piggy backing on #154.

Users are complaining (#163) because the LDAP attribute expect the binary data of the JPG picture, but for some LDAP servers (Authentik for example) we can't store binary data as it breaks serialization. Instead, this plugin will decode from Base64 to get the binary data. The best way could be to have like a drop-down to select "Binary", "Base64" and even "URL" (but I'm not versed enough in C# for this one), but I've tested this way and it works.

@crobibero
Copy link
Member

This would be a breaking change for anyone that already has it working, so a new option must be added.

@Kinsteen
Copy link
Author

Done. I'm really not sure how should I do URL format. It seems like the best idea because I'm assuming that's how people set up their LDAP servers, but I'm not proficient enough in the Jellyfin/C# code base...

@Kinsteen
Copy link
Author

This should be ready to review/test now!

Comment on lines +103 to +120
byte[] ldapProfileImage = null;
if (ProfileImageAttrFormat == "base64")
{
ldapProfileImage = Convert.FromBase64String(ldapAuthProvider.GetAttribute(ldapUser, ProfileImageAttr)?.StringValue);
}
else if (ProfileImageAttrFormat == "binary")
{
ldapProfileImage = ldapAuthProvider.GetAttribute(ldapUser, ProfileImageAttr)?.ByteValue;
}
else if (ProfileImageAttrFormat == "url")
{
using var client = new HttpClient();
ldapProfileImage = await client.GetByteArrayAsync(ldapAuthProvider.GetAttribute(ldapUser, ProfileImageAttr)?.StringValue);
}
else
{
_logger.LogError("Unknown profile image format: {Format}", ProfileImageAttrFormat);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be cleaner if this could be done via a match pattern. If the match returns a Task<byte[]> it should be simple to return Task.FromResult in the first two cases and just use a async method that retrieves the picture from the net in the third.

Additionally I highly recommend against using a stringly typed Format and instead use an Enum.

}
else if (ProfileImageAttrFormat == "url")
{
using var client = new HttpClient();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the IHttpClientFactory to get the HttpClient.

}
else if (ProfileImageAttrFormat == "url")
{
using var client = new HttpClient();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the IHttpClientFactory to get the HttpClient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants