Adding credential property to AFURLConnectionOperation
This commit is contained in:
parent
121ef7afa8
commit
1d243f7794
2 changed files with 19 additions and 2 deletions
|
|
@ -124,6 +124,18 @@
|
||||||
*/
|
*/
|
||||||
@property (readonly, nonatomic, assign) NSStringEncoding responseStringEncoding;
|
@property (readonly, nonatomic, assign) NSStringEncoding responseStringEncoding;
|
||||||
|
|
||||||
|
|
||||||
|
///--------------------------------
|
||||||
|
/// @name Accessing URL Credentials
|
||||||
|
///--------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
|
||||||
|
|
||||||
|
@discussion This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong) NSURLCredential *credential;
|
||||||
|
|
||||||
///------------------------
|
///------------------------
|
||||||
/// @name Accessing Streams
|
/// @name Accessing Streams
|
||||||
///------------------------
|
///------------------------
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
@synthesize totalBytesRead = _totalBytesRead;
|
@synthesize totalBytesRead = _totalBytesRead;
|
||||||
@dynamic inputStream;
|
@dynamic inputStream;
|
||||||
@synthesize outputStream = _outputStream;
|
@synthesize outputStream = _outputStream;
|
||||||
|
@synthesize credential = _credential;
|
||||||
@synthesize userInfo = _userInfo;
|
@synthesize userInfo = _userInfo;
|
||||||
@synthesize backgroundTaskIdentifier = _backgroundTaskIdentifier;
|
@synthesize backgroundTaskIdentifier = _backgroundTaskIdentifier;
|
||||||
@synthesize uploadProgress = _uploadProgress;
|
@synthesize uploadProgress = _uploadProgress;
|
||||||
|
|
@ -545,10 +546,10 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
} else {
|
} else {
|
||||||
if ([challenge previousFailureCount] == 0) {
|
if ([challenge previousFailureCount] == 0) {
|
||||||
NSURLCredential *credential = nil;
|
NSURLCredential *credential = nil;
|
||||||
|
|
||||||
NSString *username = (__bridge_transfer NSString *)CFURLCopyUserName((__bridge CFURLRef)[self.request URL]);
|
NSString *username = (__bridge_transfer NSString *)CFURLCopyUserName((__bridge CFURLRef)[self.request URL]);
|
||||||
NSString *password = (__bridge_transfer NSString *)CFURLCopyPassword((__bridge CFURLRef)[self.request URL]);
|
NSString *password = (__bridge_transfer NSString *)CFURLCopyPassword((__bridge CFURLRef)[self.request URL]);
|
||||||
|
|
||||||
if (username && password) {
|
if (username && password) {
|
||||||
credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
|
credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
|
||||||
} else if (username) {
|
} else if (username) {
|
||||||
|
|
@ -556,6 +557,10 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
} else {
|
} else {
|
||||||
credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
|
credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!credential) {
|
||||||
|
credential = self.credential;
|
||||||
|
}
|
||||||
|
|
||||||
if (credential) {
|
if (credential) {
|
||||||
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue