Networking with URLSession: Authentication&ATS
来源:互联网 发布:2017淘宝买家秀男大jb 编辑:程序博客网 时间:2024/04/25 02:31
内容来自PART 8: AUTHENTICATION,记录下学习的笔记
Networking with URLSessionL: Authentication&ATS
Authentication
Authentication分类
- Basic/Digest access
- Basic access over HTTPS
- OpenID Connect (on OAuth 2.0)
- Client/Server certificates: X.509
Kerberos/NTLM (NT LAN Manager)
- URLAuthenticationMethodNegotiate
HTTP请求报头: Authorization
HTTP响应报头: WWW-Authenticate
基本认证
基本认证是一种用来允许Web浏览器或其他客户端程序在请求时提供用户名和口令形式的身份凭证的一种登录验证方式。
把 “用户名+冒号+密码”用BASE64算法加密后的字符串放在http request 中的header Authorization中发送给服务端。
不错的文章
- HTTP认证方式
- 维基百科-HTTP基本认证
客户端的请求(用户名“”Aladdin”,口令, password “open sesame”):
GET /private/index.html HTTP/1.0Host: localhostAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
如果一个session task需要authentication
,并且没有有效的可以的credentials
,就创建了一个authentication challenge
,首先是调用URLSessionTaskDelegate
协议的如下方法:
func urlSession(URLSession, task: URLSessionTask,didReceive: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
如果task的代理没有响应这个消息,task就给session代理(URLSessionDelegate
)发送消息:
func urlSession(URLSession, didReceive: URLAuthenticationChallenge,completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
Cookie
可通过URLSessionConfiguration配置对象的属性来控制配置cookie
1.Set cookies from cookie store?
configuration.httpShouldSetCookies = false
2.Accept cookies?
configuration.httpCookieAcceptPolicy = .never
3.Store cookies?
configuration.httpCookieStorage = nil
ATS
不错的关于ATS的介绍的文章:
- iOS 10 适配 ATS(app支持https通过App Store审核)
- 关于 iOS 10 中 ATS 的问题
介绍了几个有关ATS相关的工具
1.ealeksandrov/ProvisionQL
可用来查看api包的ATS设置的状况和mobileprovision
安装:下载后把ProvisionQL.qlgenerator
复制到library
文件夹中的QuickLook
文件夹,然后在终端输入qlmanage -r
即可
如下,在QQ的ipa安装包上按空格:
2.Ashton-W/RemoveATSExceptions.sh从info.plist
中移除NSAppTransportSecurity
3.https://www.ssllabs.com/ssltest/
分析ssl server
如下,在info.plist中如下设置
<dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSExceptionDomains</key> <dict> <key>qualitycoding.org</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict></dict>
测试时如果使用WKWebView
打开http://qualitycoding.org
这个非HTTPS的链接,会在浏览器中弹出如下的提示:
而打开其他的http则不会提示
另外,如果想打开http的网页,并且不使用NSAllowsArbitraryLoads
,SFSafariViewController
是个不错的选择。
- Networking with URLSession: Authentication&ATS
- Networking with URLSession一 URLSession
- Networking with URLSession: Background Session
- Networking with URLSession二 上传&下载
- URLSession
- URLSession
- iOS7 Networking with NSURLSession
- iOS7 Networking with NSURLSession
- iOS7 Networking with NSURLSession
- iOS7 Networking with NSURLSession
- UsernameToken Authentication with Rampart
- UsernameToken Authentication with Rampart
- Virtualized bridged networking with MacVTap
- Using DevStack with neutron Networking
- ATS
- ATS
- ATS
- ats
- 游戏化思维——核心驱动力
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 一个全局的定时事件发生器
- hdu 1071 The area
- PowerDesigner逆向工程,同时将comm注释转化为name显示
- Networking with URLSession: Authentication&ATS
- mysql数据库-外键
- redis存储关系性数据库数据
- 图片轮播
- Java并发编程系列之三:锁与volatile的内存语义
- 清除tomcat下的work目录
- Java8新特性jdeps详解
- spring4学习记录01-初识spring
- js笔记2