正确获取并存储Box iOS sdk oauth2令牌

时间:2014-02-25 07:13:30

标签: ios xcode oauth-2.0 box-api

我正在开发一个项目,使用示例应用程序中给出的许多代码,但无法弄清楚为什么我的应用程序不存储oauth令牌。正如我所说,我已经使用了ios sdk示例应用程序中的大量代码,示例应用程序本身可以100%正常工作......

我的日志非常混乱,您看到了问题吗?

编辑:

我启用了2步验证,每次登录时,我都会收到2封电子邮件。有人说我从iPhone手机浏览器登录了一个盒子,有人说我从在developers.box.com注册的应用程序登录了一个盒子。

这是我的输出:

2014-02-25 08:09:39.055 SidebarDemo[4005:3b07] +[BoxAPIOperation globalAPIOperationNetworkThreadEntryPoint:]: <NSThread: 0x9fa2d80>{name = Box API Operation Thread, num = 2} started
2014-02-25 08:09:39.054 SidebarDemo[4005:70b] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued <BoxAPIJSONOperation: 0x9d5ceb0> GET https://api.box.com/2.0/folders/0 on global queue
2014-02-25 08:09:39.056 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: BoxAPIOperation <BoxAPIJSONOperation: 0x9d5ceb0> GET https://api.box.com/2.0/folders/0 was started
2014-02-25 08:09:39.063 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: Starting <BoxAPIJSONOperation: 0x9d5ceb0> GET https://api.box.com/2.0/folders/0
2014-02-25 08:09:39.068 SidebarDemo[4005:70b] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued <BoxAPIJSONOperation: 0x9d68fb0> GET https://api.box.com/2.0/folders/0/items on global queue
2014-02-25 08:09:39.866 SidebarDemo[4005:3b07] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: OAuth2 access token is expired.
2014-02-25 08:09:39.866 SidebarDemo[4005:3b07] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: Re-enqueueing operation that failed to authenticate
2014-02-25 08:09:39.867 SidebarDemo[4005:3b07] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued <BoxAPIJSONOperation: 0x9c81680> GET https://api.box.com/2.0/folders/0 on global queue
2014-02-25 08:09:39.867 SidebarDemo[4005:3b07] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: Attempting automatic OAuth2 token refresh
2014-02-25 08:09:39.867 SidebarDemo[4005:3b07] -[BoxParallelOAuth2Session performRefreshTokenGrant:]: access token expired: (null)
2014-02-25 08:09:39.868 SidebarDemo[4005:3b07] -[BoxParallelOAuth2Session performRefreshTokenGrant:]: refreshing tokens
2014-02-25 08:09:39.868 SidebarDemo[4005:3b07] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued <BoxAPIOAuth2ToJSONOperation: 0x9c85920> POST https://api.box.com/oauth2/token on global queue
2014-02-25 08:09:39.869 SidebarDemo[4005:3b07] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation <BoxAPIJSONOperation: 0x9d5ceb0> GET https://api.box.com/2.0/folders/0 did finsh loading
2014-02-25 08:09:39.869 SidebarDemo[4005:3b07] -[BoxAPIOperation finish]: BoxAPIOperation <BoxAPIJSONOperation: 0x9d5ceb0> GET https://api.box.com/2.0/folders/0 finished with state 3
2014-02-25 08:09:39.870 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: BoxAPIOperation <BoxAPIOAuth2ToJSONOperation: 0x9c85920> POST https://api.box.com/oauth2/token was started
2014-02-25 08:09:39.870 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: Starting <BoxAPIOAuth2ToJSONOperation: 0x9c85920> POST https://api.box.com/oauth2/token
2014-02-25 08:09:40.163 SidebarDemo[4005:3b07] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation <BoxAPIOAuth2ToJSONOperation: 0x9c85920> POST https://api.box.com/oauth2/token did finsh loading
2014-02-25 08:09:40.163 SidebarDemo[4005:3b07] Refresh failed. User is logged out. Initiate login flow
2014-02-25 08:09:40.167 SidebarDemo[4005:3b07] -[BoxAPIQueueManager OAuth2OperationDidComplete:]: <BoxAPIOAuth2ToJSONOperation: 0x9c85920> POST https://api.box.com/oauth2/token completed. Removing from set of OAuth2 dependencies
2014-02-25 08:09:40.167 SidebarDemo[4005:3b07] -[BoxAPIOperation finish]: BoxAPIOperation <BoxAPIOAuth2ToJSONOperation: 0x9c85920> POST https://api.box.com/oauth2/token finished with state 3
2014-02-25 08:09:40.168 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: BoxAPIOperation <BoxAPIJSONOperation: 0x9d68fb0> GET https://api.box.com/2.0/folders/0/items was started
2014-02-25 08:09:40.168 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: Starting <BoxAPIJSONOperation: 0x9d68fb0> GET https://api.box.com/2.0/folders/0/items
2014-02-25 08:09:40.422 SidebarDemo[4005:3b07] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: OAuth2 access token is expired.
2014-02-25 08:09:40.423 SidebarDemo[4005:3b07] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: Re-enqueueing operation that failed to authenticate
2014-02-25 08:09:40.423 SidebarDemo[4005:3b07] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued <BoxAPIJSONOperation: 0x9faa340> GET https://api.box.com/2.0/folders/0/items on global queue
2014-02-25 08:09:40.424 SidebarDemo[4005:3b07] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: Attempting automatic OAuth2 token refresh
2014-02-25 08:09:40.424 SidebarDemo[4005:3b07] -[BoxParallelOAuth2Session performRefreshTokenGrant:]: access token expired: (null)
2014-02-25 08:09:40.424 SidebarDemo[4005:3b07] -[BoxParallelOAuth2Session performRefreshTokenGrant:]: refreshing tokens
2014-02-25 08:09:40.425 SidebarDemo[4005:3b07] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued <BoxAPIOAuth2ToJSONOperation: 0x9d51130> POST https://api.box.com/oauth2/token on global queue
2014-02-25 08:09:40.425 SidebarDemo[4005:3b07] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation <BoxAPIJSONOperation: 0x9d68fb0> GET https://api.box.com/2.0/folders/0/items did finsh loading
2014-02-25 08:09:40.521 SidebarDemo[4005:3b07] folder items error: Error Domain=com.box.sdk.errordomain Code=20000 "The operation couldn’t be completed. (com.box.sdk.errordomain error 20000.)"
2014-02-25 08:09:40.521 SidebarDemo[4005:3b07] -[BoxAPIOperation finish]: BoxAPIOperation <BoxAPIJSONOperation: 0x9d68fb0> GET https://api.box.com/2.0/folders/0/items finished with state 3
2014-02-25 08:09:40.521 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: BoxAPIOperation <BoxAPIOAuth2ToJSONOperation: 0x9d51130> POST https://api.box.com/oauth2/token was started
2014-02-25 08:09:40.522 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: Starting <BoxAPIOAuth2ToJSONOperation: 0x9d51130> POST https://api.box.com/oauth2/token
2014-02-25 08:09:40.525 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webView:shouldStartLoadWithRequest:navigationType:]: Web view should start request <NSMutableURLRequest: 0x9fafaf0> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } with navigation type 5
2014-02-25 08:09:40.526 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webView:shouldStartLoadWithRequest:navigationType:]: Request Headers 
{
    Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    "User-Agent" = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_3 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B508";
}
2014-02-25 08:09:40.528 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webView:shouldStartLoadWithRequest:navigationType:]: Was not authenticated, launching URLConnection and not loading the request in the web view
2014-02-25 08:09:40.528 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webView:shouldStartLoadWithRequest:navigationType:]: URLConnection is <NSURLConnection: 0x9c9ba90> { request: <NSMutableURLRequest: 0x9fafaf0> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } }
2014-02-25 08:09:40.802 SidebarDemo[4005:3b07] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation <BoxAPIOAuth2ToJSONOperation: 0x9d51130> POST https://api.box.com/oauth2/token did finsh loading
2014-02-25 08:09:40.803 SidebarDemo[4005:3b07] Refresh failed. User is logged out. Initiate login flow
2014-02-25 08:09:40.804 SidebarDemo[4005:70b] Warning: Attempt to present <BoxAuthorizationNavigationController: 0x9e6b710> on <SWRevealViewController: 0x9fa5840> whose view is not in the window hierarchy!
2014-02-25 08:09:40.805 SidebarDemo[4005:70b] -[BoxAuthorizationViewController clearCookies]: Attempt to clear cookies
2014-02-25 08:09:40.806 SidebarDemo[4005:3b07] -[BoxAPIQueueManager OAuth2OperationDidComplete:]: <BoxAPIOAuth2ToJSONOperation: 0x9d51130> POST https://api.box.com/oauth2/token completed. Removing from set of OAuth2 dependencies
2014-02-25 08:09:40.806 SidebarDemo[4005:3b07] -[BoxAPIOperation finish]: BoxAPIOperation <BoxAPIOAuth2ToJSONOperation: 0x9d51130> POST https://api.box.com/oauth2/token finished with state 3
2014-02-25 08:09:40.807 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: BoxAPIOperation <BoxAPIJSONOperation: 0x9c81680> GET https://api.box.com/2.0/folders/0 was started
2014-02-25 08:09:40.807 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: Starting <BoxAPIJSONOperation: 0x9c81680> GET https://api.box.com/2.0/folders/0
2014-02-25 08:09:40.940 SidebarDemo[4005:70b] -[BoxAuthorizationViewController connection:willSendRequestForAuthenticationChallenge:]: connection <NSURLConnection: 0x9c9ba90> { request: <NSMutableURLRequest: 0x9fafaf0> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } } did receive authentication challenge <NSURLAuthenticationChallenge: 0x9fb1190>
2014-02-25 08:09:40.940 SidebarDemo[4005:70b] -[BoxAuthorizationViewController connection:willSendRequestForAuthenticationChallenge:]: Server trust authentication challenge
2014-02-25 08:09:40.942 SidebarDemo[4005:70b] -[BoxAuthorizationViewController completeServerTrustAuthenticationChallenge:shouldTrust:]: Trust the host.
2014-02-25 08:09:41.046 SidebarDemo[4005:3b07] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation <BoxAPIJSONOperation: 0x9c81680> GET https://api.box.com/2.0/folders/0 did finsh loading
2014-02-25 08:09:41.046 SidebarDemo[4005:3b07] -[BoxAPIOperation finish]: BoxAPIOperation <BoxAPIJSONOperation: 0x9c81680> GET https://api.box.com/2.0/folders/0 finished with state 3
2014-02-25 08:09:41.047 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: BoxAPIOperation <BoxAPIJSONOperation: 0x9faa340> GET https://api.box.com/2.0/folders/0/items was started
2014-02-25 08:09:41.047 SidebarDemo[4005:3b07] -[BoxAPIOperation executeOperation]: Starting <BoxAPIJSONOperation: 0x9faa340> GET https://api.box.com/2.0/folders/0/items
2014-02-25 08:09:41.280 SidebarDemo[4005:3b07] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation <BoxAPIJSONOperation: 0x9faa340> GET https://api.box.com/2.0/folders/0/items did finsh loading
2014-02-25 08:09:41.280 SidebarDemo[4005:3b07] folder items error: Error Domain=com.box.sdk.errordomain Code=20002 "The operation couldn’t be completed. (com.box.sdk.errordomain error 20002.)"
2014-02-25 08:09:41.281 SidebarDemo[4005:3b07] -[BoxAPIOperation finish]: BoxAPIOperation <BoxAPIJSONOperation: 0x9faa340> GET https://api.box.com/2.0/folders/0/items finished with state 3
2014-02-25 08:09:41.534 SidebarDemo[4005:70b] -[BoxAuthorizationViewController connection:didReceiveResponse:]: Connection <NSURLConnection: 0x9c9ba90> { request: <NSMutableURLRequest: 0x9fafaf0> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } } did receive response <NSHTTPURLResponse: 0x9c5d260> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } { status code: 200, headers {
    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Tue, 25 Feb 2014 07:09:41 GMT";
    Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
    Pragma = "no-cache";
    Server = nginx;
    "Set-Cookie" = "z=dns8qfgvluf8bonm9e7j28h4i6; path=/; domain=.box.com; secure; HttpOnly, presentation=desktop; path=/; domain=.box.com";
    "Transfer-Encoding" = Identity;
} }
2014-02-25 08:09:41.535 SidebarDemo[4005:70b] -[BoxAuthorizationViewController connection:didReceiveResponse:]: HTTP Headers were: {
    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Tue, 25 Feb 2014 07:09:41 GMT";
    Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
    Pragma = "no-cache";
    Server = nginx;
    "Set-Cookie" = "z=dns8qfgvluf8bonm9e7j28h4i6; path=/; domain=.box.com; secure; HttpOnly, presentation=desktop; path=/; domain=.box.com";
    "Transfer-Encoding" = Identity;
}
2014-02-25 08:09:41.536 SidebarDemo[4005:70b] -[BoxAuthorizationViewController connection:didReceiveData:]: Connection <NSURLConnection: 0x9c9ba90> { request: <NSMutableURLRequest: 0x9fafaf0> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } } did receive 8090 bytes of data
2014-02-25 08:09:41.536 SidebarDemo[4005:70b] -[BoxAuthorizationViewController connectionDidFinishLoading:]: Connection <NSURLConnection: 0x9c9ba90> { request: <NSMutableURLRequest: 0x9fafaf0> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } } did finish loading. Requesting that the webview load the data (8090 bytes) with reponse <NSHTTPURLResponse: 0x9c5d260> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } { status code: 200, headers {
    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Tue, 25 Feb 2014 07:09:41 GMT";
    Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
    Pragma = "no-cache";
    Server = nginx;
    "Set-Cookie" = "z=dns8qfgvluf8bonm9e7j28h4i6; path=/; domain=.box.com; secure; HttpOnly, presentation=desktop; path=/; domain=.box.com";
    "Transfer-Encoding" = Identity;
} }
2014-02-25 08:09:41.573 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webView:shouldStartLoadWithRequest:navigationType:]: Web view should start request <NSMutableURLRequest: 0x9d67f00> { URL: https://api.box.com/oauth2/authorize?response_type=code&client_id=eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp&state=ok&redirect_uri=boxsdk-eh3fjhsm8i5n1gyffntxa8mr3ghlnqwp%3A%2F%2Fboxsdkoauth2redirect } with navigation type 5
2014-02-25 08:09:41.573 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webView:shouldStartLoadWithRequest:navigationType:]: Request Headers 
{
    Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    "User-Agent" = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_3 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B508";
}
2014-02-25 08:09:41.574 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webViewDidStartLoad:]
2014-02-25 08:09:41.676 SidebarDemo[4005:70b] -[BoxAuthorizationViewController webViewDidFinishLoad:]

1 个答案:

答案 0 :(得分:0)

我的钥匙串脚本没有正常工作,与其他文件无关。在我的情况下,而不是创建一个新项目和实现BoxSDK,使用BoxSDK示例应用程序将其他所有内容编码到其中。

:)