public static async Task DeviceAuthLogin(DeviceAuth deviceAuth) { WebClient webClient = new WebClient(); webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; webClient.Headers.Add("Authorization", "basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("ea2c2ef1b13c4158f987900918521d5d:a967ea60eefc1f8551a6034dc8e89000"))); NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty); queryString.Add("account_id", deviceAuth.AccountId); queryString.Add("device_id", deviceAuth.DeviceId); queryString.Add("secret", deviceAuth.Secret); queryString.Add("grant_type", "device_auth"); try { Globals.AuthData = (OAuthToken)JsonConvert.DeserializeObject <OAuthToken>(await webClient.UploadStringTaskAsync("https://api.aurorafn.dev/account/api/oauth/token", queryString.ToString())); } catch (WebException ex) { if (ex.Status != WebExceptionStatus.ProtocolError || ex.Response == null) { throw new Exception("Unable to connect to Aurora servers."); } HttpWebResponse response = (HttpWebResponse)ex.Response; if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.BadRequest) { throw new Exception("Invalid credentials!"); } throw new Exception("Unknown exception occurred!"); } }
private async Task LoginWithDeviceAuth(DeviceAuth auth) { Login login = this; try { await AuroraAuth.DeviceAuthLogin(auth); new Aurora.Launcher.Windows.Launcher().Show(); login.Close(); } catch (Exception ex) { login.SetLoggingIn(); } }
public static void SaveDeviceAuth(DeviceAuth deviceAuth) => AuroraConfig.Save(new Config() { DeviceAuth = deviceAuth, Path = AuroraConfig.Get()?.Path });