Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
New auth update patched
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholastay committed Apr 21, 2017
1 parent d37d74a commit b6249b8
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Xenon/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<setting name="username" serializeAs="String">
<value />
</setting>
<setting name="nexonDeviceId" serializeAs="String">
<value />
</setting>
</Xenon.Properties.Settings>
</userSettings>
</configuration>
21 changes: 11 additions & 10 deletions Xenon/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,20 @@ private async void Button_Click(object sender, RoutedEventArgs e)
#endif
}

private string encodeB64(string str) => Convert.ToBase64String(Encoding.UTF8.GetBytes(str));

private async Task performLogin(string username, string password)
{
var req = new HttpRequestMessage()
{
RequestUri = new Uri("https://api.nexon.net/auth/login"),
RequestUri = new Uri("https://accounts.nexon.net/account/login/launcher"),
Method = HttpMethod.Post,
Content = new StringContent($"{{\"allow_unverified\":true,\"user_id\":\"{username}\",\"user_pw\":\"{password}\"}}", Encoding.UTF8, "application/json")
Content = new StringContent($"{{\"id\":\"{username}\",\"password\":\"{Nexon.Auth.HashHexPassword(password)}\",\"auto_login\":false,\"client_id\":\"{Nexon.Auth.CLIENT_ID}\",\"scope\":\"{Nexon.Auth.SCOPE}\",\"device_id\":\"{Nexon.Auth.DeviceId}\"}}", Encoding.UTF8, "application/json")
};
req.Headers.Add("User-Agent", "NexonLauncher node-webkit/0.14.6 (Windows NT 10.0; WOW64) WebKit/537.36 (@c26c0312e940221c424c2730ef72be2c69ac1b67) nexon_client");
req.Headers.Add("Authorization", "Basic " + encodeB64($"{username.Replace("@", "%40")}:{password}")); // nexon launcher does this, it uriencodes to %40 which is weird but meh

HttpResponseMessage res = await httpClient.SendAsync(req);
dynamic json = await parseResponseJson(res);

nexonToken = json["token"];
nexonToken = json["access_token"];
cookieContainer.Add(new Cookie("nxtk", nexonToken, "/", ".nexon.net")); // this cookie is used in all future requests
}

Expand All @@ -162,7 +159,7 @@ private async Task isMapleUpToDate()
{
var req = new HttpRequestMessage()
{
RequestUri = new Uri("https://api.nexon.net/products/10100"),
RequestUri = new Uri("https://api.nexon.io/products/10100"),
Method = HttpMethod.Get
};
addNexonLauncherData(req); // bearer auth + UA
Expand Down Expand Up @@ -199,7 +196,7 @@ private async Task getLaunchData()
// getting passport cookie to be able to get the launch token
var req = new HttpRequestMessage()
{
RequestUri = new Uri("https://api.nexon.net/users/me/passport"),
RequestUri = new Uri("https://api.nexon.io/users/me/passport"),
Method = HttpMethod.Get
};
addNexonLauncherData(req);
Expand Down Expand Up @@ -261,6 +258,10 @@ private async Task<dynamic> parseResponseJson(HttpResponseMessage res)
{
// include err checking here
dynamic json = JObject.Parse(await res.Content.ReadAsStringAsync());

if (!res.IsSuccessStatusCode)
throw new Exception($"Nexon {res.StatusCode} error: \n\n{json["message"]} [{json["code"]}]");

if (json["error"] != null)
throw new Exception($"Nexon error: \n\n{json["error"]["message"]} [{json["error"]["code"]}]");

Expand All @@ -269,8 +270,8 @@ private async Task<dynamic> parseResponseJson(HttpResponseMessage res)

private void addNexonLauncherData(HttpRequestMessage req)
{
req.Headers.Add("User-Agent", "NexonLauncher.nxl-17.02.03-219-5e3143f");
req.Headers.Add("Authorization", "bearer " + encodeB64(nexonToken)); // this + cookie is used for auth here.
req.Headers.Add("User-Agent", "NexonLauncher.nxl-17.03.02-275-220ecfb");
req.Headers.Add("Authorization", "bearer " + Util.EncodeB64(nexonToken)); // this + cookie is used for auth here.
}

private void returnNoError()
Expand Down
48 changes: 48 additions & 0 deletions Xenon/Nexon/Auth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;

namespace Xenon.Nexon
{
public static class Auth
{
public const string CLIENT_ID = "7853644408";
public const string SCOPE = "us.launcher.all";

public static string DeviceId = ""; // lets just make a random 64 string that we use everytime...

static Auth()
{
DeviceId = Properties.Settings.Default.nexonDeviceId;

if (String.IsNullOrEmpty(DeviceId))
{
DeviceId = "";

var random = new Random();
for (int i = 0; i < 64; i++)
DeviceId += random.Next(16).ToString("X");

Properties.Settings.Default.nexonDeviceId = DeviceId;
Properties.Settings.Default.Save();
}
}

public static string HashHexPassword(string password)
{
// hashes the password as sha-512 and hex as required by nexon
// https://msdn.microsoft.com/en-us/library/s02tk69a(v=vs.110).aspx
SHA512 shaM = new SHA512Managed();
byte[] shaData = shaM.ComputeHash(Encoding.UTF8.GetBytes(password));

var sb = new StringBuilder();
for (int i = 0; i < shaData.Length; i++)
sb.Append(shaData[i].ToString("x2")); // hex formatted

return sb.ToString();
}
}
}
14 changes: 13 additions & 1 deletion Xenon/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Xenon/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<Setting Name="username" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="nexonDeviceId" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
17 changes: 17 additions & 0 deletions Xenon/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xenon
{
static class Util
{
public static string EncodeB64(string plainText)
=> System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(plainText));

public static string DecodeB64(string base64EncodedData)
=> System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(base64EncodedData));
}
}
3 changes: 3 additions & 0 deletions Xenon/Xenon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Nexon\Auth.cs" />
<Compile Include="Util.cs" />
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -114,6 +116,7 @@
<ItemGroup>
<Resource Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.1.29.4\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets') And '$(Configuration)' != 'Debug'" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down

0 comments on commit b6249b8

Please sign in to comment.