private static void Reload() { var oldAppTokens = AppTokens; var oldSubTokens = PackageTokens; using (var db = Database.Get()) { AppTokens = db.Query <PICSToken>("SELECT `AppID`, `Token` FROM `PICSTokens`").ToDictionary(x => x.AppID, x => x.Token); PackageTokens = db.Query <PICSToken>("SELECT `SubID`, `Token` FROM `PICSTokensSubs`").ToDictionary(x => x.SubID, x => x.Token); } var apps = Enumerable.Empty <SteamApps.PICSRequest>(); var subs = Enumerable.Empty <SteamApps.PICSRequest>(); if (oldAppTokens != null) { apps = AppTokens .Where(x => !oldAppTokens.ContainsKey(x.Key)) .Select(app => NewAppRequest(app.Key, app.Value)); } if (oldSubTokens != null) { subs = PackageTokens .Where(x => !oldSubTokens.ContainsKey(x.Key)) .Select(sub => NewPackageRequest(sub.Key, sub.Value)); } if (apps.Any() || subs.Any()) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetProductInfo(apps, subs)); } }
private static void HandleAppToken(uint id, ulong accessToken) { if (!AppTokens.TryGetValue(id, out var existingToken)) { AppTokens.Add(id, accessToken); Log.WriteInfo(nameof(PICSTokens), $"New token for appid {id}"); using var db = Database.Get(); db.Execute("INSERT INTO `PICSTokens` (`AppID`, `Token`) VALUES(@AppID, @Token) ON DUPLICATE KEY UPDATE `Token` = VALUES(`Token`)", new PICSToken { AppID = id, Token = accessToken } ); } else if (existingToken != accessToken) { Log.WriteWarn(nameof(PICSTokens), $"New token for appid {id} that mismatches the existing one ({existingToken} != {accessToken})"); IRC.Instance.SendOps($"{Colors.RED}[Tokens] Bot got an app token that mismatches the one in database:{Colors.BLUE} {id} {Colors.NORMAL}({existingToken} != {accessToken})"); AppTokens[id] = accessToken; using var db = Database.Get(); db.Execute("UPDATE `PICSTokens` SET `Token` = @Token, `Date` = NOW() WHERE `AppID` = @AppID", new PICSToken { AppID = id, Token = accessToken } ); } }
private static void HandleAppToken(uint id, ulong accessToken) { if (!AppTokens.TryGetValue(id, out var existingToken)) { AppTokens.Add(id, accessToken); IRC.Instance.SendOps($"{Colors.GREEN}[Tokens]{Colors.NORMAL} Added a new app token that the bot got itself:{Colors.BLUE} {id} {Colors.NORMAL}({Steam.GetAppName(id)})"); Log.WriteInfo(nameof(PICSTokens), $"New token for appid {id}"); using var db = Database.Get(); db.Execute("INSERT INTO `PICSTokens` (`AppID`, `Token`) VALUES(@AppID, @Token)", new PICSToken { AppID = id, Token = accessToken } ); } else if (existingToken != accessToken) { Log.WriteWarn(nameof(PICSTokens), $"New token for appid {id} that mismatches the existing one ({existingToken} != {accessToken})"); IRC.Instance.SendOps($"{Colors.RED}[Tokens] Bot got an app token that mismatches the one in database:{Colors.BLUE} {id} {Colors.NORMAL}({existingToken} != {accessToken})"); AppTokens[id] = accessToken; } }
public static SteamApps.PICSRequest NewAppRequest(uint id) { if (AppTokens.TryGetValue(id, out var token)) { Log.WriteInfo(nameof(PICSTokens), "Using an overriden token for appid {0}", id); } return new SteamApps.PICSRequest(id, token, false); }
private static AppTokens GetConfigurationTokens() { AppTokens appTokens = new AppTokens(); appTokens.appId = AppSettings.Get(AppSettings.GEO_CLIENT_APP_ID); appTokens.appKey = AppSettings.Get(AppSettings.GEO_CLIENT_APP_KEY); return(appTokens); }
/// <summary> /// Method returns building information based on the BIN in NYC /// </summary> public static JObject GetBuildingDetailsFromGeoClientAPI(string buildingIdentificationNumber) { var client = new HttpClient(); client.BaseAddress = new Uri("https://api.cityofnewyork.us/"); AppTokens appTokens = GetConfigurationTokens(); HttpResponseMessage response = client.GetAsync("geoclient/v1/bin.json?bin=" + buildingIdentificationNumber + "&app_id=" + appTokens.appId + "&app_key=" + appTokens.appKey).Result; return(JObject.Parse(response.Content.ReadAsStringAsync().Result)); }
/// <summary> /// Method returns details based on BBL in NYC /// </summary> public static JObject GetBBLDetailsFromGeoClientAPI(string propertyBBL) { var client = new HttpClient(); client.BaseAddress = new Uri("https://api.cityofnewyork.us/"); AppTokens appTokens = GetConfigurationTokens(); string borough = BAL.BBL.GetBoroughName(propertyBBL); HttpResponseMessage response = client.GetAsync("geoclient/v1/bbl.json?borough=" + borough + "&block=" + propertyBBL.Substring(1, 5) + "&lot=" + propertyBBL.Substring(6, 4) + "&app_id=" + appTokens.appId + "&app_key=" + appTokens.appKey).Result; return(JObject.Parse(response.Content.ReadAsStringAsync().Result)); }
public async Task <IActionResult> Login(LinkedinUserAuthCodeDto linkedinUserAuthCodeDto) { string linkedinAuthToken = await ExchangeLinkedinCodeToUserToken(linkedinUserAuthCodeDto.LinkedinAuthCode); LinkedinUser linkedinUser = await GetLinkedinUser(linkedinAuthToken); User user = await _userManager.FindByEmailAsync(linkedinUser.Email); if (user == null) { user = new User { UserName = linkedinUser.Email.Split("@")[0], NickName = linkedinUser.LocalizedFirstName + " " + linkedinUser.LocalizedLastName, Email = linkedinUser.Email, PhotoUrl = await _photoController.UploadAvatarByUrl(linkedinUser.PhotoUrl), RegisteredVia = "Linkedin", Created = DateTime.Now, LastActive = DateTime.Now }; var result = await _userManager.CreateAsync(user); if (!result.Succeeded) { return(BadRequest("User not created")); } var res = _userManager.AddToRoleAsync(user, "User").Result; if (!res.Succeeded) { return(BadRequest("error on adding role for user")); } } // generate the jwt for the local user... var userForToken = await _userManager.FindByEmailAsync(user.Email); if (userForToken == null) { return(BadRequest("cant create user")); } string token = AppTokens.GenerateJwtToken(userForToken, _config, _userManager).Result; var userForReturnDto = _mapper.Map <UserForReturnDto>(userForToken); return(Ok(new { token = token, user = userForReturnDto })); }
private Task <bool> RequestPICSProductInfo(uint appId) { var tsc = new TaskCompletionSource <bool>(); SteamApps.PICSRequest request = new SteamApps.PICSRequest(appId); if (AppTokens.ContainsKey(appId)) { request.AccessToken = AppTokens[appId]; request.Public = false; } IDisposable subscription = null; Action <SteamApps.PICSProductInfoCallback> cbMethod = (appInfo) => { subscription.Dispose(); foreach (var app_value in appInfo.Apps) { var app = app_value.Value; DebugLog.WriteLine("Steam3Session", "Got AppInfo for " + app.ID); if (AppInfo.ContainsKey(app.ID)) { DebugLog.WriteLine("Steam3Session", "AppInfo already stored " + app.ID); continue; } AppInfo.Add(app.ID, app); } foreach (var app in appInfo.UnknownApps) { AppInfo.Add(app, null); } DebugLog.WriteLine("Steam3Session", "Response pending: " + appInfo.ResponsePending); tsc.SetResult(!appInfo.ResponsePending); }; subscription = callbacks.Subscribe(steamApps.PICSGetProductInfo(new List <SteamApps.PICSRequest>() { request }, new List <SteamApps.PICSRequest>() { }), cbMethod); return(tsc.Task); }
public async Task <IActionResult> FbLogin(FbUserAuthCodeDto fbUserAuthCodeDto) { string fbAuthToken = await ExchangeFbCodeToFbUserToken(fbUserAuthCodeDto.fbAuthCode); FbUser fbUser = await GetFbUser(fbAuthToken); User user = await _userManager.FindByEmailAsync(fbUser.Email); if (user == null) { user = new User { UserName = fbUser.Email.Split("@")[0], NickName = fbUser.Name, Email = fbUser.Email, PhotoUrl = await _photoController.UploadAvatarByUrl(fbUser.Picture.Data.Url) }; var result = await _userManager.CreateAsync(user); if (!result.Succeeded) { return(BadRequest("User not created")); } var res = _userManager.AddToRoleAsync(user, "User").Result; if (!res.Succeeded) { return(BadRequest("error on adding role for user")); } } // generate the jwt for the local user... var userForToken = await _userManager.FindByEmailAsync(user.Email); if (userForToken == null) { return(BadRequest("cant create user")); } string token = AppTokens.GenerateJwtToken(userForToken, _config, _userManager).Result; var userForReturnDto = _mapper.Map <UserForReturnDto>(userForToken); return(Ok(new { token = token, user = userForReturnDto })); }
public async Task <IActionResult> Login(UserForLoginDto userForLoginDto) { var user = await _userManager.FindByEmailAsync(userForLoginDto.Email); if (user == null) { return(Unauthorized()); } var result = await _signInManager.CheckPasswordSignInAsync(user, userForLoginDto.Password, false); if (result.Succeeded) { string token = await AppTokens.GenerateJwtToken(user, _config, _userManager); var userForReturnDto = _mapper.Map <UserForReturnDto>(user); return(Ok(new { token = token, user = userForReturnDto })); } return(Unauthorized()); }
/// <summary> /// Method returns address corrections and details based on street number, street address and borough for NYC properties /// </summary> public static JObject GetAddressDetailsFromGeoClientAPI(string streetNumber, string streetName, string borough) { var client = new HttpClient(); client.BaseAddress = new Uri("https://api.cityofnewyork.us/"); AppTokens appTokens = GetConfigurationTokens(); try { HttpResponseMessage response = client.GetAsync("geoclient/v1/address.json?houseNumber=" + streetNumber + "&street=" + streetName + "&borough=" + borough + "&app_id=" + appTokens.appId + "&app_key=" + appTokens.appKey).Result; return(JObject.Parse(response.Content.ReadAsStringAsync().Result)); } catch (Exception e) { Common.Logs.log().Error(string.Format("Geoclient API call failed{0}", Common.Logs.FormatException(e))); return(null); } }
public void RequestAppInfo(uint appId, bool bForce = false) { if ((AppInfo.ContainsKey(appId) && !bForce) || bAborted) { return; } bool completed = false; Action <SteamApps.PICSTokensCallback> cbMethodTokens = (appTokens) => { completed = true; if (appTokens.AppTokensDenied.Contains(appId)) { Log.Info("Insufficient privileges to get access token for app {0}", appId); } foreach (var token_dict in appTokens.AppTokens) { this.AppTokens[token_dict.Key] = token_dict.Value; } }; WaitUntilCallback(() => { callbacks.Subscribe(steamApps.PICSGetAccessTokens(new List <uint>() { appId }, new List <uint>() { }), cbMethodTokens); }, () => { return(completed); }); completed = false; Action <SteamApps.PICSProductInfoCallback> cbMethod = (appInfo) => { completed = !appInfo.ResponsePending; foreach (var app_value in appInfo.Apps) { var app = app_value.Value; Log.Info("Got AppInfo for {0}", app.ID); AppInfo[app.ID] = app; } foreach (var app in appInfo.UnknownApps) { AppInfo[app] = null; } }; SteamApps.PICSRequest request = new SteamApps.PICSRequest(appId); if (AppTokens.ContainsKey(appId)) { request.AccessToken = AppTokens[appId]; request.Public = false; } WaitUntilCallback(() => { callbacks.Subscribe(steamApps.PICSGetProductInfo(new List <SteamApps.PICSRequest>() { request }, new List <SteamApps.PICSRequest>() { }), cbMethod); }, () => { return(completed); }); }
public static SteamApps.PICSRequest NewAppRequest(uint id) { AppTokens.TryGetValue(id, out var token); return(new SteamApps.PICSRequest(id, token, false)); }
public static bool HasAppToken(uint id) => AppTokens.ContainsKey(id);
public void RequestAppInfo(uint appId) { if (AppInfo.ContainsKey(appId) || bAborted) { return; } Action <SteamApps.PICSTokensCallback, JobID> cbMethodTokens = (appTokens, jobId) => { if (appTokens.AppTokensDenied.Contains(appId)) { Console.WriteLine("Insufficient privileges to get access token for app {0}", appId); } foreach (var token_dict in appTokens.AppTokens) { this.AppTokens.Add(token_dict.Key, token_dict.Value); } }; using (JobCallback <SteamApps.PICSTokensCallback> appTokensCallback = new JobCallback <SteamApps.PICSTokensCallback>(cbMethodTokens, callbacks, steamApps.PICSGetAccessTokens(new List <uint>() { appId }, new List <uint>() { }))) { do { WaitForCallbacks(); }while (!appTokensCallback.Completed && !bAborted); } Action <SteamApps.PICSProductInfoCallback, JobID> cbMethod = (appInfo, jobId) => { Debug.Assert(appInfo.ResponsePending == false); foreach (var app_value in appInfo.Apps) { var app = app_value.Value; Console.WriteLine("Got AppInfo for {0}", app.ID); AppInfo.Add(app.ID, app); } foreach (var app in appInfo.UnknownApps) { AppInfo.Add(app, null); } }; SteamApps.PICSRequest request = new SteamApps.PICSRequest(appId); if (AppTokens.ContainsKey(appId)) { request.AccessToken = AppTokens[appId]; request.Public = false; } using (JobCallback <SteamApps.PICSProductInfoCallback> appInfoCallback = new JobCallback <SteamApps.PICSProductInfoCallback>(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List <SteamApps.PICSRequest>() { request }, new List <SteamApps.PICSRequest>() { }))) { do { WaitForCallbacks(); }while (!appInfoCallback.Completed && !bAborted); } }