如何生成新的 Meteor 登录令牌(服务器端)以建立快速登录链接 [英] How to generate new Meteor login tokens (server side) in order to make a quick login link
本文介绍了如何生成新的 Meteor 登录令牌(服务器端)以建立快速登录链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Meteor 有一个 loginWithToken
方法,用户对象中有 resume
令牌.因此,您可以使用带有 loginWithToken
的这些令牌之一登录.那行得通.
Meteor has a loginWithToken
method, and there are resume
tokens in the user object. So one can login using one of these tokens with loginWithToken
. That works.
有没有办法生成新的登录令牌,还是我应该只使用简历令牌来创建快速登录链接?
Is there a way to generate new login tokens, or should I just use the resume tokens to create a quick login link?
推荐答案
正如 Johnny 所说,可以使用 Accounts._generateStampedLoginToken()
函数,其实没什么特别的,就是下面这个函数:
As Johnny said, you can use the Accounts._generateStampedLoginToken()
function, which is actually nothing special, just the following function:
_generateStampedLoginToken = function () {
return {
token: Random.secret(),
when: new Date
};
}
无论如何,要使用它,这里是一个例子:
anyway, to use it, here is an example:
// Server //
// Creates a stamped login token
var stampedLoginToken = Accounts._generateStampedLoginToken();
/**
* Hashes the stamped login token and inserts the stamped login token
* to the user with the id specified, adds it to the field
* services.resume.loginTokens.$.hashedToken.
* (you can use Accounts._hashLoginToken(stampedLoginToken.token)
* to get the same token that gets inserted)
*/
Accounts._insertLoginToken(user._id, stampedLoginToken);
// Client //
// Login with the stamped loginToken's token
Meteor.loginWithToken(stampedLoginToken.token);
这篇关于如何生成新的 Meteor 登录令牌(服务器端)以建立快速登录链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文