diff --git a/SSO-Auth/WebResponse.cs b/SSO-Auth/WebResponse.cs index 6dcf8db..ac93907 100644 --- a/SSO-Auth/WebResponse.cs +++ b/SSO-Auth/WebResponse.cs @@ -1,3 +1,5 @@ +using System.Globalization; + namespace Jellyfin.Plugin.SSO_Auth; /// @@ -413,6 +415,14 @@ const sleep = (milliseconds) => { /// A string with the HTML to serve to the client. public static string Generator(string data, string provider, string baseUrl, string mode, bool isLinking = false) { + // Strip out the protocol (http:// or https://) and convert the domain to Punycode + var idnMapping = new IdnMapping(); + var protocolSeparatorIndex = baseUrl.IndexOf("//"); + var protocol = baseUrl.Substring(0, protocolSeparatorIndex + 2); + var domain = baseUrl.Substring(protocolSeparatorIndex + 2); + var punycodeDomain = idnMapping.GetAscii(domain); + var punycodeBaseUrl = protocol + punycodeDomain; + return Base + @" async function link(request) { const jfCredentialsString = localStorage.getItem(""jellyfin_credentials""); @@ -426,7 +436,7 @@ async function link(request) { if (jfUser == null) return; if (jfToken == null) return; - const url = '" + $"{baseUrl}/sso/{mode}/Link/{provider}/" + @"' + jfUser; + const url = '" + $"{punycodeBaseUrl}/sso/{mode}/Link/{provider}/" + @"' + jfUser; return new Promise(resolve => { var xhr = new XMLHttpRequest(); @@ -451,7 +461,7 @@ async function link(request) { async function main() { localStorage.removeItem('jellyfin_credentials'); - document.getElementById('iframe-main').src = '" + baseUrl + @"/web/index.html'; + document.getElementById('iframe-main').src = '" + punycodeBaseUrl + @"/web/index.html'; var data = '" + data + @"'; while (localStorage.getItem(""_deviceId2"") == null || @@ -469,7 +479,7 @@ async function main() { if (" + $"{isLinking}".ToLower() + @") await link(request); - var url = '" + baseUrl + "/sso/" + mode + "/Auth/" + provider + @"'; + var url = '" + punycodeBaseUrl + "/sso/" + mode + "/Auth/" + provider + @"'; let response = await new Promise(resolve => { var xhr = new XMLHttpRequest(); @@ -493,7 +503,7 @@ async function main() { jfCreds['Servers'][0]['UserId'] = responseJson['User']['Id']; localStorage.setItem('jellyfin_credentials', JSON.stringify(jfCreds)); localStorage.setItem('enableAutoLogin', 'true'); - window.location.replace('" + baseUrl + @"/web/index.html'); + window.location.replace('" + punycodeBaseUrl + @"/web/index.html'); } document.addEventListener('DOMContentLoaded', function () {