本文整理匯總了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);
}