Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added ability to set request/access tokens before calling resumeSessi…

…on and not rely entirely on stored tokens
  • Loading branch information...
commit 50d40756a4ff58cc063292aa056d153ff163852c 1 parent 4791945
Zach Graves zachgraves authored
Showing with 22 additions and 10 deletions.
  1. +22 −10 Source/YOSSocial/YOSSession.m
32 Source/YOSSocial/YOSSession.m
View
@@ -81,13 +81,21 @@ - (BOOL)resumeSession
{
YOSAuthRequest *tokenAuthRequest = [YOSAuthRequest requestWithSession:self];
- if([self.tokenStore hasRequestToken]) {
- YOSRequestToken *storedRequestToken = [self.tokenStore requestToken];
+ if([tokenStore hasRequestToken] && self.requestToken == nil) {
+ [self setRequestToken:[tokenStore requestToken]];
+ } else if ([tokenStore hasAccessToken] && self.accessToken == nil) {
+ [self setAccessToken:[tokenStore accessToken]];
+ }
+
+ if(self.requestToken) {
+ if(![requestToken key] || ![requestToken secret]) {
+ return FALSE;
+ }
// check if the request token has expired.
// if expired, return FALSE as there is no session to resume.
- if([storedRequestToken tokenHasExpired]) {
- // NSLog(@"Request token (%@) has expired.", storedRequestToken.key);
+ if([self.requestToken tokenHasExpired]) {
+ // NSLog(@"Request token (%@) has expired.", self.requestToken.key);
return FALSE;
}
@@ -97,7 +105,7 @@ - (BOOL)resumeSession
}
// exchange the request token for an access token.
- YOSAccessToken *newAccessToken = [tokenAuthRequest fetchAccessToken:storedRequestToken withVerifier:self.verifier];
+ YOSAccessToken *newAccessToken = [tokenAuthRequest fetchAccessToken:self.requestToken withVerifier:self.verifier];
// check for the presence of a key and secret,
// if missing the session is invalid, most likely
@@ -112,16 +120,20 @@ - (BOOL)resumeSession
// session is ready
return TRUE;
}
- } else if([self.tokenStore hasAccessToken]) {
- YOSAccessToken *storedAccessToken = [self.tokenStore accessToken];
- [self setAccessToken:storedAccessToken];
+ } else if(self.accessToken) {
+ if(![accessToken key] || ![accessToken secret]) {
+ return FALSE;
+ }
+
+ //YOSAccessToken *storedAccessToken = [self.tokenStore accessToken];
+ //[self setAccessToken:storedAccessToken];
// check if the access token has expired
// if expired we can try to renew it.
- if([storedAccessToken tokenHasExpired]) {
+ if([self.accessToken tokenHasExpired]) {
// NSLog(@"Access token (%@) has expired.", storedAccessToken.key);
- YOSAccessToken *refreshedAccessToken = [tokenAuthRequest fetchAccessToken:storedAccessToken withVerifier:nil];
+ YOSAccessToken *refreshedAccessToken = [tokenAuthRequest fetchAccessToken:self.accessToken withVerifier:nil];
// check for the presence of a key and secret
// if missing the session is invalid, likely because the
Please sign in to comment.
Something went wrong with that request. Please try again.