- Release 0.7.6

This commit is contained in:
Giuseppe Nucifora 2016-04-28 01:02:36 +02:00
parent 4c469e404c
commit 2085bea970
7 changed files with 7474 additions and 28542 deletions

View File

@ -68,6 +68,22 @@
_window.backgroundColor = [UIColor whiteColor]; _window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible]; [_window makeKeyAndVisible];
/*[PNUser loginCurrentUserWithEmail:@"socials2@giuseppenucifora.com" password:@"asdasdasd" withBlockSuccess:^(PNUser * _Nullable responseObject) {
} failure:^(NSError * _Nonnull error) {
}];*/
if ([PNUser currentUser] && [[PNUser currentUser] isAuthenticated]) {
NSLogDebug(@"Login in corso...");
[[PNUser currentUser] reloadFormServerWithBlockSuccess:^(PNUser * _Nullable currentUser) {
NSLogDebug(@"Login Success...");
} failure:^(NSError * _Nonnull error) {
NSLogDebug(@"Login in error...");
}];
}
return YES; return YES;
} }

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "PNObject" s.name = "PNObject"
s.version = "0.7.5" s.version = "0.7.6"
s.summary = "PNObject is a simple replica of the more complex ParseObject" s.summary = "PNObject is a simple replica of the more complex ParseObject"
# This description is used to generate tags and improve search results. # This description is used to generate tags and improve search results.

View File

@ -95,6 +95,7 @@
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure { failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) { if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) {
[[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:parameters progress:uploadProgress success:^(NSURLSessionDataTask *task, id responseObject) { [[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:parameters progress:uploadProgress success:^(NSURLSessionDataTask *task, id responseObject) {
if (success) { if (success) {

View File

@ -35,7 +35,8 @@ NSInteger const minPassLenght = 4;
NSString * const PNObjectEncryptionKey = @"PNObjectConfigEncryptionKey"; NSString * const PNObjectEncryptionKey = @"PNObjectConfigEncryptionKey";
NSString * const PNObjectEncryptionNonce = @"PNObjectConfigEncryptionNonce"; NSString * const PNObjectEncryptionNonce = @"PNObjectConfigEncryptionNonce";
NSString * const PNObjectServiceCredentialIdentifier = @"PNObjectServiceCredentialIdentifier"; NSString * const PNObjectServiceClientCredentialIdentifier = @"PNObjectServiceClientCredentialIdentifier";
NSString * const PNObjectServiceUserCredentialIdentifier = @"PNObjectServiceUserCredentialIdentifier";
NSString* const EnvironmentProduction = @"PNObjectConfigEnvProduction"; NSString* const EnvironmentProduction = @"PNObjectConfigEnvProduction";
NSString* const EnvironmentStage = @"PNObjectConfigEnvStage"; NSString* const EnvironmentStage = @"PNObjectConfigEnvStage";
@ -77,9 +78,9 @@ static bool isFirstAccess = YES;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
isFirstAccess = NO; isFirstAccess = NO;
SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] init]; SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] initWithUserSubclass:[PNUser class] withOauth:NO];
}); });
return SINGLETON_PNObjectConfig; return SINGLETON_PNObjectConfig;
} }
@ -103,11 +104,10 @@ static bool isFirstAccess = YES;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
isFirstAccess = NO; isFirstAccess = NO;
SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] init]; SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] initWithUserSubclass:userSubClass withOauth:oauthEnabled];
if (SINGLETON_PNObjectConfig) { if (SINGLETON_PNObjectConfig) {
SINGLETON_PNObjectConfig.oauthEnabled = oauthEnabled;
SINGLETON_PNObjectConfig.userSubClass = userSubClass;
for (NSString *key in [endpointUrlsForEnvironments allKeys]) { for (NSString *key in [endpointUrlsForEnvironments allKeys]) {
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
@ -149,7 +149,7 @@ static bool isFirstAccess = YES;
return [[PNObjectConfig alloc] init]; return [[PNObjectConfig alloc] init];
} }
- (id) init - (id) initWithUserSubclass:(Class _Nonnull) userSubClass withOauth:(BOOL) oauthEnabled
{ {
if(SINGLETON_PNObjectConfig){ if(SINGLETON_PNObjectConfig){
return SINGLETON_PNObjectConfig; return SINGLETON_PNObjectConfig;
@ -158,20 +158,18 @@ static bool isFirstAccess = YES;
[self doesNotRecognizeSelector:_cmd]; [self doesNotRecognizeSelector:_cmd];
} }
self = [super init]; self = [super init];
if (self) { if (self) {
if (_oauthEnabled) { _oauthEnabled = oauthEnabled;
[AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; _userSubClass = userSubClass;
}
_configuration = [[NSMutableDictionary alloc] init]; _configuration = [[NSMutableDictionary alloc] init];
_minPasswordLenght = minPassLenght; _minPasswordLenght = minPassLenght;
_jsonSerializer = [AFJSONRequestSerializer serializer]; _jsonSerializer = [AFJSONRequestSerializer serializer];
_httpSerializer = [AFHTTPRequestSerializer serializer]; _httpSerializer = [AFHTTPRequestSerializer serializer];
_headerFields = [[NSMutableDictionary alloc] init]; _headerFields = [[NSMutableDictionary alloc] init];
NSLog(@"%@",[NAKeychain symmetricKeyWithApplicationLabel:PNObjectEncryptionKey]); NSLog(@"%@",[NAKeychain symmetricKeyWithApplicationLabel:PNObjectEncryptionKey]);
if (![NAKeychain symmetricKeyWithApplicationLabel:PNObjectEncryptionKey]) { if (![NAKeychain symmetricKeyWithApplicationLabel:PNObjectEncryptionKey]) {
@ -182,33 +180,48 @@ static bool isFirstAccess = YES;
NSData *nonce = [NASecRandom randomData:16 error:&error]; NSData *nonce = [NASecRandom randomData:16 error:&error];
[NAKeychain addSymmetricKey:nonce applicationLabel:PNObjectEncryptionNonce tag:nil label:nil]; [NAKeychain addSymmetricKey:nonce applicationLabel:PNObjectEncryptionNonce tag:nil label:nil];
}
if (_oauthEnabled) {
AFOAuthCredential *clientCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceClientCredentialIdentifier];
if (clientCredential) {
_currentOauthCredential = clientCredential;
}
AFOAuthCredential *userCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceUserCredentialIdentifier];
if (userCredential) {
_currentOauthCredential = userCredential;
}
} }
} }
return self; return self;
} }
- (void) setEnvironment:(NSString * _Nonnull) environment { - (void) setEnvironment:(NSString * _Nonnull) environment {
_currentEnv = environment; _currentEnv = environment;
_currentEndPointBaseUrl = nil; _currentEndPointBaseUrl = nil;
_currentOAuthClientID = nil; _currentOAuthClientID = nil;
_currentOAuthClientSecret = nil; _currentOAuthClientSecret = nil;
if ([_configuration objectForKey:environment]) { if ([_configuration objectForKey:environment]) {
_currentEndPointBaseUrl = [[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl]; _currentEndPointBaseUrl = [[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl];
_currentOAuthClientID = [[_configuration objectForKey:_currentEnv] objectForKey:Client_ID]; _currentOAuthClientID = [[_configuration objectForKey:_currentEnv] objectForKey:Client_ID];
_currentOAuthClientSecret = [[_configuration objectForKey:_currentEnv] objectForKey:Client_Secret]; _currentOAuthClientSecret = [[_configuration objectForKey:_currentEnv] objectForKey:Client_Secret];
} }
NSLogDebug(@"%@",[[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl]); NSLogDebug(@"%@",[[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl]);
NSAssert(_currentEndPointBaseUrl,@"Selected environment generate error. Please check configuration"); NSAssert(_currentEndPointBaseUrl,@"Selected environment generate error. Please check configuration");
[self manager]; [self manager];
[self authManager]; [self authManager];
} }
- (NSString *) baseUrl { - (NSString *) baseUrl {
@ -216,72 +229,67 @@ static bool isFirstAccess = YES;
} }
- (AFHTTPSessionManager *) manager { - (AFHTTPSessionManager *) manager {
BOOL canTryRefreh = NO;
if (!_manager) { if (!_manager) {
_manager = [AFHTTPSessionManager manager]; _manager = [AFHTTPSessionManager manager];
} }
//_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; //_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
for (NSString *key in [_headerFields allKeys]) { for (NSString *key in [_headerFields allKeys]) {
[_httpSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key]; [_httpSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key];
[_jsonSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key]; [_jsonSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key];
} }
if (canTryRefreh) { if (_currentOauthCredential && ![_currentOauthCredential isExpired] && ![[_manager requestSerializer] hasAuthorizationHeaderField]) {
if (_currentOauthCredential && ![_currentOauthCredential isExpired]) { [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
}
else {
[self refreshToken];
}
} }
else {
[self refreshToken];
}
_manager.responseSerializer = [AFJSONResponseSerializerWithData serializer]; _manager.responseSerializer = [AFJSONResponseSerializerWithData serializer];
_manager.requestSerializer = _jsonSerializer; _manager.requestSerializer = _jsonSerializer;
return _manager; return _manager;
} }
- (AFOAuth2Manager *) authManager { - (AFOAuth2Manager *) authManager {
BOOL canTryRefreh = NO; BOOL canTryRefreh = NO;
if (!_authManager) { if (!_authManager) {
_authManager = [AFOAuth2Manager manager]; _authManager = [AFOAuth2Manager manager];
} }
//_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; //_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
if (_oauthEnabled && _currentOAuthClientID && _currentOAuthClientSecret) { if (_oauthEnabled && _currentOAuthClientID && _currentOAuthClientSecret) {
if (![_authManager clientID]) { if (![_authManager clientID]) {
_authManager = [AFOAuth2Manager managerWithBaseURL:[NSURL URLWithString:_currentEndPointBaseUrl] clientID:_currentOAuthClientID secret:_currentOAuthClientSecret]; _authManager = [AFOAuth2Manager managerWithBaseURL:[NSURL URLWithString:_currentEndPointBaseUrl] clientID:_currentOAuthClientID secret:_currentOAuthClientSecret];
} }
[_authManager setUseHTTPBasicAuthentication:NO]; [_authManager setUseHTTPBasicAuthentication:NO];
canTryRefreh = YES; canTryRefreh = YES;
} }
for (NSString *key in [_headerFields allKeys]) { for (NSString *key in [_headerFields allKeys]) {
[_httpSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key]; [_httpSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key];
[_jsonSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key]; [_jsonSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key];
} }
if (canTryRefreh) { if (canTryRefreh) {
if (_currentOauthCredential && ![_currentOauthCredential isExpired]) { if (_currentOauthCredential && ![_currentOauthCredential isExpired] && ![[_manager requestSerializer] hasAuthorizationHeaderField]) {
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
@ -290,23 +298,23 @@ static bool isFirstAccess = YES;
[self refreshToken]; [self refreshToken];
} }
} }
_authManager.responseSerializer = [AFJSONResponseSerializerWithData serializer]; _authManager.responseSerializer = [AFJSONResponseSerializerWithData serializer];
return _authManager; return _authManager;
} }
- (BOOL) resetToken { - (BOOL) resetToken {
if (_currentOauthCredential) { if (_currentOauthCredential) {
_currentOauthCredential = nil; _currentOauthCredential = nil;
[AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceClientCredentialIdentifier];
return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceUserCredentialIdentifier];
} }
return NO; return NO;
} }
- (void) refreshToken { - (void) refreshToken {
[self refreshTokenWithBlockSuccess:nil failure:nil]; [self refreshTokenWithBlockSuccess:nil failure:nil];
} }
@ -322,20 +330,20 @@ static bool isFirstAccess = YES;
} }
- (void) refreshTokenForUser { - (void) refreshTokenForUser {
[self refreshTokenForUserWithBlockSuccess:nil failure:nil]; [self refreshTokenForUserWithBlockSuccess:nil failure:nil];
} }
- (void) refreshTokenForUserWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success - (void) refreshTokenForUserWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
failure:(nullable void (^)(NSError * _Nonnull error))failure { failure:(nullable void (^)(NSError * _Nonnull error))failure {
if (_currentOauthCredential) { if (_currentOauthCredential) {
[_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] refreshToken:[_currentOauthCredential refreshToken] success:^(AFOAuthCredential * _Nonnull credential) { [_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] refreshToken:[_currentOauthCredential refreshToken] success:^(AFOAuthCredential * _Nonnull credential) {
_currentOauthCredential = credential; _currentOauthCredential = credential;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
@ -346,18 +354,18 @@ static bool isFirstAccess = YES;
success(YES); success(YES);
} }
return; return;
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[self resetToken]; [self resetToken];
[self refreshTokenForUserWithBlockSuccess:success failure:failure]; [self refreshTokenForUserWithBlockSuccess:success failure:failure];
return; return;
}]; }];
} }
else { else {
if([SINGLETON_PNObjectConfig.userSubClass currentUser] && [[SINGLETON_PNObjectConfig.userSubClass currentUser] hasValidEmailAndPasswordData]) { if([SINGLETON_PNObjectConfig.userSubClass currentUser] && [[SINGLETON_PNObjectConfig.userSubClass currentUser] hasValidEmailAndPasswordData]) {
[self refreshTokenForUserWithEmail:[[SINGLETON_PNObjectConfig.userSubClass currentUser] email] password:[[(PNUser*)[SINGLETON_PNObjectConfig.userSubClass currentUser] password] password] withBlockSuccess:success failure:failure]; [self refreshTokenForUserWithEmail:[[SINGLETON_PNObjectConfig.userSubClass currentUser] email] password:[[(PNUser*)[SINGLETON_PNObjectConfig.userSubClass currentUser] password] password] withBlockSuccess:success failure:failure];
return; return;
} }
@ -366,7 +374,7 @@ static bool isFirstAccess = YES;
} }
else { else {
if (failure) { if (failure) {
NSError *error = [NSError errorWithDomain:@"" code:kHTTPStatusCodeBadRequest userInfo:nil]; NSError *error = [NSError errorWithDomain:@"" code:kHTTPStatusCodeBadRequest userInfo:nil];
failure(error); failure(error);
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
@ -379,7 +387,7 @@ static bool isFirstAccess = YES;
password:(NSString * _Nonnull) password password:(NSString * _Nonnull) password
withBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success withBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
failure:(nullable void (^)(NSError * _Nonnull error))failure { failure:(nullable void (^)(NSError * _Nonnull error))failure {
if (![email isValidEmail]) { if (![email isValidEmail]) {
if (failure) { if (failure) {
NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Email is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil]; NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Email is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
@ -396,21 +404,21 @@ static bool isFirstAccess = YES;
} }
[_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:email password:password scope:nil success:^(AFOAuthCredential * _Nonnull credential) { [_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:email password:password scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
_currentOauthCredential = credential; _currentOauthCredential = credential;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserSuccess object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserSuccess object:nil];
if (success) { if (success) {
success(YES); success(YES);
} }
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
if (failure) { if (failure) {
failure(error); failure(error);
@ -439,7 +447,7 @@ static bool isFirstAccess = YES;
[_authManager authenticateUsingFacebookOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] facebookID:facebookID facebookToken:facebookToken scope:nil success:^(AFOAuthCredential * _Nonnull credential) { [_authManager authenticateUsingFacebookOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] facebookID:facebookID facebookToken:facebookToken scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
_currentOauthCredential = credential; _currentOauthCredential = credential;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier]; [AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
@ -466,28 +474,28 @@ static bool isFirstAccess = YES;
- (void) refreshTokenForClientCredentialWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success - (void) refreshTokenForClientCredentialWithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
failure:(nullable void (^)(NSError * _Nonnull error))failure { failure:(nullable void (^)(NSError * _Nonnull error))failure {
if (_currentOauthCredential) { if (_currentOauthCredential) {
[_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] refreshToken:[_currentOauthCredential refreshToken] success:^(AFOAuthCredential * _Nonnull credential) { [_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] refreshToken:[_currentOauthCredential refreshToken] success:^(AFOAuthCredential * _Nonnull credential) {
_currentOauthCredential = credential; _currentOauthCredential = credential;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier]; [AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceClientCredentialIdentifier];
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
if (success) { if (success) {
success(YES); success(YES);
} }
return; return;
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[self resetToken]; [self resetToken];
[self refreshTokenForClientCredentialWithBlockSuccess:success failure:failure]; [self refreshTokenForClientCredentialWithBlockSuccess:success failure:failure];
return; return;
}]; }];
@ -495,14 +503,14 @@ static bool isFirstAccess = YES;
else { else {
[_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] scope:nil success:^(AFOAuthCredential * _Nonnull credential) { [_authManager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
_currentOauthCredential = credential; _currentOauthCredential = credential;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier]; [AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceClientCredentialIdentifier];
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
if (success) { if (success) {
success(YES); success(YES);

View File

@ -33,4 +33,6 @@
*/ */
- (void)setAuthorizationHeaderFieldWithCredential:(AFOAuthCredential *)credential; - (void)setAuthorizationHeaderFieldWithCredential:(AFOAuthCredential *)credential;
- (BOOL) hasAuthorizationHeaderField;
@end @end

View File

@ -32,4 +32,13 @@
} }
} }
- (BOOL) hasAuthorizationHeaderField {
NSString *token = [self valueForHTTPHeaderField:@"Authorization"];
if ([token containsString:@"Bearer"]) {
return YES;
}
return NO;
}
@end @end