在Cordova/Ionic iOS应用程序中使用WWW-Authenticate处理HTTP 401 [英] Handling HTTP 401 with WWW-Authenticate in Cordova / Ionic iOS application

查看:148
本文介绍了在Cordova/Ionic iOS应用程序中使用WWW-Authenticate处理HTTP 401的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发基于Cordova和Ionic的移动应用程序.我正在使用第三方API(即不能,并且该应用程序无法更改).

I'm currently working on a mobile app built on Cordova and Ionic. I am dealing with a third-party API (i.e. it cannot, and will not be changed for this app to work).

当应用程序的用户未经身份验证时-如果他们的会话已过期或其他原因-API会通过HTTP 401和WWW-Authenticate标头进行响应.

When a user of the app is unauthenticated - be that if their session has expired or otherwise - the API responds with an HTTP 401, with a WWW-Authenticate header.

在浏览器中进行开发时可以,但是在iPhone或模拟器中则不会出现,并且该应用必须达到请求的超时期限.达到该超时后,该请求将被取消.这意味着在JavaScript中,我们只需返回HTTP状态0,就没有实际数据来识别是否存在超时或身份验证问题.

In a browser while developing this is fine, but while on an iPhone, or in a simulator it does not appear, and the app has to reach the timeout period for the request. When that timeout is reached, the request is cancelled. This means that in the JavaScript, we simply get back a HTTP status of 0, with no real data to identify whether or not there was a timeout, or an authentication issue.

当前,我已经进行了一些有根据的猜测,例如在发生超时时检查电话是否具有连通性等,但这并不是一个理想的解决方案,因为用户仍然必须等待该超时,而且并不总是正确的

Currently, I've put in place some educated guesswork like checking if the phone has connectivity when a timeout occurs etc, but this is not an ideal solution as the user still has to wait for that timeout, and it's not always correct.

如何检查HTTP 401对话框何时出现并期望得到响应?我需要能够确定何时出现实际的401,以及何时请求只是超时.

How can I check when the HTTP 401 dialog has appeared and is expecting a response? I need to be able to identify when an actual 401 occurs, and when a request simply times out.

如果JavaScript中有一种方法可以完成,那就太好了.本地解决方案也可以使用,无论是插件还是其他方式.

If there is a method in JavaScript to accomplish then, then that'd be great. A native solution would also work, be it a plugin or otherwise.

推荐答案

我目前正在处理同一问题.

I am dealing with the same issue at the moment.

问题在于,当返回401时,它具有 WWW-Authenticate (件),它告诉浏览器弹出该小弹出窗口供您重试.在iOS Web容器中,这不是正确的"(取决于您问的是谁),这导致Cordova永远看不到请求. 科尔多瓦虫的错误记录在这里: https://issues.apache.org/jira/browse/CB-2415

The issue is that when a 401 is being returned, it has a WWW-Authenticate piece, which tells the browser to pop up that little popup for you to try again. This isn't handled "right" (depends on who you ask I guess) in the iOS web container, which results in Cordova never to see the request. The cordova bug is logged here: https://issues.apache.org/jira/browse/CB-2415

我不明白如何解决这个重大问题.但是我敢肯定它周围有一些技术上的问题.如果您查看更新,则会看到Tobias Bocanegra( https://github.com/tripodsan/cordova-ios/commit/5f0133c026d6e21c93ab1ca0e146e125dfbe8f7e )添加了快速破解"来解决该问题.也许可以帮助您进一步.在我的情况下,它没有帮助我.

I don't understand how such a major issue hasn't been resolved, yet. But I am sure there are some technicalities around it. If you check out the updates, you see that Tobias Bocanegra ( https://github.com/tripodsan/cordova-ios/commit/5f0133c026d6e21c93ab1ca0e146e125dfbe8f7e ) added a "quick hack" to solve the problem. Maybe that helps you further. It didn't help me in my situation.

我为临时修复所做的工作: 我将http请求传递到了加载模式,该模式具有一个取消按钮.因此,取决于用户取消还是等待.这太可怕了,但是对我来说确实有效. (内部应用等)

What I did in my case for a temporary fix: I passed the http requests into the loading modal, which has a cancel button. So, it is up to the user to cancel or just wait. It's horrible, but it worked in my case. (Internal app, etc.)

这篇关于在Cordova/Ionic iOS应用程序中使用WWW-Authenticate处理HTTP 401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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