1

can i access resources on a website protected by form-based authentication from an iOS app?

i have read that it is possible to send the login details in a GET / POST url connection but it seems unsatisfactory.

Networking overview talks about NSURLAuthenticationMethodHTMLForm but I cannot find any working examples

rmaddy
  • 314,917
  • 42
  • 532
  • 579
MitchBroadhead
  • 811
  • 14
  • 23
  • Did you check if service you need exposes API ? – dpizzuto May 09 '14 at 14:02
  • the service is a tomcat realm protected by FORM authentication. submitting j_userame and j_password to j_security_check would work. wondered if there was a method for doing this in xcode – MitchBroadhead May 09 '14 at 14:08
  • With "form" you mean HTTP Header basic auth ? In this case yes and you can do this by creating request with [NSMutableURLRequest](https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html) and setting the fields and values you need. – dpizzuto May 09 '14 at 14:31
  • in tomcat the choices are BASIC, DIGEST and FORM authentication. i am trying to access a realm with FORM authentication which redirects the user to an HTML login page. have you an example of sending the username and password on the NSMutableURLRequest? how does it detect if authentication failed etc? – MitchBroadhead May 09 '14 at 14:44
  • In this case, if you know the Url called when the form are sent (tipically the HTML action make HTTP Post request with specified parameters), you can create same Post request using even basic HTTP client available. [Here](http://stackoverflow.com/a/15749527/2307276) an example of post request. – dpizzuto May 09 '14 at 14:55
  • i realise i can send a HTTP GET or POST directly. i really wanted to know if iOS had a direct method of dealing with this form of authentication. – MitchBroadhead May 09 '14 at 16:19
  • No, there aren't classes in iOS library to auth with html form directly. – dpizzuto May 09 '14 at 18:32

0 Answers0