How to modify AWS api 401 response message to blank - api

We are trying to modify the response message of 401 response code on AWS API, from Unauthorized to blank but failing to do so.
tried below Terraform configuration:
/*response_parameters {
    status_code = 401
    mappings = {
      "overwrite:header.response.body" = ""
    }
  }*/
not sure if that's correct
thanks in advance!

Related

The origin '' did not find '' in the Access-Control-Allow-Origin response header for cross-origin image resource at ''

i use open layer map with mvc project ,
with cdn :
<script src="https://www.openlayers.org/api/OpenLayers.js"></script>
while i need to get location i have function
getlocation
function getLocation() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var loc_obj = JSON.parse(this.responseText);
if (loc_obj) {
usersLocationUpdated(loc_obj.latitude, loc_obj.longitude, loc_obj.added_time, loc_obj.located_time);
} else {
if (!mapLayer) {
mapLayer = new OpenLayers.Map("myMap");
}
markers = new OpenLayers.Layer.Markers("Markers");
mapLayer.addLayer(markers);
}
}
};
xhttp.open("POST", "../api/tracking/....", false);
xhttp.send();
}
the map working well in browser chrome
as appears in image :
but in IE,Edge and safari the map appears as image attached
when check console in failing browser (Edge and safari)
i have the error :
[CORS] The origin 'My web site ' did not find 'My web site '
in the Access-Control-Allow-Origin response header for cross-origin image resource at 'http://b.tile.openstreetmap.org/16/38663/27093.p'
i try many solution with send request as :
xhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
xhttp.setRequestHeader("Access-Control-Allow-Headers","*");
xhttp.setRequestHeader('Access-Control-Allow-Credentials', true);
Any help . !
OSM is CORS enabled but most browsers will reject CORS from an http url if the application is running on a https site. OpenLayers 2 defaults to an http address for OSM so try specifying it with an https address
new OpenLayers.Layer.OSM(
"OpenStreetMap",
["https://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
"https://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
"https://c.tile.openstreetmap.org/${z}/${x}/${y}.png"]
)

IBM MobileFirst Sending JSON Body from iOS SDK to Java Adapter

Using IBM Mobile First PlatForm Version 7.1 I am trying to call a Java Adapter from iOS Application using following code.
[[WLResourceRequest requestWithURL:url method:WLHttpMethodPost] sendWithJSON:#{#"one":#"two"} completionHandler:^(WLResponse *response, NSError *error) {
NSLog(#"%#",response);
NSLog(#"%#",error);
}];
Java Method on adapter side looks as following.
#POST
#Consumes("application/json")
#Produces("application/json")
public String hello(JSONObject body){
return body.toString();
}
But I get Following error in response
2016-04-20 11:31:15.520 mbs-call[15092:3787968] Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unsupported media type (415)" UserInfo={com.alamofire.serialization.response.error.response= { URL: http:/0.0.0.0:10080/mbs-api/adapters/basicadpt/users } { status code: 415, headers {
Connection = Close;
"Content-Language" = "en-US";
"Content-Length" = 0;
Date = "Wed, 20 Apr 2016 02:31:15 GMT";
"X-Powered-By" = "Servlet/3.0";
} }, NSErrorFailingURLKey=http://0.0.0.0:10080/mbs-api/adapters/basicadpt/users, com.alamofire.serialization.response.error.data=<>, NSLocalizedDescription=Request failed: unsupported media type (415)}
And it seems that in iOS SDK it adds header application/x-www-url-form-urlencoded in request when any method is called.
I have following 2 questions.
How to pass JSON Body to Java adapter?
Behaviour of sendWithJSON is different on iOS and Android. On Android it seems to add application/json header when we call adapter. Is that a bug or part of behaviour?
I believe this is a bug. I think that using sendWithJSON should automatically assume that the content type is application/json.
I suggest that you open a support request (PMR) so that they can improve the experience.
In the meantime, I found an easy workaround:
[request addHeaderValue:#"application/json" forName:#"Content-Type"]
Or in Swift:
request.addHeaderValue("application/json", forName: "Content-Type")
I had this same issue with the cordova version of an application.
var userIDTag = 'some_string';
var subTag = [userIDTag]; //<- this worked
var subTag = userIDTag; //<- this failed with the above error
var subTag = '[\'' + some_string + '\']'; //<- this also failed with the above error
The below is what I ended up doing for a Cordova app.
function subscribeByTag(userIDTag) {
var subTag = [userIDTag];
console.log("subTag: " + subTag);
WLAuthorizationManager.obtainAccessToken("push.mobileclient").then(
MFPPush.subscribe(
subTag,
function(subTag) {
navigator.notification.alert("Subscribed successfully");
},
function(failureResponse){
navigator.notification.alert("Failed to subscribe");
console.log("Failedtosubscribe:" + JSON.stringify(failureResponse));
}
)
);
}

AFNetworking incorrectly interpreted WP_Error error

I have client code that communicates with the server to create an account. The communication works, but the error response is not received correctly. In the Objective-C code below, I use AFNetworking to send the request. I purposely sent an invalid email address and expected the failure block to get executed, but my code kept going into the success block.
- (void)createAccount:(NSString *)email
andUsername:(NSString *)username
andPassword:(NSString *)password
success:(SuccessBlock)success
failure:(FailureBlock)failure
{
NSDictionary *params = #{
#"email": email,
#"username" : username,
#"password" : password,
#"client_id" : #"12345"
#"client_secret" : #"abcdef"
};
NSString *requestUrl = [self pathForEndpoint:#"users/new"
withVersion:ServiceRemoteRESTApibbPressExtVersion_1_0];
[self.api POST:requestUrl parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(responseObject); // WENT IN THIS PATH
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
failure(error); // EXPECTS THIS PATH
}
];
}
On the server side, my PHP scripts is coded as follow. I did check the debug.log and saw the printed message: *** users_new_REST_API() email invalid
add_action( 'rest_api_init', function () {
register_rest_route( 'bbpress_ext/v1', '/users/new', array(
'methods' => 'POST',
'callback' => 'users_new_REST_API'
) );
} );
public function users_new_REST_API( $request ) {
$user_name = $request['username'];
$password = $request['password'];
$user_email = $request['email'];
$client_id = $request['client_id'];
$client_secret = $request['client_secret'];
if ( ! is_email( $user_email ) ) {
error_log('*** users_new_REST_API() email invalid');
return new WP_Error('email_invalid', 'Invalid email entered.', array( 'status' => 524) );
}
}
I can't tell if AFNetworking is misbehaving or the REST-API (beta version 2) for Wordpress is broken.
Your understanding of AFNetworking error handling is incomplete. The error handler is for networking errors. It doesn't trigger for HTTP error codes. That's up to your app to decipher and handle. So, whether WP_Error returns a non-2XX HTTP status, or it just returns some kind of JSON object with some error information, AFNetworking is going to report the request succeeded.
It's not the job of AFNetworking to deal with app-level protocol logic.

php api connection code for bigcommerce not working

I'm using Web Matrix on a Windows machine with composer, and also have uploaded the same code to a windows server.
i have written my code in PHP to connect to Bigcommerce API but it just won't connect!
<?php
echo "made it";
require 'vendor/autoload.php';
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
'store_url' => 'https://store-bwvr466.mybigcommerce.com',
'username' => 'demo',
'api_key' => 'df38dd10e9665a3cfa667817d78ec91ee9384bc3'
));
Bigcommerce_Api::setCipher('rsa_rc4_128_sha');
Bigcommerce_Api::verifyPeer(false);
$products = Bigcommerce_Api::getProducts();
foreach($products as $product) {
echo $product->name;
echo $product->price;
echo " at bottom";
?>
I've read the other posts, but nothing seems to help. The first echo statement runs, but nothing else, including the bottom echo.
Please don't tell me to use curl as it's murder to install in windows!
HELP!
You have to change Bigcommerce_Api to Bigcommerce
<?php
echo "start";
require "bigcommerce.php";
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
   'store_url' => 'https://store-bwvr466.mybigcommerce.com',
   'username' => 'demo',
   'api_key' => 'df38dd10e9665a3cfa667817d78ec91ee9384bc3'
   ));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
$products = Bigcommerce::getProducts();
foreach($products as $product) {
   echo $product->name;
   echo $product->price;
}
echo "end";
?>

Google Apps Auth with edu.au domain

I am trying to authentify a domain for google docs scope. This is the url:
https://www.google.com/accounts/AuthSubRequest?next=http%3A%2F%2Fwww.mydomain.edu.au%2Fcomponents%2Fgoogle%2FretrieveToken.php&scope=https%3A%2F%2Fdocs.google.com%2Ffeeds%2F&session=1&secure=0&hd=default
So my domain is: www.mydomain.edu.au
But when makng the request Then i get this answer:
The page you have requested cannot be displayed. Another site was requesting access to your Google Account, but sent a malformed request. Please contact the site that you were trying to use when you received this message to inform them of the error. A detailed error message follows:
The site "http://edu.au" has not been registered.
So its identified as edu.au domain.
Is there a way around this?
Thanx
sample code for uploading document to google docs:
public static function uploadDocs($data = array())
{
if (!self::checkInput($data)) return false;
$data['url'] = Google::docsAPIUrl.'default/private/full'.self::getFolder($data['folderId']);
//"?convert=false"
$headers = Google::getAuthToken();
array_push($headers, Google::getGData());
$contentHeaders = self::getInputHeaders($data);
array_push($headers, 'Content-Length: '.$contentHeaders['length']);
array_push($headers, 'Content-Type: '.$contentHeaders['type']);
array_push($headers, 'Slug: '.Html::win2utf8($data['docTitle']));
if ($data['inputMethod'] == 'File')
{
$data['input'] = ((fread(fopen($data['input'], 'rb'), filesize($data['input']))));
}
$curl = Google::curl($data['url'], null, $data['input'], $headers);
if (Curl::checkCode($curl['code']))
{
return self::parseNewXML($curl['response']);
}
else
{
Google::$error = array('errorCode'=>$curl['code'],'errorString'=>$curl['response']);
return false;
}
}
AuthSub is deprecated. You should be using OAuth 2.0 and Drive API v2.