tags:

views:

109

answers:

2

I've got an SFAuthoizationView I'm using in my app and I'm trying to call the authorize method from my code to prompt the user to authorize if they currently are not authorized.

My issue is that this method does not seem to work!

My code is as follows, where authView is the SFAuthorizationView and authorizeMe is the method that gets called when a button is clicked (and the log message does show, so I know it's getting called).

If the lock is locked the authorize message just returns false and does not seem to prompt the user for a password.

Does anybody know what's up with this?

- (void) mainViewDidLoad {
    [authView setDelegate:self];
    [authView setString:"Test String"];
    [authView setAutoupdate:YES];
}

- (IBAction)authorizeMe:(id)sender {
  NSLog(@"Authorizing...");
  [authView authorize:authView];
}

- (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view {
    self.enabled = YES;
}

- (void)authorizationViewDidDeauthorize:(SFAuthorizationView *)view {
    self.enabled = NO;
}
+1  A: 

I'm guessing @"Test String" is not the name of an authorization right you've registered with the system. The authorization view needs to know what right you're requesting. This document provides an overview about how to do that.

Alex
But then why would it work to manually click on the lock icon and authorize to unlock the pane but not to authorize via code?
Lawrence Johnston
+1  A: 

I had this same problem and I've noticed a few things.

In order for the SFAuthorizationView authorize method to interact with the user you MUST set BOTH of these flags when initializing the SFAuthorizationView:

AuthorizationFlags flags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights; [m_authView setFlags:flags];

However, I don't think the SFAuthorizationView was designed to be used this way.

After setting these flags calls to [m_authView updateStatus:m_authView]; cause the user to be prompted for Admin credentials, and if you set [m_authView setAutoupdate:YES]; the user will be randomly prompted for a password and the prompt will not go away when the user click cancel!

I believe the SFAuthorizationView authorize method suppresses user interaction on purpose.

It seems as though there is another method you can call instead of authorize: (void)buttonPressed:(id)sender. This method isn't documented and it will generate compilation warnings, but it does work on 10.6.

Mr. T
One thing to note is that if you just need to check to see if the user is authorized (not actually unlock the lock) you can use `AuthorizationCopyRights([[authorizationView authorization] authorizationRef], [authorizationView authorizationRights], kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults | kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed, NULL)` which will prompt the user if needed.
Lawrence Johnston