Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[token refresh] Compatibility with python “idan/oauthlib” #167

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replaced assert with NSError
  • Loading branch information
Aleksandr Dodatko committed Apr 8, 2015
commit 57169da15c0e9bc35dfe35614b38836a48a7af01
25 changes: 22 additions & 3 deletions Sources/OAuth2Client/NXOAuth2Client.m
Original file line number Diff line number Diff line change
@@ -185,7 +185,11 @@ - (NXOAuth2AccessToken *)accessToken;

- (void)setAccessToken:(NXOAuth2AccessToken *)value;
{
if (self.accessToken == value) return;
if (self.accessToken == value)
{
return;
}

BOOL authorisationStatusChanged = ((accessToken == nil) || (value == nil)); //They can't both be nil, see one line above. So they have to have changed from or to nil.

if (!value) {
@@ -470,8 +474,23 @@ - (void)refreshAccessTokenAndRetryConnection:(NXOAuth2Connection *)retryConnecti
if (!waitingConnections) waitingConnections = [[NSMutableArray alloc] init];
[waitingConnections addObject:retryConnection];
}
if (!authConnection) {
NSAssert((accessToken.refreshToken != nil), @"invalid state");
if (!authConnection)
{
if (nil == accessToken.refreshToken)
{
if ([delegate respondsToSelector:@selector(oauthClient:didFailToGetAccessTokenWithError:)])
{
NSError* noTokenError = [NSError errorWithDomain: NXOAuth2ErrorDomain
code: NXOAuth2CouldNotRefreshTokenErrorCode
userInfo: nil];

[delegate oauthClient: self didFailToGetAccessTokenWithError: noTokenError];
}

return;
}


NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
[tokenRequest setHTTPMethod:self.tokenRequestHTTPMethod];
[authConnection cancel]; // not needed, but looks more clean to me :)