CredStore执行查询错误

Ant*_*lor 93 ios xcode9

我在对我的应用程序后端进行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;
}
Run Code Online (Sandbox Code Playgroud)

我有点失落,因为我不确定是什么导致了这个,或者CredStore甚至做了什么.CredStore在iOS中的用途是什么?

Bre*_*ett 28

尝试URLCredentialURLCredentialStorage未知中检索from 时会发生此错误URLProtectionSpace.例如

let protectionSpace = URLProtectionSpace.init(host: host, 
                                              port: port, 
                                              protocol: "http", 
                                              realm: nil, 
                                              authenticationMethod: nil)

var credential: URLCredential? = URLCredentialStorage.shared.defaultCredential(for: protectionSpace)
Run Code Online (Sandbox Code Playgroud)

产生

CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = http;
    "r_Attributes" = 1;
    srvr = host;
    sync = syna;
}
Run Code Online (Sandbox Code Playgroud)

为它提供保护空间的凭证:

let userCredential = URLCredential(user: user, 
                                   password: password, 
                                   persistence: .permanent)

URLCredentialStorage.shared.setDefaultCredential(userCredential, for: protectionSpace)
Run Code Online (Sandbox Code Playgroud)

并且下次尝试检索凭证时错误消失.

我有点失落,因为我不确定是什么导致了这个,或者CredStore甚至做了什么.CredStore在iOS中的用途是什么?

iOS上的凭证存储允许用户在设备上临时或永久地将基于证书或基于密码的凭证安全地存储到钥匙串中.

我怀疑您在后端服务器上有某种身份验证,并且该服务器正在请求对您的应用程序进行身份验证质询(没有凭据存在).

它可能被安全地忽略,因为返回nil URLCredentialStorage是一个有效的响应

  • 您将如何创建保护空间? (2认同)
  • 如何在Moya和Alamofire中使用? (2认同)

Gle*_*sov 12

我不确定为什么在使用 Alamofire 执行请求时会出现此错误,但是如果您使用 HTTP 标头中的某些令牌执行 API 请求,您可能根本不需要凭据存储。所以我们可以为我们的请求禁用它:

let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = ourHeaders
// disable default credential store
configuration.urlCredentialStorage = nil

let manager = Alamofire.SessionManager(configuration: configuration)
...
Run Code Online (Sandbox Code Playgroud)

这样更改后没有错误。


pre*_*tam 5

就我而言,我没有使用 API 密钥初始化 Stripe SDK。

        STPPaymentConfiguration.shared().publishableKey = publishableKey
Run Code Online (Sandbox Code Playgroud)

对于任何Stripe操作,我们都可以打印错误日志,很容易理解。

        print(error.debugDescription)
Run Code Online (Sandbox Code Playgroud)


Iqb*_*han 5

我也遇到了同样的问题,我发现如果您的 API URL 在 URL 末尾不包含“/”,那么 iOS 不会向服务器发送“授权”值。因此,您将在控制台中看到一条类似发布的消息。

所以只需在 URL 末尾添加“/”

https://example.com/api/devices/
Run Code Online (Sandbox Code Playgroud)