{"repo":"Jirath-Liu/shiro-jwt-wx","free":true,"listed":false,"github":"https://github.com/Jirath-Liu/shiro-jwt-wx","clone":"git clone https://github.com/Jirath-Liu/shiro-jwt-wx.git","description":"微信小程序登录，使用shiro+JWT(Token）","language":"Java","stars":19,"topics":["shiro","jwt-token","redis"],"license":null,"category":"databases-storage","readme_excerpt":"使用Shiro+JWT完成的微信小程序的登录 你也可以在csdn中查看讲解https://blog.csdn.net/weixin 44494373/article/details/105420417 微信小程序用户登陆，完整流程可参考下面官方地址，本例中是按此流程开发 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html 你需要了解的点 微信小程序的登录流程 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html Shiro的基础知识 https://shiro.apache.org/10-minute-tutorial.html JWT以及Token https://jwt.io/introduction/ 项目的流程 1. 调用 wx.login() 获取 临时登录凭证code ，并回传到开发者服务器。 2. 访问login接口，并将code给后台 3. 被JwtShirioFilter拦截(在shiro配置中配置的)，查看有没有token在Header 4. 有则自动执行登录操作，核实token的合法性，并刷新token 5. 没有则被controller拦截进入service中进行登录 6. 使用code获取用户信息，默认初始化了一些信息（可以修改的） 7. 生成token（会存至redis） 8. 返回token 本项目的结构 项目分包： 1. conf 项目的配置 - exceptoionconfig 配置了异常的抛出，使用@ControllerAdvice进行拦截统一处理 - jwt 包含一个jwt工具类，在使用时会与redis连接，存储、验证与生成token - shiro 是本项目配置的核心，其中关闭了session管理，使用jwt来完成验证，包含一个自定的应用于shiro的token - RestTemplateConfig 使用Spring 2. enums 包含了需要的枚举类 3. vo - wxapi 包含了一个请求微信后台需要的结果类 不可修改的模块：有JWT与Shiro的类别以及配置模块 具体实现 一、shiro基础配置 1.设置一个自己的realm进行token验证，用户登录会执行你的realm 在DefaultWebSecurityManager 中进行配置 realm是需要自己实现的，先让他在这里报错，当自己的提示也可以 2.我们需要关闭shiro的session功能 在DefaultWebSecurityManager 中进行配置 3.设置realm 我们需要定制一个realm，并且为了能够被识别，选择继承AuthorizingRealm类 需要我们完成的模块： 1. realm对请求的识别 我们的方案是验证token是否为我们定制的token 2. 审核信息 其中有对token的验证，我们做在工具类中 3. 身份/角色验证 4. 关闭密码校验加密 4.定制一个token，继承AuthenticationToken 默认的token是包含两个部分的，账号和密码（可以这样理解） 我们将这两个信息都调整为token 5.上述提到了jwt的工具类，我们实现一下 1. 因为签名最好是自己定的，以备不时之需，你也可使用jwt框架随机一个，我们从配置文件中导入进来 2. token生成模块，需要缓存r","default_branch":null,"files":null,"tree":[],"storefront":"/r/Jirath-Liu","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/Jirath-Liu/shiro-jwt-wx/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}