Use a consistent http and oidc clients Use the access token to send an a authenticated request to retrieve avatar and do it at the same time as requesting the userinfo endpoint Merge JTokens instead of re-parsing json strings to merge configuration
38 lines
1.9 KiB
C#
38 lines
1.9 KiB
C#
namespace Jellyfin.Plugin.OIDC_Auth;
|
|
|
|
using Json = Newtonsoft.Json;
|
|
|
|
/// <summary>
|
|
/// A helper class to return HTML for the client's auth flow.
|
|
/// </summary>
|
|
public static class WebResponse {
|
|
/// <summary>
|
|
/// A generator for the web response that incorporates the data from the server.
|
|
/// </summary>
|
|
/// <param name="data">The data of the auth flow. Is a state ID for OpenID.</param>
|
|
/// <param name="provider">The name of the provider to callback to.</param>
|
|
/// <param name="baseUrl">The base URL of the Jellyfin installation.</param>
|
|
/// <param name="isLinking">Whether or not this request is to link accounts (Rather than authenticate).</param>
|
|
/// <returns>A string with the HTML to serve to the client.</returns>
|
|
public static string Generator(string data, string provider, System.Uri baseUrl, bool isLinking = false) {
|
|
System.Globalization.IdnMapping idnMapping = new();
|
|
System.UriBuilder punyURL = new(baseUrl);
|
|
punyURL.Fragment = string.Empty;
|
|
punyURL.Host = idnMapping.GetAscii(baseUrl.Host);
|
|
if (punyURL.Port == 443) {
|
|
punyURL.Port = -1;
|
|
}
|
|
System.Collections.Generic.Dictionary<string, object> jsonData = new() {
|
|
["punyURL"] = punyURL.ToString(),
|
|
["provider"] = provider,
|
|
["isLinking"] = isLinking,
|
|
["data"] = data,
|
|
};
|
|
var jsonText = Json.JsonConvert.SerializeObject(jsonData);
|
|
// TODO: script tag parsing is entirely inane, but should only have an issue if the string `</` exists in this output , find a proper escap for an end tag because standard html escapes don't work here.
|
|
return OIDCPlugin.Instance.GetHTMLPage(OIDCPlugin.Instance.GetPage("auth.html"), punyURL.ToString())
|
|
.Replace("{\"insert\":\"here\"}", jsonText)
|
|
.Replace("src=\"index.html\"", "src=\"" + punyURL.ToString() + "/web/index.html\"");
|
|
}
|
|
}
|