Merge pull request #688 from wabbajack-tools/new-nexus-login

Rework the nexus login to no longer use the buggy SSO server.
This commit is contained in:
Timothy Baldridge 2020-04-06 22:29:27 -06:00 committed by GitHub
commit fa1ad768b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 23 deletions

View File

@ -2,6 +2,10 @@
#### Version - Next
* Included LOOT configs are no longer Base64 encoded
* Reworked Wabbajack-cli
* Can use a MEGA login (if you have it, not required)
* Don't use the buggy Nexus SSO server, instead use the in-browser API key generator
* Several fixes for zEdit merge integration, handles several side-cases of improper configuration
#### Version - 3/30/2020
* Added support for Morrowind on GOG

View File

@ -100,33 +100,52 @@ namespace Wabbajack.Lib.NexusApi
await Task.Delay(500, cancel);
}
// open a web socket to receive the api key
var guid = Guid.NewGuid();
using (var websocket = new WebSocket("wss://sso.nexusmods.com")
{
SslConfiguration =
{
EnabledSslProtocols = SslProtocols.Tls12
}
})
{
updateStatus("Please authorize Wabbajack to download Nexus mods");
var api_key = new TaskCompletionSource<string>();
websocket.OnMessage += (sender, msg) => { api_key.SetResult(msg.Data); };
websocket.Connect();
websocket.Send("{\"id\": \"" + guid + "\", \"appid\": \"" + Consts.AppName + "\"}");
await Task.Delay(1000, cancel);
await browser.NavigateTo(new Uri("https://www.nexusmods.com/users/myaccount?tab=api"));
// open a web browser to get user permission
await browser.NavigateTo(new Uri($"https://www.nexusmods.com/sso?id={guid}&application={Consts.AppName}"));
using (cancel.Register(() =>
updateStatus("Looking for API Key");
var apiKey = new TaskCompletionSource<string>();
while (true)
{
api_key.SetCanceled();
}))
var key = "";
try
{
return await api_key.Task;
key = await browser.EvaluateJavaScript(
"document.querySelector(\"input[value=wabbajack]\").parentElement.parentElement.querySelector(\"textarea.application-key\").innerHTML");
}
catch (Exception ex)
{
// ignored
}
if (!string.IsNullOrEmpty(key))
{
return key;
}
try
{
await browser.EvaluateJavaScript(
"var found = document.querySelector(\"input[value=wabbajack]\").parentElement.parentElement.querySelector(\"form button[type=submit]\");" +
"found.onclick= function() {return true;};" +
"found.class = \" \"; " +
"found.click();" +
"found.remove(); found = undefined;"
);
updateStatus("Generating API Key, Please Wait...");
}
catch (Exception)
{
// ignored
}
cancel.ThrowIfCancellationRequested();
await Task.Delay(500);
}
}