本项目是一个基于 Spring Boot、Spring Cloud、Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目。
@作者:Sheldon 地址:https://github.com/zhangxd1989
该项目包含 8 个服务
mvn clean package
打包项目及 Docker 镜像 docker-compose up -d
启动所有项目 127.0.0.1 registry config monitor rabbitmq auth-service
访问 http://localhost:8761/ 默认账号 user,密码 password
访问 http://localhost:8040/ 默认账号 admin,密码 admin
访问 http://localhost:9411/ 默认账号 admin,密码 admin
Docker 启动访问 http://localhost:15673/ 默认账号 guest,密码 guest(本地 rabbit 管理系统默认端口15672)
获取 Token
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "password=password&username=anil&grant_type=password&scope=read%20write"
返回如下格式数据:
{ "access_token": "eac56504-c4f0-4706-b72e-3dc3acdf45e9", "token_type": "bearer", "refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb", "expires_in": 3599, "scope": "read write" }
使用 access token 访问 service a 接口
curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svca
返回如下数据:
svca-service (172.18.0.8:8080)===>name:zhangxd svcb-service (172.18.0.2:8070)===>Say Hello
使用 access token 访问 service b 接口
curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svcb
返回如下数据:
svcb-service (172.18.0.2:8070)===>Say Hello
使用 refresh token 刷新 token
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "grant_type=refresh_token&refresh_token=da1007dc-683c-4309-965d-370b15aa4aeb"
返回更新后的 Token:
{ "access_token": "63ff57ce-f140-482e-ba7e-b6f29df35c88", "token_type": "bearer", "refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb", "expires_in": 3599, "scope": "read write" }
刷新配置
curl -X POST -vu user:password http://localhost:8888/bus/refresh
https://github.com/souyunku/spring-boot-cloud.git