spring security oauth2 implicit模式

前面三篇文章講了client credentials、password以及authorization code受權模式,本文就來說一下implicit模式。html

implicit模式

該模式直接在瀏覽器中向認證服務器申請令牌,無需通過client端的服務器,跳過了"受權碼"這個步驟,全部步驟在瀏覽器中完成,直接在回調url中傳遞令牌。前端

適合直接在前端應用獲取token的應用spring

步驟跟authorization code相似,只不過少了受權碼:瀏覽器

  • 在瀏覽器向認證服務器請求token
  • 用戶登陸(若是以前沒有登錄的話)
  • 用戶受權
  • 受權完直接跳轉到redirectUri並在url中攜帶token

實例

請求token

http://localhost:8080/oauth/authorize?response_type=token&client_id=demoApp&redirect_uri=https://baidu.com
  • 注意,這裏response_type=token
  • 無需傳遞client secret,傳遞client_id只是爲了驗證在auth server配置的redirect_uri是否一致
  • redirect_uri中若是攜帶參數,則最好對url編碼再做爲參數傳遞過去

回調成功

http://localhost:8081/callback#access_token=41f78007-e2ec-4978-9beb-a830b638d4d8&token_type=bearer&expires_in=1199&scope=all

能夠發現直接在url中攜帶了access_token等信息服務器

固然了,使用了implicit模式,其實就不必使用spring security oauth2的client模塊了,由於直接走瀏覽器模式。編碼

doc

相關文章
相關標籤/搜索