亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

springboot+jwt+springSecurity微信小程序授權登錄問題

瀏覽:145日期:2022-06-16 11:24:29

場景重現:1.微信小程序向后臺發送請求 ——而后臺web采用的springSecuriry沒有token生成,就會攔截請求,,所以小編記錄下這個問題

微信小程序授權登錄問題思路

參考網上一大堆資料 核心關鍵字: 自定義授權+鑒權 (說的通俗就是解決辦法就是改造springSecurity的過濾器)

參考文章

https://www.jb51.net/article/204704.htm

總的來說的

通過自定義的WxAppletAuthenticationFilter替換默認的UsernamePasswordAuthenticationFilter,在UsernamePasswordAuthenticationFilter中可任意定制自己的登錄方式。

springSecurity的原來的登錄過濾器UsernamePasswordAuthenticationFilter

springboot+jwt+springSecurity微信小程序授權登錄問題

采用賬戶+密碼的形式

springboot+jwt+springSecurity微信小程序授權登錄問題

說明我微信小程序這里很有可能不適用要升級,因為微信小程序采用openid的形式登錄,而沒有password

用戶認證

需要結合JWT來實現用戶認證,第一步登錄成功后如何頒發token。

關鍵點

使用cn.hutool.http請求第三方數據

<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.5.16</version> </dependency>

說明:請求第三方數據時,需要授權。

第三方(微信小程序)會給到appid和secret,請求攜帶appid和secret獲取一個token和expires,又了token就又了操作第三方數據的權限。

每次操作第三方數據時就需要攜帶token。

package com.shbykj.springboot.wx.security.handler;import cn.hutool.http.ContentType;import com.alibaba.fastjson.JSON;import com.shbykj.springboot.wx.enums.ConstantEnum;import com.shbykj.springboot.wx.security.WxAppletAuthenticationToken;import com.shbykj.springboot.wx.util.JwtTokenUtils;import org.apache.http.entity.ContentType;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.security.core.Authentication;import org.springframework.security.web.authentication.AuthenticationSuccessHandler;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.util.HashMap;import java.util.Map;/** * 用戶認證通過的處理handler */public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler { @Autowired private JwtTokenUtils jwtTokenUtils; @Override public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { // 使用jwt管理,所以封裝用戶信息生成jwt響應給前端 String token = jwtTokenUtils.generateToken(((WxAppletAuthenticationToken)authentication).getOpenid()); Map<String, Object> result = new HashMap<>(); result.put(ConstantEnum.AUTHORIZATION.getValue(), token); httpServletResponse.setContentType(ContentType.JSON.toString()); httpServletResponse.getWriter().write(JSON.toJSONString(result)); }}總結

發現微信小程序和后臺使用一個項目的話,會有 不能使用多個WebSecurityConfig這個錯誤,暫時只想到這里了

到此這篇關于springboot+jwt+springSecurity微信小程序授權登錄問題的文章就介紹到這了,更多相關springboot+jwt+springSecurity微信小程序授權登錄內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: 微信
相關文章:
主站蜘蛛池模板: 国产不卡视频在线播放 | 中文精品久久久久国产不卡 | 老妇xxxxbbbb | 国产三级图片 | 免费在线看黄网址 | 色综合网站国产麻豆 | 亚洲精品免费在线观看 | 精品视频专区 | 免费黄色网址大全 | 免费福利视频在线观看 | 亚洲自拍偷拍视频 | 久久中文字幕网 | 亚洲自偷自偷精品 | 日本免费久久久久久久网站 | 999yy成年在线视频免费看 | pans国产大尺度私密拍摄视频 | www.91视频.com| 尤物在线观看视频 | 成年网站视频在线观看 | 一区二区三区四区视频在线 | 女人18毛片a级毛片免费视频 | 国产九九热视频 | 久久精品在线免费观看 | 青青草手机在线观看 | 色屁屁在线 | 国产tv在线| 日本一线一区二区三区免费视频 | 欧美日韩国产高清一区二区三区 | 亚洲欧洲视频在线观看 | 成人一区专区在线观看 | 精品国产亚一区二区三区 | 久久99精品视频 | 亚洲美女在线观看 | a级无毛片 | 高清欧美日韩一区二区三区在线观看 | 亚洲成a人片在线观看中文 亚洲成a人片在线观看中文动漫 | 欧美日韩大尺码免费专区 | 国产亚洲欧美另类第一页 | 加勒比久草 | 1000部又爽又黄无遮挡的视频 | 中文字幕国产欧美 |