Exemple #1
0
        public async Task <bool> GetAccessToken(string username, string password, string profileGuid)
        {
            if (_accessToken != null && !_accessTokenIsExpired && _lastAuthenticationProfileGuid == profileGuid)
            {
                return(true);
            }

            _restClient = new RestClient(new Uri("https://accounts.nexon.net"), null);

            var request = _restClient.Create("/account/login/launcher");

            var initialRequestBody = new AccountLoginJson
            {
                Id        = username,
                Password  = password,
                AutoLogin = false,
                ClientId  = BodyClientId,
                Scope     = BodyScope,
                DeviceId  = GetDeviceUuid()
            };

            request.SetBody(initialRequestBody);

            RestResponse response = await request.ExecutePost <string>();

            // dispose of password yo
            password           = null;
            initialRequestBody = new AccountLoginJson();
            // Compiler tricks to ensure it isn't optimized away
            var ps = password;

            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                return(false);
            }

            var data = await response.GetContent();

            var body = JsonConvert.DeserializeObject <dynamic>(data);

            _accessToken           = body["access_token"];
            _accessTokenExpiration = body["access_token_expires_in"];

            _lastAuthenticationProfileGuid = profileGuid;

            _accessTokenIsExpired = false;
            StartAccessTokenExpiryTimer(_accessTokenExpiration);

            return(true);
        }
Exemple #2
0
 public void getAPIToken()
 {
     if (apiToken == null || DateTimeOffset.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds >= accessTokenExpires)
     {
         var apiClient = new RestClient("https://www.nexon.com");
         apiClient.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) NexonLauncher/2.1.0 Chrome/66.0.3359.181 Electron/3.0.4 Safari/537.36";
         var request = new RestRequest("account-webapi/login/launcher", Method.POST);
         ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
         var requestBody = new AccountLoginJson
         {
             id         = username,
             password   = password,
             auto_login = false,
             client_id  = clientID,
             scope      = "us.launcher.all",
             device_id  = NxUtil.getUUID(),
         };
         request.AddJsonBody(requestBody);
         IRestResponse response = apiClient.Execute(request);
         var           body     = JsonConvert.DeserializeObject <dynamic>(response.Content);
         if (body["code"] != null && ((String)body["code"]).Equals("TRUST_DEVICE_REQUIRED", StringComparison.InvariantCultureIgnoreCase))
         {
             trustDevicePost();
         }
         else
         {
             TimeSpan span = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0));
             apiToken = body["access_token"];
             string expireTime = body["access_token_expires_in"];
             accessTokenExpires = span.TotalSeconds + Double.Parse(expireTime);
             //add to rest client cookies
             cookies.Add(new Cookie("nxtk", apiToken)
             {
                 Domain = ".nexon.net"
             });
         }
     }
 }