除非在JWT中如何使用通配符?

编程入门 行业动态 更新时间:2024-10-11 19:25:04
本文介绍了除非在JWT中如何使用通配符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用express-jwt来保护我的节点应用程序,并且想知道如何在除非参数中使用通配符.我的工作代码如下,我真正想做的是打开对所有以'/login'开头的路径的访问,因此我不必列出每个资源.当我在不受保护的数组中添加'/login *'时,最终会以401/未经授权的方式阻止/login.

I'm using express-jwt to secure my node application, and am wondering how I can use a wildcard in the unless parameter. My working code is below, what I'd really like to do is open up access to anything that has a path starting with '/login' so I don't have to list every single resource. When I add '/login*' to the unprotected array it ends up blocking /login with a 401/unauthorized.

作品:

// routes open to all var unprotected = [ '/login', '/login/app/main.js', 'favicon.ico' ]; // configure jwt var jwtCheck = jwt({ secret: new Buffer(config.get('auth0.secret'), 'base64'), audience: config.get('auth0.clientid') }); // insert jwt middleware app.use( jwtCheck.unless({path: unprotected}) );

不起作用:

// routes open to all var unprotected = [ '/login*', 'favicon.ico' ]; // configure jwt var jwtCheck = jwt({ secret: new Buffer(config.get('auth0.secret'), 'base64'), audience: config.get('auth0.clientid') }); // insert jwt middleware app.use( jwtCheck.unless({path: unprotected}) );

推荐答案

正则表达式必须在引号之外:

The regexp needs to exist outside the quotes:

var unprotected = [ /\/login*/, /favicon.ico/ ];

请注意,此时除非使用Express,除非您不能在同一配置数组中混合使用regexp和字符串,这就是第二个参数需要使用正斜杠而不是引号的原因.

Note that at this time with express-unless you can't mix regexp and strings in the same config array, which is why the second argument needs to have forward slashes instead of quotes.

更多推荐

除非在JWT中如何使用通配符?

本文发布于:2023-11-23 01:10:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通配符   如何使用   JWT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!