diff options
author | Vitaly Takmazov | 2019-03-19 22:53:05 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-19 22:53:05 +0300 |
commit | 9ac177e6a55d83b470529834ee4d635ad746e297 (patch) | |
tree | 700a17d39cdf032258c005276acf4de4c1e03b14 /Juick | |
parent | 12bd1e22cdf0ec3b2e2d7efea6ba6de201ec4ffe (diff) |
re-read authorization on each AFHTTPSessionManager access
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.m | 14 | ||||
-rw-r--r-- | Juick/Model/User.m | 3 |
2 files changed, 10 insertions, 7 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index b812057..ae2ebad 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -31,10 +31,6 @@ self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:baseURLString]]; self.manager.requestSerializer = [AFJSONRequestSerializer new]; [self.manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - NSString *username = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"]; - if (username) { - [self.manager.requestSerializer setAuthorizationHeaderFieldWithUsername:username password:[SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]]; - } self.backgroundQueue = [NSOperationQueue new]; self.dateFormatter = [[NSDateFormatter alloc] init]; self.dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; @@ -43,6 +39,16 @@ return self; } +-(AFHTTPSessionManager *) manager { + NSString *username = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"]; + if (username) { + [_manager.requestSerializer + setAuthorizationHeaderFieldWithUsername:username + password:[SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]]; + } + return _manager; +} + -(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; [self.backgroundQueue addOperationWithBlock:^{ diff --git a/Juick/Model/User.m b/Juick/Model/User.m index 848fc2a..7f97e34 100644 --- a/Juick/Model/User.m +++ b/Juick/Model/User.m @@ -40,9 +40,6 @@ +(void) checkIsValid:(void (^)(BOOL))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; - NSString *username = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"]; - NSString *password = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]; - [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:username password:password]; [manager POST:@"post" parameters:nil progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode; if (statusCode == 400) { |