Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter REST API Library Ajax PUT throwing 403 Forbidden
    primarykey
    data
    text
    <p>I got the rest of the library working fully, just trying to generate api keys and its throwing a 403 forbidden when executed via ajax.</p> <p><code>({"status":false,"error":"Invalid API Key."})</code></p> <p>I traced it to _remap function under REST_Controller.. almost as if im calling the url incorrectly?</p> <p><strong>workflow:</strong> <code>user visits site1.com -&gt; registers for account -&gt; generates api key for their domain -&gt; key recorded in db -&gt; key displayed</code></p> <p>The following form would be on site1.com after they register for an account they would click "generate key".</p> <p><strong>ajax call:</strong></p> <pre><code>/** * Generate an API Key for Us to use */ $("#submitGetApiKey").click(function(){ $.ajax({ url: "http://dev.site1.com/api/key", crossDomain: true, type: "PUT", dataType: "jsonp", error: function(XMLHttpRequest, textStatus, errorThrown){ alert(errorThrown); }, success: function(data){ for (var i = keys.length - 1; i &gt;= 0; i--) { console.log(keys[i]); }; } }); }); </code></pre> <p>REST-SERVER on GitHub: <a href="https://github.com/philsturgeon/codeigniter-restserver" rel="noreferrer">https://github.com/philsturgeon/codeigniter-restserver</a></p> <p>look specifically at key.php under <code>application/controllers/api/key.php</code></p> <p><strong>Snippet of the key.php file that should relate to this process:</strong></p> <pre><code>/** * Key Create * * Insert a key into the database. * * @access public * @return void */ public function index_put() { // Build a new key $key = self::_generate_key(); // If no key level provided, give them a rubbish one $level = $this-&gt;put('level') ? $this-&gt;put('level') : 1; $ignore_limits = $this-&gt;put('ignore_limits') ? $this-&gt;put('ignore_limits') : 1; // Insert the new key if (self::_insert_key($key, array('level' =&gt; $level, 'ignore_limits' =&gt; $ignore_limits))) { $this-&gt;response(array('status' =&gt; 1, 'key' =&gt; $key), 201); // 201 = Created } else { $this-&gt;response(array('status' =&gt; 0, 'error' =&gt; 'Could not save the key.'), 500); // 500 = Internal Server Error } } </code></pre> <p><strong>Response/Request Headers</strong> </p> <pre><code>Request URL:http://dev.mapitusa.com/api/key Request Method:PUT Status Code:403 Forbidden Request Headersview source Accept:application/json, text/javascript, */*; q=0.01 Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Length:0 Cookie:ci_session=a%3A4%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22e165df34aa4fda5936e940658030f83d%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A9%3A%22127.0.0.1%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A118%3A%22Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_7_3%29+AppleWebKit%2F535.19+%28KHTML%2C+like+Gecko%29+Chrome%2F18.0.1025.3+Safari%2F535.19%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1328291821%3B%7Dac0f163b112dbd3769e67f4bb7122db2 Host:dev.mapitusa.com Origin:http://dev.mapitusa.com Referer:http://dev.mapitusa.com/api_test.html User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.3 Safari/535.19 Response Headersview source Cache-Control:max-age=0, public Connection:Keep-Alive Content-Encoding:gzip Content-Length:69 Content-Type:application/json Date:Fri, 03 Feb 2012 18:03:54 GMT Expires:Fri, 03 Feb 2012 18:03:54 GMT Keep-Alive:timeout=5, max=98 Server:Apache Set-Cookie:ci_session=a%3A4%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22f2f466f7b97b89f2a9b557d2d9a0dbcc%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A9%3A%22127.0.0.1%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A118%3A%22Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_7_3%29+AppleWebKit%2F535.19+%28KHTML%2C+like+Gecko%29+Chrome%2F18.0.1025.3+Safari%2F535.19%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1328292234%3B%7D6821b96c7e58b55f1767eb265ffdb79e; expires=Fri, 03-Feb-2012 20:03:54 GMT; path=/ Status:403 Vary:Accept-Encoding,User-Agent X-Powered-By:PHP/5.3.6 X-UA-Compatible:IE=Edge,chrome=1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload