1 Star 0 Fork 17

jun / spring-oauth2-demo

forked from 火星人 / spring-oauth2-demo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

spring-oauth2-demo

spring boot oauth2的使用例子,基于jwt

sso 使用方式

  1. 启动sso-auth-server
  2. 启动sso-auth-client
  3. 访问 http://localhost:8085/user 注意:sso再域名相同时浏览器会使用同一个cookie导致页面一直再login页重定向,所以需要把认证服务器和sso客户端设置为不同域名下启动。

resource server 使用方式

  1. 启动sso-auth-server
  2. 启动sso-auth-resource
  3. 浏览器访问 http://localhost:8080/oauth/authorize?client_id=testclient&response_type=code&scope=test&redirect_uri=http://127.0.0.1:8086 输入验证信息后会返回对应的code (例如:http://127.0.0.1:8086/?code=j6BgIT )
  4. 使用post请求获取token,把上一步获取的code(j6BgIT)放入请求参数 http://localhost:8080/oauth/token?code=j6BgIT&grant_type=authorization_code&client_id=testclient&redirect_uri=http://127.0.0.1:8086
  5. 使用获取的token访问资源服务器,例如 http://localhost:8086/user?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MjIzNTg4ODksInVzZXJfbmFtZSI6ImFkbWluIiwiYXV0aG9yaXRpZXMiOlsiUk9MRV90ZXN0Il0sImp0aSI6IjMxNmJjNWIyLTBlYzctNDI4OC04NTc0LWM3OTY2MTllZGE0MCIsImNsaWVudF9pZCI6InRlc3RjbGllbnQiLCJzY29wZSI6WyJ0ZXN0Il19.6Rplh9LQVJ1eZRXFcGnO9GnHkmDgsIje_nOViQRgQlE

生成jwt需要的证书

1.生产jks证书

keytool -genkeypair -alias ssotest -keyalg RSA -keypass ssopass -keystore sso.jks -storepass ssostorepass

2.导出public key, 只取public这段

keytool -list -rfc --keystore mytest.jks | openssl x509 -inform pem -pubkey  
MIT License Copyright (c) 2018 shenluw Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/bjdaijun/spring-oauth2-demo.git
git@gitee.com:bjdaijun/spring-oauth2-demo.git
bjdaijun
spring-oauth2-demo
spring-oauth2-demo
master

搜索帮助