private void _hasPhoneAttached(IWebRequest web, HasPhoneCallback callback) { var postData = new Dictionary <string, string> { ["op"] = "has_phone", ["arg"] = "null", ["sessionid"] = this.session.SessionID }; web.Request(ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", postData, this.cookies, (response, code) => { if (code == HttpStatusCode.Forbidden) { callback(PhoneStatus.FamilyView); return; } if (response == null || code != HttpStatusCode.OK) { callback(PhoneStatus.Detatched); return; } var hasPhoneResponse = JsonConvert.DeserializeObject <HasPhoneResponse>(response); callback(hasPhoneResponse.HasPhone ? PhoneStatus.Attached : PhoneStatus.Detatched); }); }
public void AddAuthenticator(IWebRequest web, LinkCallback callback) { HasPhoneCallback hasPhoneCallback = hasPhone => { if (hasPhone == PhoneStatus.FamilyView) { callback(LinkResult.FamilyViewEnabled); return; } bool settingNumber = !string.IsNullOrEmpty(this.PhoneNumber); if (hasPhone == PhoneStatus.Attached && settingNumber) { callback(LinkResult.MustRemovePhoneNumber); return; } if (hasPhone == PhoneStatus.Detatched && !settingNumber) { callback(LinkResult.MustProvidePhoneNumber); return; } BCallback numberAddedCallback = numberAdded => { if (!numberAdded) { callback(LinkResult.GeneralFailure); return; } var postData = new Dictionary <string, string>(); postData["access_token"] = this.session.OAuthToken; postData["steamid"] = this.session.SteamID.ToString(); postData["authenticator_type"] = "1"; postData["device_identifier"] = this.DeviceID; postData["sms_phone_id"] = "1"; web.MobileLoginRequest(ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/AddAuthenticator/v0001", "POST", postData, (response, code) => { if (response == null || code != HttpStatusCode.OK) { callback(LinkResult.GeneralFailure); return; } var addAuthenticatorResponse = JsonConvert.DeserializeObject <WebResponse <SteamGuardAccount> >(response); if (addAuthenticatorResponse?.Response == null) { callback(LinkResult.GeneralFailure); return; } if (addAuthenticatorResponse.Response.Status == 29) { callback(LinkResult.AuthenticatorPresent); return; } if (addAuthenticatorResponse.Response.Status != 1) { callback(LinkResult.GeneralFailure); return; } this.LinkedAccount = addAuthenticatorResponse.Response; // Force not enrolled at this stage this.LinkedAccount.FullyEnrolled = false; this.LinkedAccount.Session = this.session; this.LinkedAccount.DeviceID = this.DeviceID; callback(LinkResult.AwaitingFinalization); }); }; if (hasPhone == PhoneStatus.Detatched) { this._addPhoneNumber(web, numberAddedCallback); } else { numberAddedCallback(true); } }; if (string.IsNullOrEmpty(this.Pin)) { this._hasPhoneAttached(web, hasPhoneCallback); } else { this.UnlockFamilyView(web, success => { if (success) { this._hasPhoneAttached(web, hasPhoneCallback); } else { callback(LinkResult.FamilyViewEnabled); } }); } }