-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Conversation
This would be a breaking change for anyone that already has it working, so a new option must be added. |
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... |
This should be ready to review/test now! |
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); | ||
} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
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.