Authentication 身份验证和授权

Authentication 身份验证和授权,authentication,express,authorization,feathersjs,Authentication,Express,Authorization,Feathersjs,我已经使用创建了一个应用程序。我已经使用这个应用程序一段时间了。它成功地托管了一个博客和一些其他网页。然而,我现在已经到了需要保护我的一些路线的地步。例如,我希望为我的管理活动(/admin)提供一个路由,但我只希望特定用户具有访问权限 我知道我需要使用和授权组件。然而,在这个时候,我被困在授权上。我的目标是通过Google使用OAuth进行身份验证。然而,为了克服我的身份验证难题,我很乐意使用硬编码的用户名/密码来锁定/admin路由(不,它没有部署) 目前,我有 const app = fe

我已经使用创建了一个应用程序。我已经使用这个应用程序一段时间了。它成功地托管了一个博客和一些其他网页。然而,我现在已经到了需要保护我的一些路线的地步。例如,我希望为我的管理活动(/admin)提供一个路由,但我只希望特定用户具有访问权限

我知道我需要使用和授权组件。然而,在这个时候,我被困在授权上。我的目标是通过Google使用OAuth进行身份验证。然而,为了克服我的身份验证难题,我很乐意使用硬编码的用户名/密码来锁定
/admin
路由(不,它没有部署)

目前,我有

const app = feathers();
const routes = require('./routes');

app.configure(configuration(path.join(__dirname, '..')));

app.use(compress())
  .options('*', cors())
  .use(cors())
  .use(favicon( path.join(app.get('public'), 'favicon.ico') ))
  .use('/public', serveStatic(app.get('public'), staticFileSettings ))
  .use(bodyParser.json())
  .use(bodyParser.urlencoded({ extended: true }))
  .configure(routes)    
  .configure(hooks())
  .configure(rest())
  .configure(socketio())
  .configure(services)
  .configure(middleware)
  .configure(authentication())
;

// Setup the authentication strategy.
app.authenticate({
  type: 'local',
  'email': 'admin@feathersjs.com',
  'password': 'admin'
}).then(function(result){
  console.log('Authenticated!', result);
}).catch(function(error){
  console.error('Error authenticating!', error);
});
我的问题是,当我在app.authenticate中添加代码块时,我在启动我的app.authenticate时会出现一个错误。错误显示:

TypeError: app.authenticate is not a function
如果我删除
app.authenticate(…)我的应用程序启动正常,但没有锁定任何内容。在我的./routes/index.js文件中,我有:

app.use('/admin', function(req, res) {
    res.render('admin/index.html', {});
});    

这样,渲染就很好了。它不仅仅限于经过身份验证和授权的用户。我错过了什么?首先,我试图了解如何通过
应用程序验证
错误。

为了保护路由不被未经授权的访问,您需要在执行
feathers生成验证时安装的
feathers验证
包提供

下面是验证
/admin
路由的示例

const auth = require('feathers-authentication');

app.use(
  '/admin',
  auth.express.authenticate('jwt'), // <-- this is a strategy, can local/jwt... etc
  (req, res, next) => {
    console.log("Request for '/admin'...");
    res.render('admin');
  }
);
const auth=require('features-authentication');
应用程序使用(
“/admin”,
auth.express.authenticate('jwt'),//{
log(“请求“/admin”…”);
res.render(“管理”);
}
);

为了保护路由不受未经授权的访问,您需要在执行
羽毛生成身份验证时安装的
羽毛身份验证
软件包提供

下面是验证
/admin
路由的示例

const auth = require('feathers-authentication');

app.use(
  '/admin',
  auth.express.authenticate('jwt'), // <-- this is a strategy, can local/jwt... etc
  (req, res, next) => {
    console.log("Request for '/admin'...");
    res.render('admin');
  }
);
const auth=require('features-authentication');
应用程序使用(
“/admin”,
auth.express.authenticate('jwt'),//{
log(“请求“/admin”…”);
res.render(“管理”);
}
);

您想做什么
app.authenticate
仅在客户端(
feathers authentication/client
)上可用。最终,我试图阻止未经授权的用户访问路由
/admin
上的视图。据我所知,我需要做两件事:1)验证用户身份(我想通过Google的OAuth登录进行验证)和2)授权用户。上面的问题解释了我是如何被困在#1.你想做什么
app.authenticate
仅在客户端(
feathers authentication/client
)上可用。最终,我试图阻止未经授权的用户访问路由
/admin
上的视图。据我所知,我需要做两件事:1)验证用户身份(我想通过Google的OAuth登录进行验证)和2)授权用户。上面的问题解释了我是如何被困在#1上的。