简体   繁体   English

iOS OneDrive(skydrive)应用程序每次运行时都会显示权限对话框

[英]iOS OneDrive (skydrive) app displays permissions dialog every time it runs

I'm developing an iOS app that gives users access to their OneDrive/SkyDrive and I've run into a very annoying issue: 我正在开发一个iOS应用程序,该应用程序使用户可以访问他们的OneDrive / SkyDrive,但遇到了一个非常烦人的问题:

The very first time a user links the app to their OneDrive, everything goes as expected: 用户第一次将应用程序链接到其OneDrive时,一切都会按预期进行:

  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 然后他们可以浏览他们的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. 但是,如果应用程序关闭,并且您尝试再次访问OneDrive,而不是直接跳到#3并能够访问OneDrive,则它们将在步骤2停止(按预期,跳过了步骤1),并且它们必须再次同意才能让该应用访问其信息。

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: 该代码直接取自在线文档中的iOS示例(基于在Stack Overflow上找到的示例进行了一些细微修改),但是,这里需要进行检查:

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

And then, theDelegate implements this: 然后,theDelegate实现:

- (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. 我以为状态值可能会提供一个线索,也许我可以避免登录调用,但是当我在调用initWithClientId之后进入authCompleted时,它始终为零/未定义。 (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. 我已经看到了与OAuth2登录相关的“刷新令牌”的参考,但是我无法找到任何有关在这种情况下如何使用它们的具体示例。

Any help and/or insights greatly appreciated. 非常感谢任何帮助和/或见解。

Diz DIZ

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. 我只需要在初始登录操作期间将“ wl.offline_access”范围添加到我的范围列表中。 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. 添加了此新作用域之后,对应用程序的后续调用将不再显示“同意​​授予应用程序这些权限”对话框,而我可以直接浏览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: (信用证到期日:在Microsoft论坛上的Stephane Cavin给了我解决该问题的提示。详细信息在这里:

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 ) 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 DIZ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM