- 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

@ -69,6 +69,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,7 +78,7 @@ 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;
@ -160,10 +160,8 @@ static bool isFirstAccess = YES;
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;
@ -184,6 +182,21 @@ static bool isFirstAccess = YES;
[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;
} }
@ -217,8 +230,6 @@ static bool isFirstAccess = YES;
- (AFHTTPSessionManager *) manager { - (AFHTTPSessionManager *) manager {
BOOL canTryRefreh = NO;
if (!_manager) { if (!_manager) {
_manager = [AFHTTPSessionManager manager]; _manager = [AFHTTPSessionManager manager];
} }
@ -232,17 +243,14 @@ static bool isFirstAccess = YES;
[_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];
@ -280,7 +288,7 @@ static bool isFirstAccess = YES;
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];
@ -299,8 +307,8 @@ static bool isFirstAccess = YES;
- (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;
} }
@ -334,7 +342,7 @@ static bool isFirstAccess = YES;
_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];
@ -398,7 +406,7 @@ static bool isFirstAccess = YES;
_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];
@ -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];
@ -472,7 +480,7 @@ static bool isFirstAccess = YES;
[_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];
@ -496,7 +504,7 @@ static bool isFirstAccess = YES;
[_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];

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