Skip to content

Commit

Permalink
Bucketizes the permissions developer model by read and publish
Browse files Browse the repository at this point in the history
Summary:
This change establishes the developer model that supports the direction of
dissallowing permission requests to users that present both read and publish
permissions in a single request gesture. The specific changes are:
* Adds read and publish versions of permissions properties to certain controls
* Adds read and publish versions of open and reauthorize methods on FBSession
* Deprecates methods and properties that take unspecified collections of permissions
* Updates samples

Note - in order to unblock docs work, we are pushing this with a known build break in
one of the samples. Will fix the sample shortly.

Test Plan: Tested impacted scenarios via samples

Reviewers: clang, mmarucheck, gregschechte

Reviewed By: mmarucheck

CC: chrisp, ekoneil

Differential Revision: https://phabricator.fb.com/D580068

Task ID: 1731992
  • Loading branch information
onebit committed Sep 20, 2012
1 parent 644a659 commit 0bbc178
Show file tree
Hide file tree
Showing 16 changed files with 596 additions and 123 deletions.
4 changes: 1 addition & 3 deletions samples/BooleanOGSample/BooleanOGSample/BOGAppDelegate.m
Expand Up @@ -61,9 +61,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
viewControllerSettings = [[FBUserSettingsViewController alloc] init];
viewControllerSettings.title = @"Facebook Settings";
viewControllerSettings.tabBarItem.image = [UIImage imageNamed:@"second"];
viewControllerSettings.permissions = nil;

viewControllerSettings.tabBarItem.image = [UIImage imageNamed:@"second"];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewControllerMe, viewControllerFriends, viewControllerSettings, nil];
Expand Down
23 changes: 11 additions & 12 deletions samples/BooleanOGSample/BooleanOGSample/BOGFirstViewController.m
Expand Up @@ -148,18 +148,17 @@ - (void)postAction:(NSString *)actionPath
// if we don't have permission to post, let's first address that
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {

[FBSession.activeSession reauthorizeWithPermissions:[NSArray arrayWithObject:@"publish_actions"]
behavior:FBSessionLoginBehaviorWithFallbackToWebView
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call assuming we now have the permission
[self postAction:actionPath
leftOperand:left
rightOperand:right
result:result];
}
}];
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call assuming we now have the permission
[self postAction:actionPath
leftOperand:left
rightOperand:right
result:result];
}
}];
} else {

// create an object to hold our action information, the FBGraphObject class has a lightweight
Expand Down
Expand Up @@ -26,8 +26,6 @@ @interface FPViewController ()
@property (strong, nonatomic) IBOutlet UITextView *selectedFriendsView;
@property (retain, nonatomic) FBFriendPickerViewController *friendPickerController;

- (void)doneButtonWasPressed:(id)sender;
- (void)cancelButtonWasPressed:(id)sender;
- (void)fillTextBoxAndDismiss:(NSString *)text;

@end
Expand Down
10 changes: 8 additions & 2 deletions samples/Hackbook/Hackbook.xcodeproj/project.pbxproj
Expand Up @@ -25,6 +25,8 @@
30EA739F13F5D372003DC0D2 /* MenuButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 30EA739713F5D372003DC0D2 /* MenuButton.png */; };
30EA73FC13F5D590003DC0D2 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30EA73FB13F5D590003DC0D2 /* CoreLocation.framework */; };
30ED588C14358F8A00A226C3 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 30ED588B14358F8A00A226C3 /* Default@2x.png */; };
84750AA0160A259400C1A13D /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84750A9F160A259400C1A13D /* Accounts.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
84750AA3160A259E00C1A13D /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84750AA2160A259E00C1A13D /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
85AFB4E4158F9C5B000AF7F5 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 85AFB4E0158F9C5B000AF7F5 /* Icon-72.png */; };
85AFB4E5158F9C5B000AF7F5 /* Icon-72@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 85AFB4E1158F9C5B000AF7F5 /* Icon-72@2x.png */; };
85AFB4E6158F9C5B000AF7F5 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 85AFB4E2158F9C5B000AF7F5 /* Icon.png */; };
Expand Down Expand Up @@ -61,6 +63,8 @@
30EA739713F5D372003DC0D2 /* MenuButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MenuButton.png; sourceTree = "<group>"; };
30EA73FB13F5D590003DC0D2 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
30ED588B14358F8A00A226C3 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; };
84750A9F160A259400C1A13D /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
84750AA2160A259E00C1A13D /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
85AFB4E0158F9C5B000AF7F5 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = "<group>"; };
85AFB4E1158F9C5B000AF7F5 /* Icon-72@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72@2x.png"; sourceTree = "<group>"; };
85AFB4E2158F9C5B000AF7F5 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -95,7 +99,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2A84F0C4160306F3002CB8BD /* AdSupport.framework in Frameworks */,
84750AA3160A259E00C1A13D /* AdSupport.framework in Frameworks */,
84750AA0160A259400C1A13D /* Accounts.framework in Frameworks */,
30EA73FC13F5D590003DC0D2 /* CoreLocation.framework in Frameworks */,
30EA735E13F5D21B003DC0D2 /* UIKit.framework in Frameworks */,
30EA736013F5D21B003DC0D2 /* Foundation.framework in Frameworks */,
Expand Down Expand Up @@ -136,7 +141,8 @@
30EA735C13F5D21B003DC0D2 /* Frameworks */ = {
isa = PBXGroup;
children = (
2A84F0C3160306F3002CB8BD /* AdSupport.framework */,
84750AA2160A259E00C1A13D /* AdSupport.framework */,
84750A9F160A259400C1A13D /* Accounts.framework */,
DD37EA8E15ABA4920015966B /* FacebookSDK.framework */,
30EA73FB13F5D590003DC0D2 /* CoreLocation.framework */,
30EA735D13F5D21B003DC0D2 /* UIKit.framework */,
Expand Down
26 changes: 26 additions & 0 deletions samples/HelloFacebookSample/HelloFacebookSample/HFViewController.m
Expand Up @@ -127,6 +127,7 @@ - (void) performPublishAction:(void (^)(void)) action {
// we defer request for permission to post to the moment of post, then we check for the permission
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
// if we don't already have the permission, then we request it now
<<<<<<< HEAD
[FBSession.activeSession reauthorizeWithPermissions:[NSArray arrayWithObject:@"publish_actions"]
behavior:FBSessionLoginBehaviorWithFallbackToWebView
defaultAudience:FBSessionDefaultAudienceFriends
Expand All @@ -136,6 +137,16 @@ - (void) performPublishAction:(void (^)(void)) action {
}
//For this example, ignore errors (such as if user cancels).
}];
=======
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call ourselves assuming we now have the necessary permission
[self postStatusUpdateClick:sender];
}
}];
>>>>>>> Bucketizes the permissions developer model by read and publish
} else {
action();
}
Expand Down Expand Up @@ -163,7 +174,22 @@ - (IBAction)postStatusUpdateClick:(UIButton *)sender {

// Post Photo button handler
- (IBAction)postPhotoClick:(UIButton *)sender {
<<<<<<< HEAD
[self performPublishAction:^{
=======
// we defer request for permission to post to the moment of post, then we check for the permission
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
// if we don't already have the permission, then we request it now
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call ourselves assuming we now have the necessary permission
[self postPhotoClick:sender];
}
}];
} else {
>>>>>>> Bucketizes the permissions developer model by read and publish
// Just use the icon image from the application itself. A real app would have a more
// useful way to get an image.
UIImage *img = [UIImage imageNamed:@"Icon-72@2x.png"];
Expand Down
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
2A84F0CD16030711002CB8BD /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A84F0CC16030711002CB8BD /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
847BBEAA160B88E8004EC7CB /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 847BBEA9160B88E8004EC7CB /* Accounts.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
85AFB522158FA1C4000AF7F5 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 85AFB51E158FA1C4000AF7F5 /* Icon-72.png */; };
85AFB523158FA1C4000AF7F5 /* Icon-72@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 85AFB51F158FA1C4000AF7F5 /* Icon-72@2x.png */; };
85AFB524158FA1C4000AF7F5 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 85AFB520158FA1C4000AF7F5 /* Icon.png */; };
Expand All @@ -30,6 +31,7 @@

/* Begin PBXFileReference section */
2A84F0CC16030711002CB8BD /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
847BBEA9160B88E8004EC7CB /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
85AFB51E158FA1C4000AF7F5 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = "<group>"; };
85AFB51F158FA1C4000AF7F5 /* Icon-72@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72@2x.png"; sourceTree = "<group>"; };
85AFB520158FA1C4000AF7F5 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -60,6 +62,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
847BBEAA160B88E8004EC7CB /* Accounts.framework in Frameworks */,
2A84F0CD16030711002CB8BD /* AdSupport.framework in Frameworks */,
B98686BD151D0B3700616412 /* UIKit.framework in Frameworks */,
B98686BF151D0B3700616412 /* Foundation.framework in Frameworks */,
Expand All @@ -74,6 +77,7 @@
B98686AD151D0B3700616412 = {
isa = PBXGroup;
children = (
847BBEA9160B88E8004EC7CB /* Accounts.framework */,
B98686C2151D0B3700616412 /* ProfilePictureSample */,
B98686BB151D0B3700616412 /* Frameworks */,
B98686B9151D0B3700616412 /* Products */,
Expand Down
17 changes: 8 additions & 9 deletions samples/Scrumptious/scrumptious/SCViewController.m
Expand Up @@ -222,15 +222,14 @@ - (IBAction)announce:(id)sender {
// if we don't have permission to announce, let's first address that
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {

[FBSession.activeSession reauthorizeWithPermissions:[NSArray arrayWithObject:@"publish_actions"]
behavior:FBSessionLoginBehaviorWithFallbackToWebView
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call assuming we now have the permission
[self announce:sender];
}
}];
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call assuming we now have the permission
[self announce:sender];
}
}];
} else {
self.announceButton.enabled = false;
[self centerAndShowActivityIndicator];
Expand Down
2 changes: 1 addition & 1 deletion samples/SwitchUserSample/SwitchUserSample/SUUserManager.m
Expand Up @@ -91,7 +91,7 @@ - (FBSession*)createSessionForSlot:(int)slot {
// create a session object, with defaults accross the board, except that we provide a custom
// instance of FBSessionTokenCachingStrategy
FBSession *session = [[FBSession alloc] initWithAppID:nil
readPermissions:nil
permissions:nil
urlSchemeSuffix:nil
tokenCacheStrategy:tokenCachingStrategy];
return session;
Expand Down
65 changes: 62 additions & 3 deletions src/FBLoginView.h
Expand Up @@ -15,6 +15,7 @@
*/

#import <UIKit/UIKit.h>
#import "FBSession.h"
#import "FBGraphUser.h"

@protocol FBLoginViewDelegate;
Expand All @@ -27,10 +28,38 @@

/*!
@abstract
The permissions to login with. Defaults to nil, meaning basic permissions.@property (readwrite, copy) NSArray *permissions;
The permissions to login with. Defaults to nil, meaning basic permissions.
@discussion Methods and properties that specify permissions without a read or publish
qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred.
*/
@property (readwrite, copy) NSArray *permissions __attribute__((deprecated));

/*!
@abstract
The read permissions to request if the user logs in via this view.
@discussion
Note, that if read permissions are specified, then publish permissions should not be specified.
*/
@property (readwrite, copy) NSArray *permissions;
@property (nonatomic, copy) NSArray *readPermissions;

/*!
@abstract
The publish permissions to request if the user logs in via this view.
@discussion
Note, that a defaultAudience value of FBSessionDefaultAudienceOnlyMe, FBSessionDefaultAudienceEveryone, or
FBSessionDefaultAudienceFriends should be set if publish permissions are specified. Additionally, when publish
permissions are specified, then read should not be specified.
*/
@property (nonatomic, copy) NSArray *publishPermissions;

/*!
@abstract
The default audience to use, if publish permissions are requested at login time.
*/
@property (nonatomic, assign) FBSessionDefaultAudience defaultAudience;


/*!
Expand All @@ -48,8 +77,38 @@
@param permissions An array of strings representing the permissions to request during the
authentication flow. A value of nil will indicates basic permissions.
@discussion Methods and properties that specify permissions without a read or publish
qualification are deprecated; use of a read-qualified or publish-qualified alternative is preferred.
*/
- (id)initWithPermissions:(NSArray *)permissions __attribute__((deprecated));

/*!
@method
@abstract
Initializes and returns an `FBLoginView` object constructed with the specified permissions.
@param readPermissions An array of strings representing the read permissions to request during the
authentication flow. A value of nil will indicates basic permissions.
*/
- (id)initWithReadPermissions:(NSArray *)readPermissions;

/*!
@method
@abstract
Initializes and returns an `FBLoginView` object constructed with the specified permissions.
@param publishPermissions An array of strings representing the publish permissions to request during the
authentication flow.
@param defaultAudience An audience for published posts; note that FBSessionDefaultAudienceNone is not valid
for permission requests that include publish or manage permissions.
*/
- (id)initWithPermissions:(NSArray *)permissions;
- (id)initWithPublishPermissions:(NSArray *)publishPermissions
defaultAudience:(FBSessionDefaultAudience)defaultAudience;

/*!
@abstract
Expand Down

0 comments on commit 0bbc178

Please sign in to comment.