作者:劉賓焦人, thomas_liub@hotmail.com
請尊重作者著作權(quán)挥吵,轉(zhuǎn)載請注明出處,謝謝花椭!
SSO筆記
典型的SSO機(jī)制
Kerberos
- 麻省理工大學(xué)發(fā)明
- 客戶端/服務(wù)器結(jié)構(gòu)與DES加密技術(shù)忽匈,并且能夠進(jìn)行相互認(rèn)證,即客戶端和服務(wù)器端均可對對方進(jìn)行身份認(rèn)證
- 一種應(yīng)用對稱密鑰體制進(jìn)行密鑰管理的系統(tǒng)矿辽,支持SSO
- 不適應(yīng)互聯(lián)網(wǎng)環(huán)境
- UNIX 和 Windows 作為默認(rèn)的安全認(rèn)證服務(wù)集成進(jìn)操作系統(tǒng)
- 蘋果的Mac OS X也使用了Kerberos的客戶和服務(wù)器版本
- Red Hat Enterprise Linux4 和后續(xù)的操作系統(tǒng)使用了Kerberos的客戶和服務(wù)器版本
OAuth2
- 名詞解釋
- Third-party application:第三方應(yīng)用程序丹允,本文中又稱"客戶端"(client),即上一節(jié)例子中的"云沖印"袋倔。
- HTTP service:HTTP服務(wù)提供商嫌松,本文中簡稱"服務(wù)提供商",即上一節(jié)例子中的Google奕污。
- Resource Owner:資源所有者萎羔,本文中又稱"用戶"(user)。
- User Agent:用戶代理碳默,本文中就是指瀏覽器贾陷。
- Authorization server:認(rèn)證服務(wù)器,即服務(wù)提供商專門用來處理認(rèn)證的服務(wù)器嘱根。
- Resource server:資源服務(wù)器髓废,即服務(wù)提供商存放用戶生成的資源的服務(wù)器。它與認(rèn)證服務(wù)器该抒,可以是同一臺服務(wù)器慌洪,也可以是不同的服務(wù)器。
- 授權(quán)模式
-
授權(quán)碼模式(authorization code)
(A)用戶訪問客戶端,后者將前者導(dǎo)向認(rèn)證服務(wù)器冈爹。
(B)用戶選擇是否給予客戶端授權(quán)涌攻。
(C)假設(shè)用戶給予授權(quán),認(rèn)證服務(wù)器將用戶導(dǎo)向客戶端事先指定的"重定向URI"(redirection URI)频伤,同時(shí)附上一個授權(quán)碼恳谎。
(D)客戶端收到授權(quán)碼,附上早先的"重定向URI"憋肖,向認(rèn)證服務(wù)器申請令牌因痛。這一步是在客戶端的后臺的服務(wù)器上完成的,對用戶不可見岸更。
(E)認(rèn)證服務(wù)器核對了授權(quán)碼和重定向URI鸵膏,確認(rèn)無誤后,向客戶端發(fā)送訪問令牌(access token)和更新令牌(refresh token) -
簡化模式(implicit)
-
密碼模式(resource owner password credentials)
-
客戶端模式(client credentials)
-
- 令牌更新
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
OpenID
- OpenID 是一個以用戶為中心的數(shù)字身份識別框架怎炊,它具有開放谭企、分散性
- 沒有實(shí)現(xiàn)SSO, 沒有驗(yàn)證所有party
- 結(jié)合OAuth
- 僅web應(yīng)用
OpenID connect
- 開源項(xiàng)目
- 登陸訪問步驟
- 【百度域】,初始訪問服務(wù)结胀,無授權(quán)碼赞咙,無access token
http://www.baidu.com
- 【CAS域】责循,網(wǎng)關(guān)發(fā)起重定向?yàn)g覽器到CAS
http://192.168.1.28:8091/openid/authorize?client_id=717771&redirect_uri=http://www.baidu.com&response_type=code&scope=openid%20email%20profile&state=123123
- 【CAS域】糟港,無session id, CAS重定向授權(quán)(瀏覽器重定向)
http://192.168.1.28:8091/accounts/login/?next=/openid/authorize%3Fclient_id%3D717771%26redirect_uri%3Dhttp%3A//www.baidu.com%26response_type%3Dcode%26scope%3Dopenid%2520email%2520profile%26state%3D123123
- 【CAS域】,用戶登陸院仿,登陸成功后設(shè)置CAS域session id到cookie
http://192.168.1.28:8091/accounts/login http://192.168.1.28:8091/accounts/logout
- 【CAS域】秸抚,登陸后,跳回CAS授權(quán)
http://192.168.1.28:8091/openid/authorize?client_id=717771&redirect_uri=http://www.baidu.com&response_type=code&scope=openid%20email%20profile&state=123123
- 【百度域】歹垫,重定向?yàn)g覽器到訪問服務(wù)剥汤,帶授權(quán)碼
https://www.baidu.com/?state=123123&code=ed27cf5ee1ac4c8784126bbf825ccb45
- 【百度域】,網(wǎng)關(guān)根據(jù)授權(quán)碼排惨,獲取token吭敢,code -> tokens,設(shè)置access token到cookie
返回:curl -X POST \ -H "Cache-Control: no-cache" \ -H "Content-Type: application/x-www-form-urlencoded" \ "http://192.168.1.28:8091/openid/token/" \ -d "client_id=717771" \ -d "client_secret=1ac931638624e5d8ae002aaeaec4302031db92e7451edf36e0d008c9" \ -d "code=ed27cf5ee1ac4c8784126bbf825ccb45" \ -d "redirect_uri=http://www.baidu.com" \ -d "grant_type=authorization_code"
{ "access_token": "82b35f3d810f4cf49dd7a52d4b22a594", "token_type": "bearer", "expires_in": 3600, "refresh_token": "0bac2d80d75d46658b0b31d3778039bb", "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc0NTU5ZGE1NTQzMTY4YzFiYTQ3OWJiMWFlMmRjMGRhIn0.eyJzdWIiOiIxIiwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4yODo4MDkxL29wZW5pZCIsImF0X2hhc2giOiI2R0tQM1RfS09GcFBmNWh5bFNPMmxnIiwiZXhwIjoxNDkwNzUzODYxLCJhdXRoX3RpbWUiOjE0OTA2ODcxMTQsImlhdCI6MTQ5MDc1MzI2MSwiYXVkIjoiNzE3NzcxIn0.vzFWuo99uM2HK2TWML8zE5sLpEjg5NGSFMzxKbtYUrr_EDRghlZJwh1w8VHEzPDIbNfRfeOwqPC9nhbl2q1yJS1F8vJRrBVtBpyawLGqAr3_SBwA9Xx3AmZR5X8Xid-3SHqGu3n93gD-XbvP_gcvrdsfgmHJK5PWjqj1jA_5zMM" }
- 【百度域】,讀取用戶信息
http://192.168.1.28:8091/openid/userinfo/?access_token=82b35f3d810f4cf49dd7a52d4b22a594
- 【百度域】,刷新token
curl -X POST \ -H "Cache-Control: no-cache" \ -H "Content-Type: application/x-www-form-urlencoded" \ "http://192.168.1.28:8091/openid/token/" \ -d "client_id=717771" \ -d "grant_type=refresh_token" \ -d "refresh_token=0bac2d80d75d46658b0b31d3778039bb" -d "client_secret=1ac931638624e5d8ae002aaeaec4302031db92e7451edf36e0d008c9"
- 【百度域】,初始訪問服務(wù)结胀,無授權(quán)碼赞咙,無access token
- 登出訪問步驟
- 【百度域】,瀏覽器訪問百度域退出
http://www.baidu.com/logout
- 【CAS域】暮芭,重定向?yàn)g覽器到CAS域鹿驼,攜帶CAS域session id
http://192.168.1.28:8091/acconts/logout
- 【百度域】,瀏覽器訪問百度域退出
webSSO
- 適合本地資源和互聯(lián)網(wǎng)融合,local辕宏, internet and cloud infrastructures
CAS
- CAS協(xié)議流程,基礎(chǔ)模式
- TGT (ticket granting ticket):user name, TGC...
- TGT 的存活周期默認(rèn)為 120 分鐘
- TGC(ticket granting cookie)
- TGC 是用戶持有對自己身份信息的一種憑據(jù)
- TGC 是 CAS Server 通過 SSL 方式發(fā)送給終端用戶
- ST(service ticket)
- 在一段時(shí)間內(nèi)失效畜晰,存活周期默認(rèn)為5分鐘
- ST 只能使用一次
- ST 是基于隨機(jī)數(shù)生成的
- TGT (ticket granting ticket):user name, TGC...
- 瀏覽器訪問應(yīng)用A(CAS client)
- CAS client發(fā)現(xiàn)無ST,無session,重定向到CAS server
- 用戶完成登陸認(rèn)證
- 用戶登陸
- CAS server生成TGT對象瑞筐,加入cookie
- 分配ST,加入cookie
- 重定向回應(yīng)用(CAS client)凄鼻,帶TGC, ST
- 應(yīng)用CAS client驗(yàn)證(ST,TGC)
- CAS server驗(yàn)證ST,返回username如成功
- CAS client建立用戶session
- CAS協(xié)議流程,代理模式
- PGT, 是 CAS Client 端持有的對用戶身份信息的一種憑據(jù)
CAS Vs OpenIDConnect
- CAS不支持OAuth2. Fackbook, Google, Yahoo采用OAuth2做認(rèn)證, 而且目前85%認(rèn)證系統(tǒng)采用OAuth2
- 大部分采用OAuth2的系統(tǒng)將來會采用OpenIDConnect
- CAS缺失很多功能块蚌,不支持feature
- 動態(tài)client注冊闰非,發(fā)現(xiàn)
- 用戶claim, client claim
- Even SAML support is weak
- CAS實(shí)現(xiàn)多步驟認(rèn)證困難,大部分是基于用戶名/口令方式
- 結(jié)論
如果可能盡量用OpenIDConnect,在過度階段可以采用SAML方案從CAS到OpenIDConnect匈子。
Conclusion
Like the little ant, OpenID Connect has high hopes. Where possible, use it. Make sure developers understand the roadmap for your organization: your domain, like all the other domains on the Internet, will adopt OpenID Connect. Use SAML to fill in the gaps until all the OpenID Connect libraries and web server plugins are available. SAML is going to be around much longer than CAS, so its a better bridge solution. Use CAS only as a last resort. You should require products and software that supports the identity integration method that align with your roadmap. Be flexible…using CAS is better than the app storing its own passwords. However, realize that this application will probably never support the two factor authentication services available in OAuth2 and SAML. There are many “good” legacy SSO protocols, don’t forget Siteminder in the Enterprise world… however, if you’re faced with the situation… try NOT TO CAS.