iOS OneDrive(skydrive)应用程序每次运行时都会显示权限对话框 [英] iOS OneDrive (skydrive) app displays permissions dialog every time it runs

查看:154
本文介绍了iOS OneDrive(skydrive)应用程序每次运行时都会显示权限对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用,该应用可以使用户访问他们的OneDrive/SkyDrive,但遇到了一个非常烦人的问题:

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

用户第一次将应用程序链接到其OneDrive时,一切都会按预期进行:

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

  1. 他们必须输入用户名和密码
  2. 然后他们必须同意让该应用访问其信息
  3. 然后他们可以浏览他们的OneDrive

那很好.

但是,如果应用程序关闭,并且您尝试再次访问OneDrive,而不是直接跳到#3并能够访问OneDrive,它们将在步骤2停止(如预期的那样,跳过了步骤1) ),他们必须再次同意才能让该应用访问其信息.

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.

该代码直接取自在线文档中的iOS示例(基于在Stack Overflow上找到的示例进行了一些细微修改),但是,这里有待检查:

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"];
    }

然后,Delegate实现此目的:

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.");
        }
    }
}

我认为状态值可能会提供线索,也许我可以避免登录调用,但是当我在调用initWithClientId之后进入authCompleted时,它始终为零/未定义. (会话始终为零.)

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

我是否缺少范围?是否有不同的拨打电话而不是直接登录电话?还是比这更复杂?我已经看到了与OAuth2登录相关的刷新令牌"的参考,但是我无法找到任何在这种情况下如何使用它们的具体示例.

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

推荐答案

嗯,事实证明,答案很简单.我只需要在初始登录操作期间将"wl.offline_access"作用域添加到作用域列表中即可.在这个范围内,文档并没有真正暗示这种行为,但是,这确实帮了我大忙.

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.

添加了这个新作用域之后,对该应用程序的后续调用不再显示同意​​授予该应用程序这些权限"对话框,而我可以直接浏览OneDrive.

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.

(信用证到期日:在Microsoft论坛上的Stephane Cavin给了我解决该问题的提示.详细信息在这里:

(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:

Diz

这篇关于iOS OneDrive(skydrive)应用程序每次运行时都会显示权限对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆