- Fix Token reset
This commit is contained in:
parent
878dbdf274
commit
f26b694a14
@ -151,7 +151,7 @@ static bool isFirstAccess = YES;
|
|||||||
|
|
||||||
[[[self class] currentUser] populateObjectFromJSON:[responseObject objectForKey:@"user"]];
|
[[[self class] currentUser] populateObjectFromJSON:[responseObject objectForKey:@"user"]];
|
||||||
[[[self class] currentUser] saveLocally];
|
[[[self class] currentUser] saveLocally];
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationUserReloadFromServerSuccess object:[[self class] currentUser]];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationUserReloadFromServerSuccess object:nil];
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
success([[self class] currentUser]);
|
success([[self class] currentUser]);
|
||||||
|
|||||||
@ -295,6 +295,8 @@ static bool isFirstAccess = YES;
|
|||||||
|
|
||||||
- (BOOL) resetToken {
|
- (BOOL) resetToken {
|
||||||
if (_currentOauthCredential) {
|
if (_currentOauthCredential) {
|
||||||
|
_currentOauthCredential = nil;
|
||||||
|
|
||||||
return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
return [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
@ -323,20 +325,22 @@ 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:PNObjectServiceCredentialIdentifier];
|
||||||
|
|
||||||
[_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];
|
||||||
if (success) {
|
if (success) {
|
||||||
success(YES);
|
success(YES);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
[AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
[self resetToken];
|
||||||
|
|
||||||
[self refreshTokenForUserWithBlockSuccess:success failure:failure];
|
[self refreshTokenForUserWithBlockSuccess:success failure:failure];
|
||||||
return;
|
return;
|
||||||
@ -357,7 +361,7 @@ static bool isFirstAccess = YES;
|
|||||||
|
|
||||||
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:error];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -385,6 +389,7 @@ 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:PNObjectServiceCredentialIdentifier];
|
||||||
|
|
||||||
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_httpSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
@ -392,12 +397,13 @@ static bool isFirstAccess = YES;
|
|||||||
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
|
|
||||||
|
[[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:error];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
|
||||||
if (failure) {
|
if (failure) {
|
||||||
failure(error);
|
failure(error);
|
||||||
}
|
}
|
||||||
@ -432,12 +438,13 @@ static bool isFirstAccess = YES;
|
|||||||
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
|
|
||||||
|
[[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:error];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:nil];
|
||||||
if (failure) {
|
if (failure) {
|
||||||
failure(error);
|
failure(error);
|
||||||
}
|
}
|
||||||
@ -464,13 +471,14 @@ static bool isFirstAccess = YES;
|
|||||||
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
|
||||||
if (success) {
|
if (success) {
|
||||||
success(YES);
|
success(YES);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
[AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
|
[self resetToken];
|
||||||
|
|
||||||
[self refreshTokenForClientCredentialWithBlockSuccess:success failure:failure];
|
[self refreshTokenForClientCredentialWithBlockSuccess:success failure:failure];
|
||||||
return;
|
return;
|
||||||
@ -487,11 +495,13 @@ static bool isFirstAccess = YES;
|
|||||||
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_authManager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialSuccess object:nil];
|
||||||
if (success) {
|
if (success) {
|
||||||
success(YES);
|
success(YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
} failure:^(NSError * _Nonnull error) {
|
} failure:^(NSError * _Nonnull error) {
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialFail object:error];
|
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenClientCredentialFail object:nil];
|
||||||
if (failure) {
|
if (failure) {
|
||||||
failure(error);
|
failure(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user