mirror of
https://github.com/9p4/jellyfin-plugin-sso.git
synced 2026-09-19 13:12:19 +00:00
Fix #7
This commit is contained in:
+42
-37
@@ -393,6 +393,10 @@ function getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
const sleep = (milliseconds) => {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
||||
}
|
||||
|
||||
";
|
||||
|
||||
public static string Generator(string data, string provider, string baseUrl, string mode)
|
||||
@@ -400,44 +404,45 @@ function getDeviceName() {
|
||||
return Base + @"
|
||||
async function main() {
|
||||
var data = '" + data + @"';
|
||||
if (localStorage.getItem(""_deviceId2"") == null || localStorage.getItem(""jellyfin_credentials"") == null) {
|
||||
while (localStorage.getItem(""_deviceId2"") == null ||
|
||||
localStorage.getItem(""jellyfin_credentials"") == null ||
|
||||
JSON.parse(localStorage.getItem(""jellyfin_credentials""))['Servers'][0]['Id'] == null) {
|
||||
// If localStorage isn't initialized yet, try again.
|
||||
setTimeout(main, 100);
|
||||
} else {
|
||||
var deviceId = localStorage.getItem(""_deviceId2"");
|
||||
var appName = ""Jellyfin Web"";
|
||||
var appVersion = ""10.8.0"";
|
||||
var deviceName = getDeviceName();
|
||||
var provider = '" + provider + @"';
|
||||
|
||||
var request = {deviceId, appName, appVersion, deviceName, data, provider: '" + provider + @"'};
|
||||
|
||||
var url = '" + baseUrl + "/sso/" + mode + @"/Auth';
|
||||
|
||||
let response = await new Promise(resolve => {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.onload = function(e) {
|
||||
resolve(xhr.response);
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
resolve(undefined);
|
||||
};
|
||||
xhr.send(JSON.stringify(request));
|
||||
})
|
||||
var responseJson = JSON.parse(response);
|
||||
var userId = 'user-' + responseJson['User']['Id'] + '-' + responseJson['User']['ServerId'];
|
||||
responseJson['User']['EnableAutoLogin'] = true;
|
||||
localStorage.setItem(userId, JSON.stringify(responseJson['User']));
|
||||
var jfCreds = JSON.parse(localStorage.getItem('jellyfin_credentials'));
|
||||
jfCreds['Servers'][0]['AccessToken'] = responseJson['AccessToken'];
|
||||
jfCreds['Servers'][0]['UserId'] = responseJson['User']['Id'];
|
||||
localStorage.setItem('jellyfin_credentials', JSON.stringify(jfCreds));
|
||||
localStorage.setItem('enableAutoLogin', 'true');
|
||||
window.location.replace('" + baseUrl + @"');
|
||||
await sleep(100);
|
||||
}
|
||||
var deviceId = localStorage.getItem(""_deviceId2"");
|
||||
var appName = ""Jellyfin Web"";
|
||||
var appVersion = ""10.8.0"";
|
||||
var deviceName = getDeviceName();
|
||||
var provider = '" + provider + @"';
|
||||
|
||||
var request = {deviceId, appName, appVersion, deviceName, data, provider: '" + provider + @"'};
|
||||
|
||||
var url = '" + baseUrl + "/sso/" + mode + @"/Auth';
|
||||
|
||||
let response = await new Promise(resolve => {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.onload = function(e) {
|
||||
resolve(xhr.response);
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
resolve(undefined);
|
||||
};
|
||||
xhr.send(JSON.stringify(request));
|
||||
})
|
||||
var responseJson = JSON.parse(response);
|
||||
var userId = 'user-' + responseJson['User']['Id'] + '-' + responseJson['User']['ServerId'];
|
||||
responseJson['User']['EnableAutoLogin'] = true;
|
||||
localStorage.setItem(userId, JSON.stringify(responseJson['User']));
|
||||
var jfCreds = JSON.parse(localStorage.getItem('jellyfin_credentials'));
|
||||
jfCreds['Servers'][0]['AccessToken'] = responseJson['AccessToken'];
|
||||
jfCreds['Servers'][0]['UserId'] = responseJson['User']['Id'];
|
||||
localStorage.setItem('jellyfin_credentials', JSON.stringify(jfCreds));
|
||||
localStorage.setItem('enableAutoLogin', 'true');
|
||||
window.location.replace('" + baseUrl + @"');
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
@@ -445,6 +450,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
|
||||
// https://stackoverflow.com/a/25435165
|
||||
</script><iframe class='docs-texteventtarget-iframe' src='" + baseUrl + "' style='position: absolute;width:0;height:0;border:0;'></iframe></body></html>";
|
||||
</script><iframe class='docs-texteventtarget-iframe' sandbox='allow-same-origin allow-forms allow-scripts' src='" + baseUrl + "' style='position: absolute;width:0;height:0;border:0;'></iframe></body></html>";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user