KGBasicChallengeHandler Class Reference
Inherits from | KGChallengeHandler : NSObject |
Declared in | KGBasicChallengeHandler.h |
Overview
Challenge handler for Basic authentication as defined in RFC 2617.
This BasicChallengeHandler can be loaded and instantiated using KGChallengeHandlers load, and registered at a location using KGDispatchChallengeHandler register. In addition, one can install general and realm-specific KGLoginHandler objects onto this KGBasicChallengeHandler to assist in handling challenges associated with any or specific realms. This can be achieved usingsetLoginHandler:
(LoginHandler*) and
setRealmLoginHandler:(NSString *)realm loginHandler:(
KGLoginHandler *)
loginHandler
methods.
The following example loads an instance of a KGBasicChallengeHandler, sets a login
handler onto it and registers the basic handler at a URI location. In this way, all attempts to access
that URI for which the server issues “Basic” challenges are handled by the registered KGBasicChallengeHandler.
@interface MyLoginHandler : KGLoginHandler
@end
@implementation MyLoginHandler
-(NSURLCredential*) credentials {
return [[NSURLCredential alloc] initWithUser:@"global" password:@"credentials" persistence:NSURLCredentialPersistenceNone];
}
@end
-(void)initChallenge {
// set up Login Handler:
MyLoginHandler* loginHandler = [[MyLoginHandler alloc] init];
KGBasicChallengeHandler* challengeHandler = [KGBasicChallengeHandler create];
[challengeHandler setLoginHandler:loginHandler];
// Attach the challenge handler as a default challenge handler to the KGWebSocketFactory
// It can also be attached to the KGWebSocket created using [KGWebSocket setChallengeHandler:]
[webSocketFactory setDefaultChallengeHandler:challengeHandler];
}
see RFC 2616 – HTTP 1.1 see RFC 2617 Section 2 – Basic Authentication
Tasks
-
– setRealmLoginHandler:loginHandler:
Set a Login Handler to be used if and only if a challenge request has a realm parameter matching the provided realm.
-
– setLoginHandler:
Provide a general (non-realm-specific) login handler to be used in association with this challenge handler. The login handler is used to assist in obtaining credentials to respond to any Basic challenge requests when no realm-specific login handler matches the realm parameter of the request (if any).
-
– loginHandler
Get the general (non-realm-specific) login handler associated with this challenge handler. A login handler is used to assist in obtaining credentials to respond to challenge requests.
Instance Methods
loginHandler
Get the general (non-realm-specific) login handler associated with this challenge handler. A login handler is used to assist in obtaining credentials to respond to challenge requests.
- (KGLoginHandler *)loginHandler
Return Value
a login handler to assist in providing credentials, or nil if none has been established yet.
Declared In
KGBasicChallengeHandler.h
setLoginHandler:
Provide a general (non-realm-specific) login handler to be used in association with this challenge handler. The login handler is used to assist in obtaining credentials to respond to any Basic challenge requests when no realm-specific login handler matches the realm parameter of the request (if any).
- (KGChallengeHandler *)setLoginHandler:(KGLoginHandler *)loginHandler
Parameters
- loginHandler
a login handler for credentials.
Declared In
KGBasicChallengeHandler.h
setRealmLoginHandler:loginHandler:
Set a Login Handler to be used if and only if a challenge request has a realm parameter matching the provided realm.
- (void)setRealmLoginHandler:(NSString *)realm loginHandler:(KGLoginHandler *)loginHandler
Parameters
- realm
the realm upon which to apply the loginHandler.
- loginHandler
the login handler to use for the provided realm.
Declared In
KGBasicChallengeHandler.h