メールとパスワードを入力する必要があるフォームで認証を実装したSailsJS Webサイトがあります。 ActivityOverloard 2.0 example codeどのようにアクセストークンを実装すれば、ログインページ(sailsjs)をバイパスできますか
ログインからコピー
login: function(req, res) {
console.log("Login hehe!!");
// Try to look up user using the provided email address
User.findOne({
email: req.param('email')
}, function foundUser(err, user) {
if (err) return res.negotiate(err);
if (!user) return res.notFound();
console.log("found email");
// Compare password attempt from the form params to the encrypted password
// from the database (`user.password`)
require('machinepack-passwords').checkPassword({
passwordAttempt: req.param('password'),
encryptedPassword: user.encryptedPassword
}).exec({
error: function(err) {
console.log("There was an error with password");
return res.negotiate(err);
},
// If the password from the form params doesn't checkout w/ the encrypted
// password from the database...
incorrect: function() {
console.log("Password doesn't checkout w/ the encrypted");
return res.notFound();
},
success: function() {
console.log("Good password");
var now = new Date();
User.update(user.id, { online: true, lastLoggedIn: now }, function() {
// Store user id in the user session
req.session.me = user.id;
User.publishUpdate(user.id, {
online: true,
id: user.id,
name: user.name,
lastLoggedIn: now,
action: ' has logged in.'
});
// All done- let the client know that everything worked.
return res.ok();
});
}
});
});
私のページは今すぐログイン
myPage: function(req, res) {
if (!req.session.me) {
return res.view('login'); // not authenticated will take you to the login page
}
// It's authenticated, it runs the code below
// DO SOMETHING
非常に特殊なユースケースで保護されて、私はそれをすることはできません(ユーザとの対話なしに私のページを開く必要があります私はまだそれを保護する必要があります。私はある種のアクセストークンを渡す必要があります。
「アクセストークン」をクエリのパラメータとして渡すことは、おそらく良い考えではないと私は理解していますか?実際に、私は私の問題を解決し、フォームを経由してユーザーとの対話を通じてセッションベースの認証以外のマイページにアクセスすることを可能にする方法がわからない
...
それは私がしたいと私には思われますプログラムでトークンを取得してから、ページを参照する必要があります。そこに問題を解決するためのベストプラクティスがあると思います。
任意のポインタ?誰かが知識のギャップを埋めることができるかもしれません。
デフォルトを使用してみました 'session'メカニズムを帆。これは、セッションを格納するためにredisを使用します。 https://sailsjs.com/documentation/reference/configuration/sails-config-session – khushalbokadey
あなたはどのように具体的になりますか? – zabumba
シングルサインオンスタイルの操作を探していると思います。 SAML 2.0を搭載したパスポートでは、あなたのためのトリックが必要です。 – Glen