2

Sails アプリを PaaS にデプロイしました。簡単なパスワードで保護して、ステージング サーバーに誰もアクセスできないようにしたいと考えています。

それを行う最も簡単な方法は何ですか?

http-authのように見えますが、ドキュメントはExpressJSの実装方法を説明していますが、SailsJSでは見つかりませんapp.use()

私が試したこと

私のpolicies.jsファイルで

module.exports.policies = {

  // '*': true,
    '*': require('http-auth').basic({
      realm: 'admin area'
    }, function customAuthMethod (username, password, onwards) {
      return onwards(username === "Tina" && password === "Bullock");
    }),

につながる

info: Starting app...

error: Cannot map invalid policy:  { realm: 'admin area',
  msg401: '401 Unauthorized',
  msg407: '407 Proxy authentication required',
  contentType: 'text/plain',
  users: [] }

また、ポリシーはビューには適用できないようですが、アクションにはのみ適用できます...

4

2 に答える 2

3

Reason

I think your problem comes from this page http://sailsjs.org/documentation/concepts/middleware that uses incorrect pattern for http-auth module.

Solution

SailsJS uses connect/express style middleware, so the only thing that you need to do is to provide proper middleware to it.

// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
        realm: "Simon Area."
    }, function (username, password, callback) { // Custom authentication.
        callback(username === "Tina" && password === "Bullock");
    }
});

// Use proper middleware.
module.exports.policies = {
    '*': auth.connect(basic)
    ...

Todo

Makes sense to notify SailsJS team, so they remove wrong sample.

Related links

于 2016-06-04T19:25:59.487 に答える