博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JWT能够干什么,不应该干什么?
阅读量:7110 次
发布时间:2019-06-28

本文共 2067 字,大约阅读时间需要 6 分钟。

http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-for-sessions/

 

At the start of this article, I said that there are good usecases for JWT, but that they're just not suitable as a session mechanism. This still holds true; the usecases where JWT is particularly effective are typically usecases where they are used as a single-use authorization token.

From the :

JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties. [...] enabling the claims to be digitally signed or integrity protected with a Message Authentication Code (MAC) and/or encrypted.

In this context, "claim" can be something like a 'command', a one-time authorization, or basically any other scenario that you can word as:

Hello Server B, Server A told me that I could <claim goes here>, and here's the (cryptographic) proof.

For example, you might run a file-hosting service where the user has to authenticate to download their files, but the files themselves are served by a separate, stateless "download server". In this case, you might want to have your application server (Server A) issue single-use "download tokens", that the client can then use to download the file from a download server (Server B).

When using JWT in this manner, there are a few specific properties:

  • The tokens are short-lived. They only need to be valid for a few minutes, to allow a client to initiate the download.
  • The token is only expected to be used once. The application server would issue a new token for every download, so any one token is just used to request a file once, and then thrown away. There's no persistent state, at all.
  • The application server still uses sessions. It's just the download server that uses tokens to authorize individual downloads, because it doesn't need persistent state.

As you can see here, it's completely reasonable to combine sessions and JWT tokens - they each have their own purpose, and sometimes you need both. Just don't use JWT for persistentlong-lived data.

转载于:https://www.cnblogs.com/kidsitcn/p/7910616.html

你可能感兴趣的文章
BZOJ 2229 最小割
查看>>
BZOJ 3546 Life of the Party (二分图匹配-最大流)
查看>>
Switch Between Gnome And KDE Desktops In Ubuntu Or Kubuntu
查看>>
VIM Quick Reference Card
查看>>
VS2010总报错:是否缺少程序集引用?
查看>>
计算机十二种常用密码破解法
查看>>
编程算法 - 最长公共子序列(LCS) 代码(C)
查看>>
红蚂蚁咬伤案
查看>>
WIN7 右下角音量图标不见了
查看>>
从源代码分析Android-Universal-Image-Loader的缓存处理机制
查看>>
也让盲人拥抱互联网
查看>>
清除浮动,浮动元素的高度自适应问题
查看>>
【反传销】传销故事总结—如何尽可能保护自身和家人安全
查看>>
pyqt4学习之一:搭建环境和入门
查看>>
162. Find Peak Element
查看>>
天津政府应急系统之GIS一张图(arcgis api for flex)讲解(三)显示地图坐标系模块...
查看>>
MFC程序消息处理的顺序
查看>>
PHP+tcpdf的生成
查看>>
linux设置iptables防火墙的详细步骤(centos防火墙设置方法)
查看>>
二十六个月Android学习工作总结【转】
查看>>