Spring Security Oauth2 (一) 整体流程介绍

整体流程
在这里插入图片描述

1.用户授权

用户点击(微信授权)按钮既发送get请求到下面的链接,跳转到授权页面

http://localhost:8080/oauth/authorize?response_type=code&client_id=client&redirect_uri=http://www.baidu.com&scope=all

跳转到登录页面,这个是有因为未登录授权服务器,所以需要登录.(就像我们在使用微信扫码授权时,首先要登录微信一样,如果不登录微信就无法授权.可以先登录,这样就会弹出登录页面了)
http://localhost:8080/login
在这里插入图片描述

在这里插入图片描述
浏览器,重定向到https://www.baidu.com/?code=mfB14e获得授权码

2.申请令牌

携带授权码,访问授权服务器,获得access_token
http://localhost:8080/oauth/token
发送参数与后端的对应关系
1)Basic Auth 认证
username|.withClient
password|.secret
2)post传参
client_id|.withClient
redirect_uri|.redirectiUris
scope|.scope
grant_type|.authorizedGrantTypes
code|无,网页返回
在这里插入图片描述

3.获得资源

通过access_token来访问资源服务器,获得资源(既用户名之类的,注意这里不是客户端(我们本来要访问的)的资源,而是认证服务器的资源)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/claroja/article/details/114553407