Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Support custom authentication UI #23

wants to merge 1 commit into from

2 participants


The default auth UI in a dedicated window is a nice shortcut, however sometimes it might be desirable to integrated WebView into another window.

This patch adds a new optional method to PhFacebookDelegate:
```- (BOOL) needAuth:(NSString*)authURL forPermissions:(NSString *)permissions;

If this method is implemented and returns true, PhFacebook will not display authentication window, instead it will rely on delegate to display appropriate URLs to user and perform necessary callbacks similarly to PhWebViewController.

As a bonus also added invalidateCachedToken which removes cached tokens from user defaults.
@k7d k7d referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.

Yeah, there are so many different formatting styles for Objective-C that it's easy to slip...

Anyways, check the new commit 455ba44c1ea33aa2eb63, this should be better. You can discard the original commit as this one is on different branch.

@k7d k7d closed this
@k7d k7d reopened this

Sorry didn't mean to close it... probably it's too early in the morning and coffee hasn't kicked in yet :)

@philippec philippec referenced this pull request from a commit
@k7d k7d #23: new delegate method needAuthentication to allow custom auth UI +…
… invalidateCachedToken method (fixed formating & stuff)

Thanks! I have pulled your latest patch. I took the liberty of rewording the comments, and I also named the parameter "authenticationURL" to make it clearer than "authURL" since it is now a public header. So you will want to rebase your sources.


@philippec philippec closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 13, 2011
  1. @k7d
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 6 deletions.
  1. +10 −5 classes/PhFacebook.h
  2. +17 −1 classes/PhFacebook.m
15 classes/PhFacebook.h
@@ -14,11 +14,11 @@
@interface PhFacebook : NSObject
- 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;
@@ -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;
@@ -49,6 +50,10 @@
- (void) requestResult: (NSDictionary*) result;
+// 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;
18 classes/PhFacebook.m
@@ -78,6 +78,15 @@ - (void) clearToken
_authToken = nil;
+ [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];
@@ -125,7 +134,14 @@ - (void) getAccessTokenForPermissions: (NSArray*) permissions cached: (BOOL) can
authURL = [NSString stringWithFormat: kFBAuthorizeWithScopeURL, _appID, kFBLoginSuccessURL, scope];
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)
Something went wrong with that request. Please try again.