]> git.openstreetmap.org Git - rails.git/commitdiff
Ensure URL used for oauth header is absolute
authorJohn Firebaugh <john.firebaugh@gmail.com>
Sun, 21 Jul 2013 01:40:41 +0000 (18:40 -0700)
committerTom Hughes <tom@compton.nu>
Sun, 21 Jul 2013 07:47:21 +0000 (08:47 +0100)
Fixes #356.

app/assets/javascripts/oauth.js

index aac63f243fd40afd7a0ad7b322c81299778b29b6..98ce302e105925de575198d60624de4ce2013443 100644 (file)
@@ -1,6 +1,12 @@
 //= require ohauth
 
 $(document).ready(function () {
+  function makeAbsolute(url) {
+    var a = document.createElement('a');
+    a.href = url;
+    return a.href;
+  }
+
   if (OSM.oauth_token) {
     var headerGenerator = window.ohauth.headerGenerator({
       consumer_key: OSM.oauth_consumer_key,
@@ -12,7 +18,7 @@ $(document).ready(function () {
     $.ajaxPrefilter(function(options, jqxhr) {
       if (options.oauth) {
         options.headers = options.headers || {};
-        options.headers.Authorization = headerGenerator(options.type, options.url, jqxhr.data);
+        options.headers.Authorization = headerGenerator(options.type, makeAbsolute(options.url), jqxhr.data);
       }
     });
   }