- fix refresh token
This commit is contained in:
parent
9266ae3689
commit
45f9930941
@ -95,6 +95,12 @@
|
|||||||
- (void) refreshTokenAction {
|
- (void) refreshTokenAction {
|
||||||
[[PNObjectConfig sharedInstance] refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
[[PNObjectConfig sharedInstance] refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
||||||
|
|
||||||
|
[PNUser loginCurrentUserWithUsername:@"test" password:@"test" withBlockSuccess:^(PNUser * _Nullable responseObject) {
|
||||||
|
|
||||||
|
NSLog(@"success");
|
||||||
|
} failure:^(NSError * _Nonnull error) {
|
||||||
|
NSLog(@"%@",error);
|
||||||
|
}];
|
||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
|
|
||||||
}];
|
}];
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'PNObject'
|
s.name = 'PNObject'
|
||||||
s.version = '2.0'
|
s.version = '2.1'
|
||||||
s.summary = 'PNObject is a simple replica of the more complex ParseObject'
|
s.summary = 'PNObject is a simple replica of the more complex ParseObject'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,18 @@
|
|||||||
withBlockSuccess:(nullable void (^)(PNUser * _Nullable responseObject))success
|
withBlockSuccess:(nullable void (^)(PNUser * _Nullable responseObject))success
|
||||||
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <#Description#>
|
||||||
|
*
|
||||||
|
* @param username username description
|
||||||
|
* @param password <#password description#>
|
||||||
|
* @param success <#success description#>
|
||||||
|
* @param failure <#failure description#>
|
||||||
|
*/
|
||||||
|
+ (void) loginCurrentUserWithUsername:(NSString * _Nonnull) username
|
||||||
|
password:(NSString * _Nonnull) password
|
||||||
|
withBlockSuccess:(nullable void (^)(PNUser * _Nullable responseObject))success
|
||||||
|
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <#Description#>
|
* <#Description#>
|
||||||
|
|||||||
@ -390,6 +390,38 @@ static bool isFirstAccess = YES;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void) loginCurrentUserWithUsername:(NSString * _Nonnull) username
|
||||||
|
password:(NSString * _Nonnull) password
|
||||||
|
withBlockSuccess:(nullable void (^)(PNUser * _Nullable responseObject))success
|
||||||
|
failure:(nullable void (^)(NSError * _Nonnull error))failure {
|
||||||
|
|
||||||
|
[[PNObjectConfig sharedInstance] refreshTokenForUserWithUsername:username password:password withBlockSuccess:^(BOOL refreshSuccess) {
|
||||||
|
if (refreshSuccess) {
|
||||||
|
|
||||||
|
PNUser *user = [[self class] new];
|
||||||
|
|
||||||
|
PNObjcPassword *objectPassword = [PNObjcPassword new];
|
||||||
|
[objectPassword setPassword:password];
|
||||||
|
[objectPassword setConfirmPassword:password];
|
||||||
|
|
||||||
|
[user setAuthenticated:YES];
|
||||||
|
[user setUsername:username];
|
||||||
|
[user setPassword:objectPassword];
|
||||||
|
[user saveLocally];
|
||||||
|
[user reloadFormServer];
|
||||||
|
|
||||||
|
USER = user;
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
success(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} failure:failure];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+ (void) uploadAvatar:(UIImage * _Nonnull) avatar
|
+ (void) uploadAvatar:(UIImage * _Nonnull) avatar
|
||||||
Progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
Progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||||
Success:(nullable void (^)(NSDictionary * _Nullable responseObject))success
|
Success:(nullable void (^)(NSDictionary * _Nullable responseObject))success
|
||||||
|
|||||||
@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[[PNObjectConfig sharedInstance] refreshTokenForOauthMode:oauthMode WithBlockSuccess:^(BOOL refreshSuccess) {
|
[[PNObjectConfig sharedInstance] refreshTokenForOauthMode:oauthMode retries:MAX_RETRIES WithBlockSuccess:^(BOOL refreshSuccess) {
|
||||||
|
|
||||||
[self DELETEWithEndpointAction:endPoint
|
[self DELETEWithEndpointAction:endPoint
|
||||||
oauthMode:oauthMode
|
oauthMode:oauthMode
|
||||||
|
|||||||
@ -102,7 +102,7 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[[PNObjectConfig sharedInstance] refreshTokenForOauthMode:oauthMode WithBlockSuccess:^(BOOL refreshSuccess) {
|
[[PNObjectConfig sharedInstance] refreshTokenForOauthMode:oauthMode retries:MAX_RETRIES WithBlockSuccess:^(BOOL refreshSuccess) {
|
||||||
|
|
||||||
return [self GETWithEndpointAction:endPoint
|
return [self GETWithEndpointAction:endPoint
|
||||||
oauthMode:oauthMode
|
oauthMode:oauthMode
|
||||||
|
|||||||
@ -134,6 +134,7 @@
|
|||||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
|
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
|
||||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||||
|
|
||||||
|
|
||||||
if([[PNObjectConfig sharedInstance] setCredentialTokenForOauthMode:oauthMode]){
|
if([[PNObjectConfig sharedInstance] setCredentialTokenForOauthMode:oauthMode]){
|
||||||
|
|
||||||
[[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] endPointUrl] stringByAppendingFormat:@"%@",endPoint]
|
[[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] endPointUrl] stringByAppendingFormat:@"%@",endPoint]
|
||||||
@ -172,7 +173,7 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[[PNObjectConfig sharedInstance] refreshTokenForOauthMode:oauthMode WithBlockSuccess:^(BOOL refreshSuccess) {
|
[[PNObjectConfig sharedInstance] refreshTokenForOauthMode:oauthMode retries:MAX_RETRIES WithBlockSuccess:^(BOOL refreshSuccess) {
|
||||||
|
|
||||||
return [self POSTWithEndpointAction:endPoint oauthMode:oauthMode formData:postFormData parameters:parameters retries:retries-1 progress:uploadProgress success:success failure:failure];
|
return [self POSTWithEndpointAction:endPoint oauthMode:oauthMode formData:postFormData parameters:parameters retries:retries-1 progress:uploadProgress success:success failure:failure];
|
||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
|
|||||||
@ -210,6 +210,11 @@ typedef NS_ENUM(NSInteger, OAuthMode) {
|
|||||||
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;
|
||||||
|
|
||||||
|
|
||||||
|
- (void) refreshTokenForUserWithUsername:(NSString * _Nonnull) username
|
||||||
|
password:(NSString * _Nonnull) password
|
||||||
|
withBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||||
|
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||||
/**
|
/**
|
||||||
* <#Description#>
|
* <#Description#>
|
||||||
*/
|
*/
|
||||||
@ -222,8 +227,9 @@ typedef NS_ENUM(NSInteger, OAuthMode) {
|
|||||||
* <#Description#>
|
* <#Description#>
|
||||||
*/
|
*/
|
||||||
- (void) refreshTokenForOauthMode:(OAuthMode) oauthMode
|
- (void) refreshTokenForOauthMode:(OAuthMode) oauthMode
|
||||||
WithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
retries:(NSUInteger) retries
|
||||||
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
WithBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||||
|
failure:(nullable void (^)(NSError * _Nonnull error))failure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <#Description#>
|
* <#Description#>
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#import <NSDataAES/NSData+AES.h>
|
#import <NSDataAES/NSData+AES.h>
|
||||||
#import <DDDKeychainWrapper/DDDKeychainWrapper.h>
|
#import <DDDKeychainWrapper/DDDKeychainWrapper.h>
|
||||||
#import "HTTPStatusCodes.h"
|
#import "HTTPStatusCodes.h"
|
||||||
|
#import "PNObject+PNObjectConnection.h"
|
||||||
|
|
||||||
NSString * const PNObjectLocalNotificationRefreshTokenClientCredentialSuccess = @"PNObjectLocalNotificationRefreshTokenClientCredentialSuccess";
|
NSString * const PNObjectLocalNotificationRefreshTokenClientCredentialSuccess = @"PNObjectLocalNotificationRefreshTokenClientCredentialSuccess";
|
||||||
NSString * const PNObjectLocalNotificationRefreshTokenClientCredentialFail = @"PNObjectLocalNotificationRefreshTokenClientCredentialFail";
|
NSString * const PNObjectLocalNotificationRefreshTokenClientCredentialFail = @"PNObjectLocalNotificationRefreshTokenClientCredentialFail";
|
||||||
@ -261,10 +262,10 @@ static bool isFirstAccess = YES;
|
|||||||
|
|
||||||
|
|
||||||
if (![currentEnvConfig objectForKey:Client_ID] || ![currentEnvConfig objectForKey:Client_Secret]) {
|
if (![currentEnvConfig objectForKey:Client_ID] || ![currentEnvConfig objectForKey:Client_Secret]) {
|
||||||
_currentUserCredenzialClientID = _currentClientCredenzialClientID;
|
_currentUserCredenzialClientID = _currentClientCredenzialClientID;
|
||||||
_currentUserCredenzialClientSecret = _currentClientCredenzialClientSecret;
|
_currentUserCredenzialClientSecret = _currentClientCredenzialClientSecret;
|
||||||
_currentUserCredenzialEndPointPath = _currentClientCredenzialEndPointPath;
|
_currentUserCredenzialEndPointPath = _currentClientCredenzialEndPointPath;
|
||||||
_currentUserCredenzialEndPointUrl = _currentClientCredenzialEndPointUrl;
|
_currentUserCredenzialEndPointUrl = _currentClientCredenzialEndPointUrl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_currentUserCredenzialClientID = [currentEnvConfig objectForKey:Client_ID];
|
_currentUserCredenzialClientID = [currentEnvConfig objectForKey:Client_ID];
|
||||||
@ -405,10 +406,10 @@ static bool isFirstAccess = YES;
|
|||||||
if (!_userCredentialAuthManager) {
|
if (!_userCredentialAuthManager) {
|
||||||
_userCredentialAuthManager = [AFOAuth2Manager manager];
|
_userCredentialAuthManager = [AFOAuth2Manager manager];
|
||||||
|
|
||||||
if (_currentUserCredenzialClientID && _currentUserCredenzialClientID && _currentOAuthUserName && _currentOAuthPassword) {
|
if ((_currentUserCredenzialClientID && _currentUserCredenzialClientID) || (_currentOAuthUserName && _currentOAuthPassword)) {
|
||||||
|
|
||||||
if (![_userCredentialAuthManager clientID]) {
|
if (![_userCredentialAuthManager clientID]) {
|
||||||
_userCredentialAuthManager = [AFOAuth2Manager managerWithBaseURL:[NSURL URLWithString:_currentClientCredenzialEndPointUrl] clientID:_currentUserCredenzialClientID secret:_currentUserCredenzialClientID];
|
_userCredentialAuthManager = [AFOAuth2Manager managerWithBaseURL:[NSURL URLWithString:_currentClientCredenzialEndPointUrl] clientID:_currentUserCredenzialClientID secret:_currentUserCredenzialClientSecret];
|
||||||
}
|
}
|
||||||
|
|
||||||
[_userCredentialAuthManager setUseHTTPBasicAuthentication:NO];
|
[_userCredentialAuthManager setUseHTTPBasicAuthentication:NO];
|
||||||
@ -499,27 +500,27 @@ 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 {
|
||||||
[self refreshTokenForOauthMode:OAuthModeClientCredential WithBlockSuccess:success failure:failure];
|
[self refreshTokenForOauthMode:OAuthModeClientCredential retries:MAX_RETRIES WithBlockSuccess:success failure:failure];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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 {
|
||||||
|
|
||||||
[self refreshTokenForOauthMode:OAuthModePassword WithBlockSuccess:success failure:failure];
|
[self refreshTokenForOauthMode:OAuthModePassword retries:MAX_RETRIES WithBlockSuccess:success failure:failure];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) refreshTokenForOauthMode:(OAuthMode) oauthMode
|
- (void) refreshTokenForOauthMode:(OAuthMode) oauthMode
|
||||||
|
retries:(NSUInteger) retries
|
||||||
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 {
|
||||||
|
|
||||||
__block __typeof__(_currentOauthClientCredential) __weak wCurrentOauthCredential = _currentOauthClientCredential;
|
__block __typeof__(_currentOauthClientCredential) wCurrentOauthCredential = _currentOauthClientCredential;
|
||||||
|
|
||||||
__block __typeof__(_managerHttpRequestSerializer) __weak wHttpSerializer = _managerHttpRequestSerializer;
|
|
||||||
__block __typeof__(_managerJsonRequestSerializer) __weak wJsonSerializer = _managerJsonRequestSerializer;
|
|
||||||
__block __typeof__(_clientCredentialAuthManager) __weak wClientCredentialAuthManager = _clientCredentialAuthManager;
|
|
||||||
__block __typeof__(_userCredentialAuthManager) __weak wUserCredentialAuthManager = _userCredentialAuthManager;
|
|
||||||
__block __typeof__(_manager) __weak wManager = _manager;
|
|
||||||
|
|
||||||
|
__block __typeof__(_managerHttpRequestSerializer) wHttpSerializer = _managerHttpRequestSerializer;
|
||||||
|
__block __typeof__(_managerJsonRequestSerializer) wJsonSerializer = _managerJsonRequestSerializer;
|
||||||
|
__block __typeof__(_clientCredentialAuthManager) wClientCredentialAuthManager = _clientCredentialAuthManager;
|
||||||
|
__block __typeof__(_userCredentialAuthManager) wUserCredentialAuthManager = _userCredentialAuthManager;
|
||||||
|
__block __typeof__(_manager) wManager = _manager;
|
||||||
|
|
||||||
switch (oauthMode) {
|
switch (oauthMode) {
|
||||||
case OAuthModeClientCredential:
|
case OAuthModeClientCredential:
|
||||||
@ -533,7 +534,6 @@ static bool isFirstAccess = YES;
|
|||||||
[wHttpSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wHttpSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
[wJsonSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wJsonSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
[wClientCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wClientCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
[wUserCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
|
||||||
[wManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
|
||||||
@ -545,7 +545,15 @@ static bool isFirstAccess = YES;
|
|||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
[self resetTokenForOauthMode:oauthMode];
|
[self resetTokenForOauthMode:oauthMode];
|
||||||
|
|
||||||
[self refreshTokenForClientCredentialWithBlockSuccess:success failure:failure];
|
if (retries > 0) {
|
||||||
|
[self refreshTokenForOauthMode:oauthMode retries:retries-1 WithBlockSuccess:success failure:failure];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (failure) {
|
||||||
|
failure(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -557,7 +565,6 @@ static bool isFirstAccess = YES;
|
|||||||
[wHttpSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wHttpSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
[wJsonSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wJsonSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
[wClientCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wClientCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
[wUserCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
|
||||||
[wManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
[wManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
|
||||||
@ -595,8 +602,15 @@ static bool isFirstAccess = YES;
|
|||||||
|
|
||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
[self resetTokenForOauthMode:oauthMode];
|
[self resetTokenForOauthMode:oauthMode];
|
||||||
|
if (retries > 0) {
|
||||||
|
[self refreshTokenForOauthMode:oauthMode retries:retries-1 WithBlockSuccess:success failure:failure];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (failure) {
|
||||||
|
failure(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[self refreshTokenForOauthMode:oauthMode WithBlockSuccess:success failure:failure];
|
|
||||||
return;
|
return;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -630,10 +644,18 @@ static bool isFirstAccess = YES;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (retries > 0) {
|
||||||
[self refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
[self refreshTokenForOauthMode:OAuthModeClientCredential retries:retries-1 WithBlockSuccess:^(BOOL refreshSuccess) {
|
||||||
[self refreshTokenForOauthMode:oauthMode WithBlockSuccess:success failure:failure];
|
[self refreshTokenForOauthMode:oauthMode retries:retries-1 WithBlockSuccess:success failure:failure];
|
||||||
} failure:failure];
|
} failure:failure];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (failure) {
|
||||||
|
NSError *error = [NSError errorWithDomain:@"" code:kHTTPStatusCodeBadRequest userInfo:nil];
|
||||||
|
failure(error);
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
@ -664,12 +686,12 @@ static bool isFirstAccess = YES;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__block __typeof__(_currentOauthUserCredential) __weak wCurrentOauthCredential = _currentOauthUserCredential;
|
__block __typeof__(_currentOauthUserCredential) wCurrentOauthCredential = _currentOauthUserCredential;
|
||||||
|
|
||||||
__block __typeof__(_managerHttpRequestSerializer) __weak wHttpSerializer = _managerHttpRequestSerializer;
|
__block __typeof__(_managerHttpRequestSerializer) wHttpSerializer = _managerHttpRequestSerializer;
|
||||||
__block __typeof__(_managerJsonRequestSerializer) __weak wJsonSerializer = _managerJsonRequestSerializer;
|
__block __typeof__(_managerJsonRequestSerializer) wJsonSerializer = _managerJsonRequestSerializer;
|
||||||
__block __typeof__(_manager) __weak wManager = _manager;
|
__block __typeof__(_manager) wManager = _manager;
|
||||||
__block __typeof__(_userCredentialAuthManager) __weak wUserCredentialAuthManager = _userCredentialAuthManager;
|
__block __typeof__(_userCredentialAuthManager) wUserCredentialAuthManager = _userCredentialAuthManager;
|
||||||
|
|
||||||
[_userCredentialAuthManager authenticateUsingFacebookOAuthWithURLString:_currentClientCredenzialEndPointUrl facebookId:facebookId facebookToken:facebookToken scope:@"" success:^(AFOAuthCredential * _Nonnull credential) {
|
[_userCredentialAuthManager authenticateUsingFacebookOAuthWithURLString:_currentClientCredenzialEndPointUrl facebookId:facebookId facebookToken:facebookToken scope:@"" success:^(AFOAuthCredential * _Nonnull credential) {
|
||||||
wCurrentOauthCredential = credential;
|
wCurrentOauthCredential = credential;
|
||||||
@ -714,12 +736,12 @@ static bool isFirstAccess = YES;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__block __typeof__(_currentOauthUserCredential) __weak wCurrentOauthCredential = _currentOauthUserCredential;
|
__block __typeof__(_currentOauthUserCredential) wCurrentOauthCredential = _currentOauthUserCredential;
|
||||||
|
|
||||||
__block __typeof__(_managerHttpRequestSerializer) __weak wHttpSerializer = _managerHttpRequestSerializer;
|
__block __typeof__(_managerHttpRequestSerializer) wHttpSerializer = _managerHttpRequestSerializer;
|
||||||
__block __typeof__(_managerJsonRequestSerializer) __weak wJsonSerializer = _managerJsonRequestSerializer;
|
__block __typeof__(_managerJsonRequestSerializer) wJsonSerializer = _managerJsonRequestSerializer;
|
||||||
__block __typeof__(_manager) __weak wManager = _manager;
|
__block __typeof__(_manager) wManager = _manager;
|
||||||
__block __typeof__(_userCredentialAuthManager) __weak wUserCredentialAuthManager = _userCredentialAuthManager;
|
__block __typeof__(_userCredentialAuthManager) wUserCredentialAuthManager = _userCredentialAuthManager;
|
||||||
|
|
||||||
|
|
||||||
[_userCredentialAuthManager authenticateUsingOAuthWithURLString:_currentClientCredenzialEndPointUrl username:email password:password scope:@"" success:^(AFOAuthCredential * _Nonnull credential) {
|
[_userCredentialAuthManager authenticateUsingOAuthWithURLString:_currentClientCredenzialEndPointUrl username:email password:password scope:@"" success:^(AFOAuthCredential * _Nonnull credential) {
|
||||||
@ -746,6 +768,51 @@ static bool isFirstAccess = YES;
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) refreshTokenForUserWithUsername:(NSString * _Nonnull) username
|
||||||
|
password:(NSString * _Nonnull) password
|
||||||
|
withBlockSuccess:(nullable void (^)(BOOL refreshSuccess))success
|
||||||
|
failure:(nullable void (^)(NSError * _Nonnull error))failure {
|
||||||
|
|
||||||
|
if (![SINGLETON_PNObjectConfig.userSubClass isValidPassword:password]) {
|
||||||
|
if (failure) {
|
||||||
|
NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Password is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
|
||||||
|
failure(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__block __typeof__(_currentOauthUserCredential) wCurrentOauthCredential = _currentOauthUserCredential;
|
||||||
|
|
||||||
|
__block __typeof__(_managerHttpRequestSerializer) wHttpSerializer = _managerHttpRequestSerializer;
|
||||||
|
__block __typeof__(_managerJsonRequestSerializer) wJsonSerializer = _managerJsonRequestSerializer;
|
||||||
|
__block __typeof__(_manager) wManager = _manager;
|
||||||
|
__block __typeof__(_userCredentialAuthManager) wUserCredentialAuthManager = _userCredentialAuthManager;
|
||||||
|
|
||||||
|
|
||||||
|
[_userCredentialAuthManager authenticateUsingOAuthWithURLString:_currentClientCredenzialEndPointUrl username:username password:password scope:@"" success:^(AFOAuthCredential * _Nonnull credential) {
|
||||||
|
wCurrentOauthCredential = credential;
|
||||||
|
|
||||||
|
[AFOAuthCredential storeCredential:wCurrentOauthCredential withIdentifier:PNObjectServiceUserCredentialIdentifier];
|
||||||
|
|
||||||
|
[wHttpSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
|
[wJsonSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
|
[wUserCredentialAuthManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
|
[wManager.requestSerializer setAuthorizationHeaderFieldWithCredential:wCurrentOauthCredential];
|
||||||
|
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserSuccess object:nil];
|
||||||
|
if (success) {
|
||||||
|
success(YES);
|
||||||
|
}
|
||||||
|
} failure:^(NSError * _Nonnull error) {
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
|
||||||
|
if (failure) {
|
||||||
|
failure(error);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght {
|
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght {
|
||||||
_minPasswordLenght = passLenght;
|
_minPasswordLenght = passLenght;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user