Navigation Menu

Skip to content

Commit

Permalink
new delegate method needAuth to allow custom auth UI + invalidateCach…
Browse files Browse the repository at this point in the history
…edToken method
  • Loading branch information
Kaspars Dancis committed Jul 13, 2011
1 parent 94a5e20 commit d8a4be4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 10 additions & 5 deletions classes/PhFacebook.h
Expand Up @@ -14,11 +14,11 @@
@interface PhFacebook : NSObject
{
@private
NSString *_appID;
id _delegate;
PhWebViewController *_webViewController;
PhAuthenticationToken *_authToken;
NSString *_permissions;
NSString *_appID;
id _delegate;
PhWebViewController *_webViewController;
PhAuthenticationToken *_authToken;
NSString *_permissions;
}

- (id) initWithApplicationID: (NSString*) appID delegate: (id) delegate;
Expand All @@ -33,6 +33,7 @@
- (void) sendRequest: (NSString*) request;
- (void) sendRequest: (NSString*) request params: (NSDictionary*) params usePostRequest: (BOOL) postRequest;

- (void) invalidateCachedToken;

- (void) setAccessToken: (NSString*) accessToken expires: (NSTimeInterval) tokenExpires permissions: (NSString*) perms error: (NSString*) errorReason;
- (NSString*) accessToken;
Expand All @@ -49,6 +50,10 @@
- (void) requestResult: (NSDictionary*) result;

@optional
// needAuth is called before showing authentication WebView
// if it returns true, default login window will not be shown and
// application is responsible for authentication UI
- (BOOL) needAuth:(NSString*)authURL forPermissions:(NSString *)permissions;
- (void) willShowUINotification: (PhFacebook*) sender;
- (void) didDismissUI: (PhFacebook*) sender;

Expand Down
18 changes: 17 additions & 1 deletion classes/PhFacebook.m
Expand Up @@ -78,6 +78,15 @@ - (void) clearToken
_authToken = nil;
}

-(void)invalidateCachedToken
{
[self clearToken];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:kFBStoreAccessToken];
[defaults removeObjectForKey: kFBStoreTokenExpiry];
[defaults removeObjectForKey: kFBStoreAccessPermissions];
}

- (void) setAccessToken: (NSString*) accessToken expires: (NSTimeInterval) tokenExpires permissions: (NSString*) perms
{
[self clearToken];
Expand Down Expand Up @@ -125,7 +134,14 @@ - (void) getAccessTokenForPermissions: (NSArray*) permissions cached: (BOOL) can
authURL = [NSString stringWithFormat: kFBAuthorizeWithScopeURL, _appID, kFBLoginSuccessURL, scope];
else
authURL = [NSString stringWithFormat: kFBAuthorizeURL, _appID, kFBLoginSuccessURL];


if ([_delegate respondsToSelector: @selector(tokenResult:)]) {
if ([_delegate needAuth:authURL forPermissions:scope]) {
// if needAuth returns true, we will let delegate handle the auth UI
return;
}
}

// Retrieve token from web page
if (_webViewController == nil)
{
Expand Down

0 comments on commit d8a4be4

Please sign in to comment.