• JoshuaDavies
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I'm relatively new to both iOS and OAuth, but I've combed through the available documentation to try to figure this out, and I still can't get it to work properly.  I'm using the SalesforceMobileSDK-iOS.  When I create a new Mobile-SDK-based-application using the provided project template, the default login implementation is:

 

- (void)login {

SFOAuthCredentials *credentials = [[[SFOAuthCredentialsalloc] initWithIdentifier:remoteAccessConsumerKey] autorelease];

credentials.protocol = @"https";

credentials.domain = OAuthLoginDomain;

credentials.redirectUri = OAuthRedirectURI;

 

self.coordinator = [[[SFOAuthCoordinator alloc] initWithCredentials:credentials] autorelease];

self.coordinator.delegate = self;

                

// remove this line if we want to cache the key, and use refresh flow

//effectively, we are saying, purge the old login and re-authenticate each time

[self.coordinator revokeAuthentication];

 

//now let's authenticate

[self.coordinatorauthenticate];

}

 

My interest is in this line:

 

// remove this line if we want to cache the key, and use refresh flow

//effectively, we are saying, purge the old login and re-authenticate each time

[self.coordinator revokeAuthentication];

 

I _do_ want to cache the key and use the refresh flow so that my user isn't forced to re-login every time they bring up the app.  However, when I remove this line, I'm still prompted for a login each time I bring up the app (even if I switch away from it and come right back).

 

I've also tried caching the refreshToken in "oauthCoordinatorDidAuthenticate":

 

- (void)oauthCoordinatorDidAuthenticate:(SFOAuthCoordinator *)coordinator {

    [self.window.rootViewController.viewremoveFromSuperview];

    

    NSUserDefaults *defaults = [ NSUserDefaultsstandardUserDefaults ];

    // Save the access token in the preferens and try to use it to refresh the token on next launch rather

    // than display a login screen.

    [ defaults setObject:coordinator.credentials.refreshToken forKey:@"refreshToken" ];

 ...

 

and setting the same refreshToken in "applicationDidBecomeActive":

 

- (void)applicationDidBecomeActive:(UIApplication *)application

{

    NSUserDefaults *defaults = [ NSUserDefaultsstandardUserDefaults ];

    

    SFOAuthCredentials *credentials = [[[SFOAuthCredentialsalloc] initWithIdentifier:remoteAccessConsumerKey] autorelease];

    credentials.protocol = @"https";

    credentials.domain = OAuthLoginDomain;

    credentials.redirectUri = OAuthRedirectURI;

    

    //now let's authenticate

    NSString *refreshToken = [ defaults stringForKey:@"refreshToken" ];

    

    if ( refreshToken != nil )

    {

        credentials.refreshToken = refreshToken;

        self.coordinator = [[[SFOAuthCoordinator alloc] initWithCredentials:credentials] autorelease];

        self.coordinator.delegate = self;

        [ self.coordinatorauthenticate ]; // this should NOT pop up a new window, since the credentials are stored

 

Looking over the source code of SFOAuthCoordinator, this seems to be how it's supposed to work, but this just crashes my app (I'm still trying to figure out why - XCode isn't very good about telling you where your app crashed or why).

 

Has anybody been able to get this refresh flow working with the iOS Mobile SDK?  I'd have to imagine this is a pretty common setup.

if i disable showheader it failes calling the apex webservice but if i enable show headers it works on the sites page why is this?

 

Uncaught {faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }