av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

springboot+jwt+springSecurity微信小程序授權(quán)登錄問題

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

場(chǎng)景重現(xiàn):1.微信小程序向后臺(tái)發(fā)送請(qǐng)求 ——而后臺(tái)web采用的springSecuriry沒有token生成,就會(huì)攔截請(qǐng)求,,所以小編記錄下這個(gè)問題

微信小程序授權(quán)登錄問題思路

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

參考文章

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

總的來說的

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

springSecurity的原來的登錄過濾器UsernamePasswordAuthenticationFilter

springboot+jwt+springSecurity微信小程序授權(quán)登錄問題

采用賬戶+密碼的形式

springboot+jwt+springSecurity微信小程序授權(quán)登錄問題

說明我微信小程序這里很有可能不適用要升級(jí),因?yàn)槲⑿判〕绦虿捎胦penid的形式登錄,而沒有password

用戶認(rèn)證

需要結(jié)合JWT來實(shí)現(xiàn)用戶認(rèn)證,第一步登錄成功后如何頒發(fā)token。

關(guān)鍵點(diǎn)

使用cn.hutool.http請(qǐng)求第三方數(shù)據(jù)

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

說明:請(qǐng)求第三方數(shù)據(jù)時(shí),需要授權(quán)。

第三方(微信小程序)會(huì)給到appid和secret,請(qǐng)求攜帶appid和secret獲取一個(gè)token和expires,又了token就又了操作第三方數(shù)據(jù)的權(quán)限。

每次操作第三方數(shù)據(jù)時(shí)就需要攜帶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;/** * 用戶認(rèn)證通過的處理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響應(yīng)給前端 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)); }}總結(jié)

發(fā)現(xiàn)微信小程序和后臺(tái)使用一個(gè)項(xiàng)目的話,會(huì)有 不能使用多個(gè)WebSecurityConfig這個(gè)錯(cuò)誤,暫時(shí)只想到這里了

到此這篇關(guān)于springboot+jwt+springSecurity微信小程序授權(quán)登錄問題的文章就介紹到這了,更多相關(guān)springboot+jwt+springSecurity微信小程序授權(quán)登錄內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: 微信
相關(guān)文章:
主站蜘蛛池模板: 91免费看片 | 国产乱码一二三区精品 | 青青草原综合久久大伊人精品 | 久艹av| 蜜桃综合在线 | 成人av大全 | 罗宾被扒开腿做同人网站 | 欧美一级二级视频 | 欧美日韩视频在线第一区 | 欧美成人一区二区 | 毛片综合 | 日韩av一区在线观看 | 色天堂影院| 黄色网页在线观看 | 免费观看一级特黄欧美大片 | 青青久久 | 欧美一级二级视频 | 精品亚洲一区二区三区 | 男女羞羞在线观看 | 日韩av一区二区在线 | 中文字幕视频在线 | 国产精品久久国产精品 | 欧美一级欧美一级在线播放 | 日韩在线小视频 | www.青青草 | 日韩欧美在线一区 | 亚洲精品18| 成人免费淫片aa视频免费 | 日韩一区二区在线视频 | 国产成人精品免费视频 | 日韩一区二区精品 | 国产日本精品视频 | 亚洲精品视频播放 | 综合一区 | 国产成人精品一区二区在线 | 免费a v网站 | 国产一区久久久 | 日本成人三级电影 | 国产亚洲网站 | 亚洲高清视频在线观看 | 日韩精品在线观看免费 |