首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在一个使用护照-本地作为auth策略的特快应用程序中没有保护的端点。

在一个使用护照-本地作为auth策略的特快应用程序中没有保护的端点。
EN

Stack Overflow用户
提问于 2015-08-10 08:10:18
回答 2查看 246关注 0票数 1

我想知道如何创建端点(GET、POST等)不需要任何身份验证就可以访问的。这是我的密码:

代码语言:javascript
复制
router.use(AuthenticationManager.ensureAuthenticated());

router.use('/', require('./index'));
router.use('/path-1', require('./path1'));
router.use('/path-2', require('./path2'));

所有端点都将享受Authentication Manager。如何仅在./path1./path2中的某些端点中禁用该身份验证管理器?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-10 08:25:12

这样做的常规方法是在AuthenticationManager中间件之前定义这些端点:

代码语言:javascript
复制
router.use('/path-1/unprotected', require('./path1'));
router.use('/path-2/unprotected', require('./path2'));
router.use(AuthenticationManager.ensureAuthenticated());

这取决于path1.jspath2.js到底导出了什么,如果它按原样工作,或者您需要进行一些重写。

票数 1
EN

Stack Overflow用户

发布于 2015-08-10 08:48:55

可以通过以下方法对特定端点使用身份验证:

代码语言:javascript
复制
app.post('/profile', AuthenticationManager.ensureAuthenticated , userController.getUserProfile);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31914611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档