1.搭建最最最基礎的spring security oauth2
項目地址github:https://github.com/liangjinquan17/spring-security-demo
1.spring boot導包
image.png
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.編寫接口
image.png
3.調(diào)用
啟動項目,項目端口默認是8080;調(diào)用接口(http://localhost:8080/hello)
這時候因為我們加入了security的包募疮,默認啟動了鑒權服務
image.png
留意圖片截圖都是密碼,默認賬號是user洽糟,密碼會在項目啟動到時候生成和打印出來
4.校驗
當我們調(diào)用http://localhost:8080/hello接口的時候,會跳轉到http://localhost:8080/login要求先登錄。輸入賬號:user 密碼:上面截圖坤溃,校驗成功后返回接口數(shù)據(jù).
image.png
image.png
第一步配置和啟動完畢拍霜,后面我們可以加入oauth的授權功能了。