Question

I'm developing an iOS app that gives users access to their OneDrive/SkyDrive and I've run into a very annoying issue:

The very first time a user links the app to their OneDrive, everything goes as expected:

  1. They have to enter a user id and password
  2. Then they have to agree to let the app access their info
  3. Then they get to browse their OneDrive

That's all good.

But, if the app closes, and you try to access the OneDrive again, rather than skipping straight to #3, and being able to access the OneDrive, they are stopped at step #2 (step 1 is skipped, as expected) and they have to agree again to let the app access their info.

The code is taken directly from the iOS examples in the online documentation (with some slight modification based on samples found here on Stack Overflow), but, here it is for inspection:

- (void) onedriveInitWithDelegate:(id)theDelegate {
    self.onedriveClient = [[LiveConnectClient alloc] initWithClientId:MY_CLIENT_ID
    delegate:theDelegate
    userState:@"initialize"];
    }

And then, theDelegate implements this:

- (void)authCompleted:(LiveConnectSessionStatus) status
    session:(LiveConnectSession *) session
    userState:(id) userState {
    NSLog(@"Status: %u", status);
    if ([userState isEqual:@"initialize"]) {
        NSLog( @"authCompleted - Initialized.");
        if (session == nil) {
            [self.onedriveClient login:self
                scopes:[NSArray arrayWithObjects:@"wl.basic", @"wl.signin", @"wl.skydrive_update", nil]
                delegate:self
                userState:@"signin"];
            }
        }
    if ([userState isEqual:@"signin"]) {
        if (session != nil) {
            NSLog( @"authCompleted - Signed in.");
        }
    }
}

I thought that perhaps the status value might give a clue and that maybe I could avoid the login call, but it's always zero/undefined when I get to authCompleted after calling initWithClientId. (And session is always nil.)

Is there a scope I'm missing? Is there a different call to make rather than a straight-up login call? Or is it more complicated than that? I've seen reference to "refresh tokens" related to OAuth2 login, but I've not been able to find any concrete examples of how they might be used in this situation.

Any help and/or insights greatly appreciated.

Diz

Was it helpful?

Solution

Well, it turns out that the answer is pretty simple here. I just needed to add the "wl.offline_access" scope to my list of scopes during the initial login operation. The docs didn't really imply this type of behavior for this scope, but, that did the trick for me.

With this new scope added, subsequent invocations of the app no longer bring up the "agree to give the app these permissions" dialog, and I can go straight to browsing the OneDrive.

(Credit where it's due: Stephane Cavin over at the microsoft forums gave me the tip I needed to work this out. Gory details are here:

http://social.msdn.microsoft.com/Forums/en-US/8c5c7a99-7e49-401d-8616-d568eea3cef1/ios-onedrive-skydrive-app-displays-permissions-dialog-every-time-it-runs?forum=onedriveapi )

Diz

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top