Skip to content

HTTP Authentication Support on RestKit

spiderr edited this page Jan 17, 2012 · 5 revisions

HTTP Authentication is the simplest method to implement, especially if you are creating your own REST service. RestKit supports HTTP AUTH digest and other flavors supported by NSURLConnection. For other authentication standards, see OAuth Support on RestKit.

Usage

See Tutorial : Introduction to RestKit for a general overview. Below are details for creating an authenticated client.

// Be default, this will create a client with RKRequestAuthenticationTypeHTTPBasic
[RKClient clientWithBaseURL:@"http://example.com/api/" username:@"bob" password:@"s3cr3t"];

Server Side Implementation

While outside the scope of RestKit, the following information will help you if you are also implementing the server side of your REST application.

PHP HTTP Auth Documenation has a straightforward example. Copy the Basic or Digest sample code into http://example.com/api/index.php and you should be up and running immediately. If your API has multiple php files, create an include file with that code, and include it at the top of each file.

Troubleshooting

  • Make sure you have the Auth Digest module installed in your webserver. This is often not installed on hosted servers. For Apache, you can test this with 'httpd -M' on the command line, and look for 'auth_digest_module'