Zuul+OAuth2.0+JWT实战

一 代码位置

https://github.com/cakin24/spring-cloud-code/tree/master/ch8-2

二 测试

1 启动eureka-server

2 启动zuul-server

3 启动auth-server

4 启动client-a

5 浏览器输入:http://localhost:5555/client/test

Zuul+OAuth2.0+JWT实战_第1张图片

出现错误是因为还没有登录授权

6 浏览器输入:http://localhost:5555

跳转到auth-server的默认登录页面,使用admin与admin登录。

7 使用浏览器再次访问:http://localhost:5555/client/test

Zuul+OAuth2.0+JWT实战_第2张图片

头部权限信息如下:

authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NzM0MTI4MDEsInVzZXJfbmFtZSI6ImFkbWluIiwiYXV0aG9yaXRpZXMiOlsiV1JJR1RIX1dSSVRFIiwiV1JJR1RIX1JFQUQiXSwianRpIjoiZGQzZDE2YzMtM2NmZi00OGJkLTg3NmItZjI4NGE0NTE1MTUyIiwiY2xpZW50X2lkIjoienV1bF9zZXJ2ZXIiLCJzY29wZSI6WyJXUklHVEgiLCJyZWFkIl19.F0t6aIeGPZ42Tt0nxtJfgpi7FaPti1DizGDjf6HWCac

解析后为:

{"alg":"HS256","typ":"JWT"}
{"exp":1573412801,"user_name":"admin","authorities":["WRIGTH_WRITE","WRIGTH_READ"],"jti":"dd3d16c3-3cff-48bd-876b-f284a4515152","client_id":"zuul_server","scope":["WRIGTH","read"]}
FaJDHfhdjafhsdafdjkslhgaskdjfdsfhasdfjas

它们分别是jwt token的头部,荷载、签名信息

你可能感兴趣的:(微服务)