在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java  網(wǎng)絡(luò)安全  HTML/ axios如何獲取后臺(tái)spring-security+jwt生成的token?

axios如何獲取后臺(tái)spring-security+jwt生成的token?

clipboard.png

我現(xiàn)在后臺(tái)已經(jīng)正確返回了jwt token但是就是不知道如何在axios獲取這個(gè)保存在cookie中

回答
編輯回答
萌面人

解決了:
@Override

protected void successfulAuthentication(HttpServletRequest req,
                                        HttpServletResponse res,
                                        FilterChain chain,
                                        Authentication auth) throws IOException, ServletException {
    String token = Jwts.builder()
            .setSubject(((org.springframework.security.core.userdetails.User) auth.getPrincipal()).getUsername())
            .setExpiration(new Date(System.currentTimeMillis() + 60 * 60 * 24 * 1000))
            .signWith(SignatureAlgorithm.HS512, SECRET)
            .compact();
    res.addHeader("Authorization", TOKEN_PREFIX + token);
    res.setHeader("Access-Control-Expose-Headers","Authorization");//在這里添加 就OK了
}

參考:
[Axios get access to response header fields Ask Question](https://stackoverflow.com/questions/37897523/axios-get-access-to-response-header-fields)
2017年1月10日 12:59
編輯回答
何蘇葉
response.headers.Authorization
2017年8月12日 13:56