- Release 0.7.6
This commit is contained in:
parent
4c469e404c
commit
2085bea970
@ -69,6 +69,22 @@
|
||||
_window.backgroundColor = [UIColor whiteColor];
|
||||
[_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;
|
||||
}
|
||||
|
||||
|
||||
35798
Example/Pods/Pods.xcodeproj/project.pbxproj
generated
35798
Example/Pods/Pods.xcodeproj/project.pbxproj
generated
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
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"
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
|
||||
@ -95,6 +95,7 @@
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||
|
||||
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) {
|
||||
|
||||
if (success) {
|
||||
|
||||
@ -35,7 +35,8 @@ NSInteger const minPassLenght = 4;
|
||||
NSString * const PNObjectEncryptionKey = @"PNObjectConfigEncryptionKey";
|
||||
NSString * const PNObjectEncryptionNonce = @"PNObjectConfigEncryptionNonce";
|
||||
|
||||
NSString * const PNObjectServiceCredentialIdentifier = @"PNObjectServiceCredentialIdentifier";
|
||||
NSString * const PNObjectServiceClientCredentialIdentifier = @"PNObjectServiceClientCredentialIdentifier";
|
||||
NSString * const PNObjectServiceUserCredentialIdentifier = @"PNObjectServiceUserCredentialIdentifier";
|
||||
|
||||
NSString* const EnvironmentProduction = @"PNObjectConfigEnvProduction";
|
||||
NSString* const EnvironmentStage = @"PNObjectConfigEnvStage";
|
||||
@ -77,7 +78,7 @@ static bool isFirstAccess = YES;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
isFirstAccess = NO;
|
||||
SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] init];
|
||||
SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] initWithUserSubclass:[PNUser class] withOauth:NO];
|
||||
});
|
||||
|
||||
return SINGLETON_PNObjectConfig;
|
||||
@ -103,11 +104,10 @@ static bool isFirstAccess = YES;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
isFirstAccess = NO;
|
||||
SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] init];
|
||||
SINGLETON_PNObjectConfig = [[super allocWithZone:NULL] initWithUserSubclass:userSubClass withOauth:oauthEnabled];
|
||||
|
||||
if (SINGLETON_PNObjectConfig) {
|
||||
SINGLETON_PNObjectConfig.oauthEnabled = oauthEnabled;
|
||||
SINGLETON_PNObjectConfig.userSubClass = userSubClass;
|
||||
|
||||
for (NSString *key in [endpointUrlsForEnvironments allKeys]) {
|
||||
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
@ -149,7 +149,7 @@ static bool isFirstAccess = YES;
|
||||
return [[PNObjectConfig alloc] init];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
- (id) initWithUserSubclass:(Class _Nonnull) userSubClass withOauth:(BOOL) oauthEnabled
|
||||
{
|
||||
if(SINGLETON_PNObjectConfig){
|
||||
return SINGLETON_PNObjectConfig;
|
||||
@ -160,10 +160,8 @@ static bool isFirstAccess = YES;
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
if (_oauthEnabled) {
|
||||
[AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
}
|
||||
|
||||
_oauthEnabled = oauthEnabled;
|
||||
_userSubClass = userSubClass;
|
||||
_configuration = [[NSMutableDictionary alloc] init];
|
||||
_minPasswordLenght = minPassLenght;
|
||||
|
||||
@ -184,6 +182,21 @@ static bool isFirstAccess = YES;
|
||||
[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;
|
||||
}
|
||||
@ -217,8 +230,6 @@ static bool isFirstAccess = YES;
|
||||
|
||||
- (AFHTTPSessionManager *) manager {
|
||||
|
||||
BOOL canTryRefreh = NO;
|
||||
|
||||
if (!_manager) {
|
||||
_manager = [AFHTTPSessionManager manager];
|
||||
}
|
||||
@ -232,9 +243,7 @@ static bool isFirstAccess = YES;
|
||||
[_jsonSerializer setValue:[_headerFields objectForKey:key] forHTTPHeaderField:key];
|
||||
}
|
||||
|
||||
if (canTryRefreh) {
|
||||
|
||||
if (_currentOauthCredential && ![_currentOauthCredential isExpired]) {
|
||||
if (_currentOauthCredential && ![_currentOauthCredential isExpired] && ![[_manager requestSerializer] hasAuthorizationHeaderField]) {
|
||||
|
||||
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
@ -243,7 +252,6 @@ static bool isFirstAccess = YES;
|
||||
else {
|
||||
[self refreshToken];
|
||||
}
|
||||
}
|
||||
|
||||
_manager.responseSerializer = [AFJSONResponseSerializerWithData serializer];
|
||||
_manager.requestSerializer = _jsonSerializer;
|
||||
@ -280,7 +288,7 @@ static bool isFirstAccess = YES;
|
||||
|
||||
if (canTryRefreh) {
|
||||
|
||||
if (_currentOauthCredential && ![_currentOauthCredential isExpired]) {
|
||||
if (_currentOauthCredential && ![_currentOauthCredential isExpired] && ![[_manager requestSerializer] hasAuthorizationHeaderField]) {
|
||||
|
||||
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
@ -299,8 +307,8 @@ static bool isFirstAccess = YES;
|
||||
- (BOOL) resetToken {
|
||||
if (_currentOauthCredential) {
|
||||
_currentOauthCredential = nil;
|
||||
|
||||
return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceClientCredentialIdentifier];
|
||||
return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceUserCredentialIdentifier];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@ -334,7 +342,7 @@ static bool isFirstAccess = YES;
|
||||
_currentOauthCredential = credential;
|
||||
|
||||
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
|
||||
|
||||
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
@ -398,7 +406,7 @@ static bool isFirstAccess = YES;
|
||||
_currentOauthCredential = credential;
|
||||
|
||||
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
|
||||
|
||||
[_httpSerializer 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) {
|
||||
_currentOauthCredential = credential;
|
||||
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
|
||||
|
||||
[_httpSerializer 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) {
|
||||
_currentOauthCredential = credential;
|
||||
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceClientCredentialIdentifier];
|
||||
|
||||
[_httpSerializer 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) {
|
||||
_currentOauthCredential = credential;
|
||||
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
|
||||
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceClientCredentialIdentifier];
|
||||
|
||||
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
[_jsonSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||
|
||||
@ -33,4 +33,6 @@
|
||||
*/
|
||||
- (void)setAuthorizationHeaderFieldWithCredential:(AFOAuthCredential *)credential;
|
||||
|
||||
- (BOOL) hasAuthorizationHeaderField;
|
||||
|
||||
@end
|
||||
|
||||
@ -32,4 +32,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) hasAuthorizationHeaderField {
|
||||
NSString *token = [self valueForHTTPHeaderField:@"Authorization"];
|
||||
|
||||
if ([token containsString:@"Bearer"]) {
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user