public void EnsureKeyCanAccessPackages(IEnumerable <string> packageIds, string key) { using (IHttpClient client = _httpClientAdapter.GetHttpClient(_configSettings.FrontEndWebSiteRoot)) { string uri = string.Format("{0}/{1}", _configSettings.AuthorizePackageIdsUri, key); HttpContent content = HttpContentExtensions.CreateJsonDataContract(packageIds); using (HttpResponseMessage response = client.Post(uri, content)) { if (response.StatusCode != HttpStatusCode.OK) { _logger.Error("External call returned non-OK status of '{0}'. Authorization for Packages failed.", response.StatusCode); throw new Exception("An error occurred when trying to authorize access to PackagesIds."); } bool accessAllowed; if (!bool.TryParse(response.Content.ReadAsString(), out accessAllowed) || !accessAllowed) { _logger.Error("The given userkey was refused access one or more of the given Package IDs."); throw new PackageAuthorizationException(); } } } }
public void ValidateNonce(string nonce) { using (IHttpClient client = _httpClientAdapter.GetHttpClient(_configSettings.FrontEndWebSiteRoot)) { string uri = string.Format("{0}/{1}", _configSettings.AuthorizeRatingsUri, nonce); using (HttpResponseMessage response = client.Get(uri)) { if (response.StatusCode != HttpStatusCode.OK) { _logger.Error("External call returned non-OK status of '{0}'. Authorization for Ratings Update failed.", response.StatusCode); throw new Exception("An error occurred when trying to authorize access to Ratings Update."); } bool accessAllowed; if (!bool.TryParse(response.Content.ReadAsString(), out accessAllowed) || !accessAllowed) { _logger.Error("The given key was refused access for updating the aggregate ratings."); throw new Exception("The given key was refused access for updating the aggregate ratings."); } } } }