本文整理汇总了TypeScript中jwt-simple.encode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript encode函数的具体用法?TypeScript encode怎么用?TypeScript encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: moment
export const createJWT = (user: any): string => {
const payload = {
sub: user.id,
iat: moment().unix(),
exp: moment().add(14, 'days').unix()
};
return encode(payload, config.TOKEN_SECRET);
};
示例2: createJWT
public static createJWT(user: IUser): string {
let payload = {
sub: user._id,
iat: moment().unix(),
exp: moment().add(14, 'days').unix()
}
return jwt.encode(payload, environment.TOKEN_SECRET);
}
示例3: findUser
findUser(req.user.username, (user) => {
if (user) {
var token = jwt.encode({
username: req.user.username,
id: req.user._id
}, secret);
res.json({ success: true, token: token });
} else {
res.json({ success: false })
}
})
示例4: getToken
getToken(accountUser: AccountUser) {
const days = 1; // 1 day
const expires = (Date.now() + (days * 24 * 60 * 60 * 1000));
const payload = {
sub: accountUser._id,
exp: expires
};
const token = encode(payload, process.env.CYMPLAR_SECRET);
return token;
}
示例5: getToken
getToken(user: User) {
const days = 1; // 1 day
const expires = (Date.now() + (days * 24 * 60 * 60 * 1000));
const payload = {
sub: user._id,
exp: expires
};
const token = encode(payload, process.env.AUSTRAL_SECRET);
return token;
}
示例6: httpError
.then(function (member: { _id: string, joiningyear: number, paid: boolean, exec: string }) {
// Yes a member, but are they paid up?
if (!member.joiningyear && !member.paid && moment('2016-05-01').isBefore(moment())) {
console.log('/api/login, member:\n', member);
httpError(HTTP_PaymentRequired, 'Payment Required to Complete Login', response);
}
else if (member.joiningyear == 2016 && !member.paid) {
httpError(HTTP_PaymentRequired, 'Payment Required to Complete Login', response);
}
else {
response.json({ jwt: jwt.encode({ _id: member._id }, secretJwtKey), exec: member.exec });
}
})
示例7:
.then((member: { _id: string, firstname: string, familyname: string, exec: string, role: string }) => {
request.session.login(
member._id,
member.firstname,
member.familyname,
member.exec,
_.isUndefined(member.role) ? 'member' : member.role,
request.headers['device']);
response.json({
jwt: jwt.encode({ _id: member._id }, process.env.SECRET_JWT_KEY),
exec: member.exec, permissions: Role.getPermissions(request.session.role)
});
})
示例8: createToken
export function createToken(req: {
hostname: string,
accountId: string,
createdTime: Date
}): string {
const expiryTime = new Date(req.createdTime.getTime() + 30 * 60000);
var payload = {
host: req.hostname,
accountId: req.accountId,
time: req.createdTime,
expiryTime
};
return jwt.encode(payload, secret, 'HS512');
};
示例9: generateApiToken
/**
* Creates a JSON Web Token for a given user and time.
*
* @param {UserDocument} user User to issue for
* @param {Date} now Current time
* @param {boolean} isRefreshToken If set, mark the token as refresh token (can't be used for creating login tokens)
* @returns {string} JSON Web Token for the API
*/
public static generateApiToken(user: UserDocument, now: Date, isRefreshToken: boolean) {
return jwtEncode({
iss: user.id,
iat: now,
exp: new Date(now.getTime() + config.vpdb.apiTokenLifetime),
irt: isRefreshToken,
scp: [ 'all' ],
}, config.vpdb.secret);
}
示例10: generateStorageToken
/**
* Creates a media token.
*
* Media tokens are only valid for a given path and HTTP method and time out
* much faster (default 1 minute).
*
* @param {UserDocument} user User to issue for
* @param {Date} now Current time
* @param {string} path Path the token will be valid for
* @returns {string} JSON Web Token for a storage item
*/
public static generateStorageToken(user: UserDocument, now: Date, path: string): string {
if (!path.startsWith('/')) {
path = AuthenticationUtil.urlPath(path);
}
return jwtEncode({
iss: user.id,
iat: now,
exp: new Date(now.getTime() + config.vpdb.storageTokenLifetime),
path,
scp: [ 'storage' ],
}, config.vpdb.secret);
}