0

我是 Web 开发新手,目前我正在开发一个供 IOS 应用程序使用的 Rest API。所以我开发了 API 并在其中实现了带有 oauth2 安全性的 jwt 令牌。现在我想提供移动应用程序使用的 API。所以我的后端服务器有 SSL 证书。所以消费的 Rest API 将类似于

https://server:port/dataapiurl

到目前为止,我已经阅读了有关 SSL 和 JWT 的信息,并且出于不同的原因,SSL 用于客户端服务器通信之间的加密通道,而 JWT 用于授权。

因此,即使我实现 JWT 并且通信不在 SSL 中也没有意义。所以要确保客户端和服务器之间的通信完成,客户端(移动应用程序)端必须做什么?

1.手机APP是否需要安装新的证书或者我们后端服务器的SSL证书?

2.如果是我们后端服务器的SSL证书,那么如何在手机端安装呢?

任何帮助表示赞赏。

4

1 回答 1

0

您可以但不能在客户端上设置您的 ssl 证书。你可以只遵循 NSURLSessionDelegate 协议并实现这个:

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
    NSArray* netTrusts = @["your hostname here"];
    if(netTrusts != nil && [netTrusts containsObject:challenge.protectionSpace.host]){
        NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
        completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
    }
}

}

于 2017-04-19T08:16:42.167 回答