示例#1
0
 public AuthInfo Login()
 {
     AuthInfo AI = new AuthInfo();
     try
     {
         HttpWebRequest auth = (HttpWebRequest)WebRequest.Create(helper.Validate);
         auth.Method = "POST";
         auth.ContentType = "application/json";
         RefreshRequest ag = new RefreshRequest(AccessToken);
         string logindata = JsonConvert.SerializeObject(ag, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
         byte[] postdata = Encoding.UTF8.GetBytes(logindata);
         auth.ContentLength = postdata.LongLength;
         Stream poststream = auth.GetRequestStream();
         poststream.Write(postdata, 0, postdata.Length);
         poststream.Close();
         HttpWebResponse authans = (HttpWebResponse)auth.GetResponse();
         if(authans.StatusCode == HttpStatusCode.NoContent)
         {
             AI.Pass = true;
             return AI;
         }
         AI.Pass = false;
         return AI;
     }
     catch (WebException ex)
     {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message + new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
         return AI;
     }
     catch (Exception ex)
     {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message;
         return AI;
     }
 }
示例#2
0
 public AuthInfo Login()
 {
     AuthInfo AI = new AuthInfo();
     try
     {
         HttpWebRequest auth = (HttpWebRequest)WebRequest.Create(helper.Refresh);
         auth.Method = "POST";
         auth.ContentType = "application/json";
         RefreshRequest ag = new RefreshRequest(AccessToken);
         string logindata = JsonConvert.SerializeObject(ag, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
         byte[] postdata = Encoding.UTF8.GetBytes(logindata);
         auth.ContentLength = postdata.LongLength;
         Stream poststream = auth.GetRequestStream();
         poststream.Write(postdata, 0, postdata.Length);
         poststream.Close();
         HttpWebResponse authans = (HttpWebResponse)auth.GetResponse();
         StreamReader ResponseStream = new StreamReader(authans.GetResponseStream());
         Response response = JsonConvert.DeserializeObject<Response>(ResponseStream.ReadToEnd());
         if (response.clientToken != MeCore.Config.GUID)
         {
             AI.ErrorMsg += "Client Token unmatched.";
         }
         if (response.selectedProfile != null) {
             AI.DisplayName = response.selectedProfile.name;
             AI.UUID = response.selectedProfile.id;
         }
         AI.Pass = true;
         AI.Session = response.accessToken;
         if (response.user != null)
         {
             AI.UserType = response.user.legacy ? "Legacy" : "Mojang";
             AI.Prop = response.user.properties != null ? JsonConvert.SerializeObject(response.user.properties, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) : "{}";
         }
         else
         {
             AI.UserType = "Mojang"; AI.Prop = "{}";
         }
         return AI;
     }
     catch (WebException ex) {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message + new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
         return AI;
     }
     catch (Exception ex) {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message;
         return AI;
     }
 }