Skip to content

Commit 984c51b

Browse files
author
Pat Patterson
committed
Switch to X-Authorization HTTP header between JS and proxy for better compatibility
1 parent ebd92f6 commit 984c51b

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

forcetk.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@ if (forcetk.Client === undefined) {
7272
if (location.protocol === 'file:'){
7373
// In PhoneGap
7474
this.proxy_url = null;
75+
this.authzHeader = null;
7576
} else {
7677
// In Visualforce
7778
this.proxy_url = location.protocol + "//" + location.hostname
7879
+ "/services/proxy";
80+
this.authzHeader = "Authorization";
7981
}
8082
} else {
8183
// On a server outside VF
8284
this.proxy_url = proxyUrl;
85+
this.authzHeader = "X-Authorization";
8386
}
8487
}
8588

@@ -92,8 +95,8 @@ if (forcetk.Client === undefined) {
9295
* @param [payload=null] payload for POST/PATCH etc
9396
*/
9497
forcetk.Client.prototype.ajax = function(path, callback, error, method, payload) {
98+
var that = this;
9599
var url = this.instance_url + '/services/data' + path;
96-
var sessionId = this.sessionId;
97100

98101
$j.ajax({
99102
type: (typeof method === 'undefined' || method == null)
@@ -107,10 +110,10 @@ if (forcetk.Client === undefined) {
107110
error: error,
108111
dataType: "json",
109112
beforeSend: function(xhr) {
110-
if (this.proxy_url !== null) {
113+
if (that.proxy_url !== null) {
111114
xhr.setRequestHeader('SalesforceProxy-Endpoint', url);
112115
}
113-
xhr.setRequestHeader("Authorization", "OAuth " + sessionId);
116+
xhr.setRequestHeader(that.authzHeader, "OAuth " + that.sessionId);
114117
}
115118
});
116119
}

proxy.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
$url_query_param = null; // 'url'
175175
$url_header = 'HTTP_SALESFORCEPROXY_ENDPOINT';
176176

177-
$authz_header = 'AUTHORIZATION';
177+
$authz_header = 'HTTP_X_AUTHORIZATION';
178178

179179
$return_all_headers = true;
180180

@@ -186,22 +186,10 @@
186186

187187
$status = array();
188188

189-
// Get the full collection of HTTP headers - start with $_SERVER...
190-
$request_headers = $_SERVER;
191-
192-
// ...and add anything in apache_request_headers() that's not already there
193-
foreach(apache_request_headers() as $key=>$value) {
194-
$key = str_replace(" ","_",strtoupper(str_replace("-"," ",$key)));
195-
if ((! array_key_exists($key, $request_headers))
196-
&& (! array_key_exists('HTTP_'.$key, $request_headers))) {
197-
$request_headers[$key]=urldecode($value);
198-
}
199-
}
200-
201189
if ( $url_query_param != null ) {
202190
$url = $_GET[$url_query_param];
203191
} else if ( $url_header != null ) {
204-
$url = $request_headers[$url_header];
192+
$url = $_SERVER[$url_header];
205193
} else {
206194
$url = null;
207195
}
@@ -260,13 +248,13 @@
260248
}
261249

262250
$headers = array();
263-
if ( isset($authz_header) && isset($request_headers[$authz_header]) ) {
251+
if ( isset($authz_header) && isset($_SERVER[$authz_header]) ) {
264252
// Set the Authorization header
265-
array_push($headers, "Authorization: ".$request_headers[$authz_header] );
253+
array_push($headers, "Authorization: ".$_SERVER[$authz_header] );
266254
}
267-
if ( isset($request_headers['CONTENT_TYPE']) ) {
255+
if ( isset($_SERVER['CONTENT_TYPE']) ) {
268256
// Pass through the Content-Type header
269-
array_push($headers, "Content-Type: ".$request_headers['CONTENT_TYPE'] );
257+
array_push($headers, "Content-Type: ".$_SERVER['CONTENT_TYPE'] );
270258
}
271259
if ( count($headers) > 0 ) {
272260
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

0 commit comments

Comments
 (0)