Based on Apple's CustomHTTPProtocol,
JiveAuthenticatingHTTPProtocol
provides authentication callbacks for a UIWebView
.
No cleanup of the sample code has been done, so there might be some strange "patterns" inside.
See #3 for more details.
JiveAuthenticatingHTTPProtocol
captures all NSURLConnection
traffic.
- Ensure that no other
NSURLConnection
s can start after you call+[JAHPAuthenticatingHTTPProtocol start]
. - Before loading an
NSURLRequest
that may require handling an authentication callback, call+[JAHPAuthenticatingHTTPProtocol setDelegate:]
, - Then call
+[JAHPAuthenticatingHTTPProtocol start]
. - Finally, load your
NSURLRequest
, and handle the callbacks fromJAHPAuthenticatingHTTPProtocolDelegate
.
See JiveAuthenticatingHTTPProtocolDemo/ViewController.m
for an example.
It might be a good idea to memoize the credentials entered by the user to avoid "spamming" them with the data input alerts. This is an absolute "must" if your page contains the video which requires authorization.
This library supports all of the authentication schemes NSURLAuthentication
supports.
This has been tested with NTLM
and ADFS
authentication, (which NSURLAuthentication
natively supports). Basically, if an authentication method works in Safari
, it'll probably work here, too.
You can add more authorization methods like this :
- (BOOL)authenticatingHTTPProtocol:(JAHPAuthenticatingHTTPProtocol *)authenticatingHTTPProtocol
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
NSArray* interceptedAuthMethods =
@[
NSURLAuthenticationMethodHTTPBasic
, NSURLAuthenticationMethodNTLM
];
NSSet* interceptedAuthMethodsSet = [NSSet setWithArray: interceptedAuthMethods];
BOOL canAuthenticate =
[interceptedAuthMethodsSet containsObject: protectionSpace.authenticationMethod];
return canAuthenticate;
}
Stubbing the above function to always return "true" is not always a good idea.
If you do so, it would be your responsibility to implement all the required handshakes.
BSD per the LICENSE file.