加密技术
对称加密
非对称加密
不可逆加密算法
base64编码
token认证
Token身份验证
服务端验证用户身份的一种安全技术
- 服务端生成的
- 验证身份
工作原理
前端 后端
登录请求->用户名密码 生成token
本地存储 <-token
其它请求->token 验证token
<-数据
JWT技术
1. 前端
axios网络库 拦截器统一设置token到请求头authroiation
<script src='./lib/axios.min.js'>
<script>
默认axios实例
axios({method:'get',url:''}).then(res=>{}).catch(err=>{})
let myAxios = axios.create({baseURL:'http//ip:port'})
myAxios.intercepter.request.use((config)=>{
let token = Cookies.get('TOKEN')
if(token){
config.headers.common['authoriaton'] = token
}
},(error)=>{
Promise.reject(error)
})
1. <script src='./lib/axios.min.js'>
2. <script src='./lib/request.js'>
3. myAxios({method:'get',url:'/goods/list'}).then(res=>{}).catch(err=>{})
</script>
2. app.all('/*',function(req,res,next){
过滤不需要验证请求
let token = req.headers.authriation
})