接上文spring cloud下基于oauth2認證授權的實現,我們將基于spring cloud實現oauth2的注銷功能。
1 增加自定義注銷endpoint
所謂注銷只需將access_token和refresh_token失效即可,我們模仿org.springframework.security.oauth2.provider.endpoint.tokenendpoint寫一個使access_token和refresh_token失效的endpoint:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@frameworkendpoint public class revoketokenendpoint { @autowired @qualifier ( "consumertokenservices" ) consumertokenservices consumertokenservices; @requestmapping (method = requestmethod.delete, value = "/oauth/token" ) @responsebody public string revoketoken(string access_token) { if (consumertokenservices.revoketoken(access_token)){ return "注銷成功" ; } else { return "注銷失敗" ; } } } |
2 注銷請求方式
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.wisely.top/2017/07/25/spring-cloud-oauth2-logout/