
正文
使用公钥私钥加密实现单点登录(SSO)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Oauth2+Gateway+springcloud+springcloud-alibaba-nacos+jwt ,使用公钥私钥加密实现单点登录(OSS)
github地址点这里
注意事项GET: http://localhost:9090/oauth/authorize?client_id=client_id&response_type=code获取授权码,因为代码里写了重定向等参数,这里就不需要写了,测试时候发现,如果代码里不写重定向地址,在这里写重定向地址当做参数,会报错.具体原因暂时不明
获取token,POST: http://127.0.0.1:9090/oauth/token 需要在 Basic Auth 中添加客户端账号和密码(相当于把账号和密码进行base64编码后,在前面拼接Basic ,放入headers,(即Authorization:Basic [base64码]), body中添加 grant_type:authorization_code, code:上一步中得到的code
刷新token,POST: http://127.0.0.1:9090/oauth/token 需要在 Basic Auth 中添加客户端账号和密码(相当于把账号和密码进行base64后,在前面拼接Basic ,放入headers,(即Authorization:Basic [base64码]),body中添加 grant_type:refresh_token, refresh_token:上一步中得到的refresh_token
POST: http://127.0.0.1:9091 请求资源带上需要token,headers中添加 Authorization:Bearer [上一步得到的access_token]
校验令牌: http://localhost:9090/oauth/check_token?token= [access_token]
密码模式
- http://localhost:9090/oauth/token?username=xxx&password=xxx&grant_type=password&scope=select&client_id=client_id&client_secret=secret
client模式
- http://localhost:9090/oauth/token?grant_type=client_credentials&scope=select&client_id=client_id&client_secret=secret
使用令牌
- 携带
access_token参数访问受保护的资源,http://localhost:9090/xxx/xx?access_token=xxxxxxxxxxx
GET: http://localhost:9090/oauth/authorize?client_id=client_id&response_type=code获取授权码,因为代码里写了重定向等参数,这里就不需要写了,测试时候发现,如果代码里不写重定向地址,在这里写重定向地址当做参数,会报错.具体原因暂时不明
获取token,POST: http://127.0.0.1:9090/oauth/token 需要在 Basic Auth 中添加客户端账号和密码(相当于把账号和密码进行base64编码后,在前面拼接Basic ,放入headers,(即Authorization:Basic [base64码]), body中添加 grant_type:authorization_code, code:上一步中得到的code
刷新token,POST: http://127.0.0.1:9090/oauth/token 需要在 Basic Auth 中添加客户端账号和密码(相当于把账号和密码进行base64后,在前面拼接Basic ,放入headers,(即Authorization:Basic [base64码]),body中添加 grant_type:refresh_token, refresh_token:上一步中得到的refresh_token
POST: http://127.0.0.1:9091 请求资源带上需要token,headers中添加 Authorization:Bearer [上一步得到的access_token]
校验令牌: http://localhost:9090/oauth/check_token?token= [access_token]
密码模式
- http://localhost:9090/oauth/token?username=xxx&password=xxx&grant_type=password&scope=select&client_id=client_id&client_secret=secret
client模式
- http://localhost:9090/oauth/token?grant_type=client_credentials&scope=select&client_id=client_id&client_secret=secret
使用令牌
- 携带
access_token参数访问受保护的资源,http://localhost:9090/xxx/xx?access_token=xxxxxxxxxxx







