ios CredStore 执行查询错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46099940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CredStore Perform Query error
提问by Anthony Taylor
I am running into an issue while doing API calls to my apps backend, every connection now prompts with
我在对我的应用程序后端进行 API 调用时遇到问题,现在每个连接都提示
CredStore - performQuery - Error copying matching creds. Error=-25300, query={
atyp = http;
class = inet;
"m_Limit" = "m_LimitAll";
ptcl = http;
"r_Attributes" = 1;
srvr = "myappsurl.com";
sync = syna;
}
I am a little lost as I am not sure what is causing this, or what CredStore even does. What purpose does CredStore serve in iOS?
我有点迷茫,因为我不确定是什么导致了这种情况,或者 CredStore 甚至做了什么。CredStore 在 iOS 中的作用是什么?
采纳答案by Brett
This error occurs when trying to retrieve an URLCredential
from URLCredentialStorage
for an unknown URLProtectionSpace
.
e.g.
尝试为未知检索URLCredential
from时会发生此错误。例如URLCredentialStorage
URLProtectionSpace
let protectionSpace = URLProtectionSpace.init(host: host,
port: port,
protocol: "http",
realm: nil,
authenticationMethod: nil)
var credential: URLCredential? = URLCredentialStorage.shared.defaultCredential(for: protectionSpace)
produces
产生
CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
"m_Limit" = "m_LimitAll";
ptcl = http;
"r_Attributes" = 1;
srvr = host;
sync = syna;
}
Give it a credential for the protection space:
给它一个保护空间的凭证:
let userCredential = URLCredential(user: user,
password: password,
persistence: .permanent)
URLCredentialStorage.shared.setDefaultCredential(userCredential, for: protectionSpace)
and the error goes away next time you try to retrieve the credential.
下次您尝试检索凭据时,错误就会消失。
I am a little lost as I am not sure what is causing this, or what CredStore even does. What purpose does CredStore serve in iOS?
我有点迷茫,因为我不确定是什么导致了这种情况,或者 CredStore 甚至做了什么。CredStore 在 iOS 中的作用是什么?
Credential storage on iOS allows users to securely store certificate-based or password-based credentials on the device either temporarily or permanently to the keychain.
iOS 上的凭据存储允许用户将设备上基于证书或基于密码的凭据临时或永久地安全地存储到钥匙串中。
I suspect that you have some sort of authentication on your backend server and that server is requesting an authentication challenge to your app (for which no credential exists).
我怀疑您在后端服务器上进行了某种身份验证,并且该服务器正在向您的应用程序请求身份验证质询(不存在凭据)。
It can probably be safely ignored as returning nil from the URLCredentialStorage
is a valid response
它可能可以安全地忽略,因为从 返回 nilURLCredentialStorage
是一个有效的响应
回答by Gleb Tarasov
I'm not sure why do we get this error when perform requests with Alamofire, but if you do API requests with some token in HTTP headers, you maybe don't need credentials store at all. So we can disable it for our request:
我不确定为什么在使用 Alamofire 执行请求时会出现此错误,但是如果您使用 HTTP 标头中的某些令牌执行 API 请求,您可能根本不需要凭据存储。所以我们可以为我们的请求禁用它:
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = ourHeaders
// disable default credential store
configuration.urlCredentialStorage = nil
let manager = Alamofire.SessionManager(configuration: configuration)
...
No errors after such change.
这样更改后没有错误。
回答by tuan nguyen
This is transport error, let's add transport permission like this in plist file:
这是传输错误,让我们在 plist 文件中添加这样的传输权限:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Be carefulas that enables connection to any server from your app. Read more on App Transport Security before proceeding. See comment by @kezi
小心,因为这可以从您的应用程序连接到任何服务器。在继续之前阅读有关应用传输安全的更多信息。查看@kezi 的评论
回答by Iqbal Khan
This same issue happens to me and I found that if your API URL does not contain a "/" at the end of URL then iOS does not send "Authorization" value to the server. Due to which you will see a message like posted in question in the console.
我也遇到了同样的问题,我发现如果您的 API URL 在 URL 末尾不包含“/”,那么 iOS 不会向服务器发送“授权”值。因此,您将在控制台中看到类似发布的消息。
So Simply add "/" at the end of URL
所以只需在 URL 末尾添加“/”
https://example.com/api/devices/
回答by preetam
In my case, I was not initialising Stripe SDK with API key.
就我而言,我没有使用 API 密钥初始化 Stripe SDK。
STPPaymentConfiguration.shared().publishableKey = publishableKey
In case of any Stripe operation, we can print the error log, its easy to understand.
在任何 Stripe 操作的情况下,我们可以打印错误日志,它很容易理解。
print(error.debugDescription)
回答by Andrey Agapov
If you get this error, when using AVPlayer, just call .play() on main thread
如果出现此错误,在使用 AVPlayer 时,只需在主线程上调用 .play()
回答by TALE
The cause of me getting this error was due to me accidentally using two spaces between the "Bearer" and access token in my Authorization header.
我收到此错误的原因是由于我不小心在 Authorization 标头中的“Bearer”和访问令牌之间使用了两个空格。
Incorrect:
不正确:
request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
Correct:
正确的:
request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
Simple mistake, but it took a while to find it.
简单的错误,但花了一段时间才找到它。
回答by Snips
OK, I had this error, and fought with it for a long time (years) when interacting with my Ruby on Rails app.
好的,我遇到了这个错误,并且在与我的 Ruby on Rails 应用程序交互时与它斗争了很长时间(几年)。
I had default credentials set up as described in the accepted answer, but still got the error, and have been relying on a didReceiveChallenge response to supply the credentials - fortunately that worked as a work around.
我按照接受的答案中的描述设置了默认凭据,但仍然出现错误,并且一直依赖于 didReceiveChallenge 响应来提供凭据 - 幸运的是,这是一种解决方法。
But! I've just found the solution!
但!我刚刚找到了解决方案!
I was working on a hunch that that the protectedSpace fields did not match the Authorization challenge from the Ruby on Rails server - and I looked into the realm field, which seemed to be the only one that was being left undefined.
我的预感是,protectedSpace 字段与来自 Ruby on Rails 服务器的授权挑战不匹配 - 我查看了领域字段,它似乎是唯一未定义的字段。
I started by printing out the server response headers, and although I was able to examine these, they did not include the WWW-Authorization field that would have included the realm field.
我首先打印出服务器响应标头,虽然我能够检查这些标头,但它们不包括 WWW-Authorization 字段,而该字段将包含领域字段。
I thought this was maybe because my Rails app wasn't specifying the realm, so I started looking at the Rails side of things.
我想这可能是因为我的 Rails 应用程序没有指定领域,所以我开始关注 Rails 方面的事情。
I found I could specify the realm in the call to,
我发现我可以在调用中指定领域,
authenticate_or_request_with_http_basic
...which I am using for HTTP Basic authentication.
...我用于 HTTP 基本身份验证。
I wasn't specifying a realm already, so added one,
我还没有指定一个领域,所以添加了一个,
authenticate_or_request_with_http_basic("My Rails App")
I then added the corresponding string to the protectionSpace,
然后我将相应的字符串添加到protectionSpace,
NSURLProtectionSpace *protectionSpace =
[[NSURLProtectionSpace alloc] initWithHost:@"myrailsapp.com"
port:443
protocol:NSURLProtectionSpaceHTTPS
realm:@"My Rails App"
authenticationMethod:NSURLAuthenticationMethodHTTPBasic];
Voila! That worked, and I no longer get the,
瞧!那行得通,我不再明白了,
CredStore - performQuery - Error copying matching creds. Error=-25300
Even after specifying the realm in the Rails app, I still don't see it passed in the HTTP header, I don't know why, but at least it works.
即使在 Rails 应用程序中指定了领域之后,我仍然没有看到它在 HTTP 标头中传递,我不知道为什么,但至少它有效。
回答by Pavlos
I edited the String that contains the URL to fix this issue:
我编辑了包含 URL 的字符串来解决这个问题:
var myUrl = "http://myurl.com"
myUrl = myUrl.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
let url = URL(string: myUrl)
回答by Serge Maslyakov
I got this issue when I tried to open a http-page inside a web-view. But this page contained an popup which was opened first.
当我尝试在 web 视图中打开 http 页面时遇到了这个问题。但是这个页面包含一个首先打开的弹出窗口。
When backend team removed this popup everything became OK.
当后端团队删除此弹出窗口时,一切都变得正常了。