springboot2整合OAuth2.0认证明例

springboot2整合OAuth2.0实例java

代码实例放到:https://github.com/haoxiaoyong1014/springboot-examplesgit

springboot-oauth2 包括: springboot-oauth2-authorization-server(认证服务)和springboot-oauth2-resource-server(资源服务) springBoot版本:2.0.1.RELEASEgithub

受权码模式:spring

  • 访问认证服务器springboot

  • http://localhost:8888/oauth/authorize?response_type=code&client_id=merryyou&redirect_uri=https://github.com/haoxiaoyong1014?tab=repositories&scope=all服务器

  • 是否赞成并受权app

image

  • 假设用户给予受权,认证服务器将用户导向客户端事先指定的"重定向URI"(redirection URI),同时附上一个受权码(code)。

image

  • 拿到这个受权码(code)去交换 access_token
    • 认证服务器核对了受权码和重定向URI,确认无误后,向客户端发送访问令牌(access token)和更新令牌(refresh token)。

image

  • 还有一点须要说明 在请求头中处理了加入 Content-Type : application/x-www-form-urlencoded 还要加入:Authorization:Basic bWVycnl5b3U6bWVycnl5b3U=
    其中 Authorization的值是 CLIENT_ID 和 CLIENT_SECRET Base64加密获得 详细内容在 springboot-examples/springboot-oauth2-authorization-server/src/test/java/cn/merryyou/security/SpringBoot2Oauth2Test.java 中

image
相关文章
相关标签/搜索