本文整理汇总了TypeScript中jsonwebtoken.sign函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sign函数的具体用法?TypeScript sign怎么用?TypeScript sign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sign函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1:
app.post('/token', (req, res, next) => {
if (req.body.email && req.body.password) {
const email = req.body.email;
const password = req.body.password;
const user = users.find((value) => {
return value.email === email && value.password === password;
});
if (user) {
const tokenPayload = {
id: user.id,
};
const signOptions: jwter.SignOptions = {
expiresIn: 60,
};
const token = jwter.sign(tokenPayload, configs.JWTConfig.jwtSecret, signOptions);
res.json({
token,
});
} else {
res.sendStatus(404);
}
} else {
res.sendStatus(404);
}
});
开发者ID:Monsoir,项目名称:jwt-authentication-demo,代码行数:26,代码来源:app.ts
示例2: function
UserSchema.method('generateJWT', function() {
return jwt.sign({
username: this.username,
roles: this.roles,
permissions: this.roles.reduce((acc, role) => { return acc.concat(permission[role]); }, [])
}, process.env.JWT_SECRET, {expiresIn: '2 days'});
});
开发者ID:bamtron5,项目名称:webpackNGComponents,代码行数:7,代码来源:User.ts
示例3:
r.table('players').filter({ email }).then((users) => {
const options = { expiresIn: '365d' };
const user = users[0];
jwt.sign({ id: user.id }, secret, options, (err, token) => {
res.status(200).send({ token, id: user.id, name: user.name });
});
});
开发者ID:radotzki,项目名称:bullshit-server,代码行数:7,代码来源:index.ts
示例4:
User.findOne({username: req.body.username}, (err: any, item: any) => {
if (err) throw err;
if(!item){
res.send({
isSuccess: false,
errOn: 'userName',
msg: 'user is not existed! please Sign up!'
})
}else{
if(!Crypto.bcryptCompare(req.body.password, item.password)){
res.send({
isSuccess: false,
errOn: 'password',
msg: 'password is wrong!'
});
}else{
//generate token and return
let token: any = jwt.sign(req.body, config.JwtStrategy.secretOrKey, {});
res.send({
token: token,
isSuccess: true,
userName: item.username,
msg: 'Sign In Successfully'
});
}
}
})
开发者ID:jcdby,项目名称:SuwonCMIAPIServer,代码行数:27,代码来源:userController.ts
示例5: function
UserSchema.method('getToken', function():string{
const payload:MEUserPayload = {
_id: this._id,
expired: new Date(Date.now()+86400000)
}
return jwt.sign(payload, TOKEN_SECRET)
})
开发者ID:memolog,项目名称:mean-edge,代码行数:7,代码来源:user.ts
示例6: function
userSchema.method('createJWT', function() {
return jwt.sign({
_id: this._id,
email: this.email,
isAdmin: this.isAdmin
}, process.env.JWT_SECRET);
});
开发者ID:stevenfogel,项目名称:ELS,代码行数:7,代码来源:user.model.ts
示例7: getLocalToken
getLocalToken(): string | null {
if (!this.clusterSecret && !process.env.PRISMA_MANAGEMENT_API_SECRET) {
return null
}
if (!this.cachedToken) {
const grants = [{ target: `*/*`, action: '*' }]
const secret =
process.env.PRISMA_MANAGEMENT_API_SECRET || this.clusterSecret
try {
const algorithm = process.env.PRISMA_MANAGEMENT_API_SECRET
? 'HS256'
: 'RS256'
this.cachedToken = jwt.sign({ grants }, secret, {
expiresIn: '5y',
algorithm,
})
} catch (e) {
throw new Error(
`Could not generate token for cluster ${chalk.bold(
this.getDeployEndpoint(),
)}. Did you provide the env var PRISMA_MANAGEMENT_API_SECRET?
Original error: ${e.message}`,
)
}
}
return this.cachedToken!
}
开发者ID:nunsie,项目名称:prisma,代码行数:29,代码来源:Cluster.ts
示例8: createEnrollmentTokens
public async createEnrollmentTokens(
user: FrameworkUser,
numTokens: number = 1
): Promise<string[]> {
const tokens = [];
const enrollmentTokensTtlInSeconds = this.framework.getSetting('enrollmentTokensTtlInSeconds');
const enrollmentTokenExpiration = moment()
.add(enrollmentTokensTtlInSeconds, 'seconds')
.toJSON();
const enrollmentTokenSecret = this.framework.getSetting('encryptionKey');
while (tokens.length < numTokens) {
const tokenData = {
created: moment().toJSON(),
expires: enrollmentTokenExpiration,
randomHash: randomBytes(26).toString(),
};
tokens.push({
expires_on: enrollmentTokenExpiration,
token: signToken(tokenData, enrollmentTokenSecret),
});
}
await Promise.all(
chunk(tokens, 100).map(tokenChunk => this.adapter.insertTokens(user, tokenChunk))
);
return tokens.map(token => token.token);
}
开发者ID:elastic,项目名称:kibana,代码行数:31,代码来源:tokens.ts
示例9:
const success = (userId: string) => {
const payload: JsonWebTokenPayload = { userId };
return {
errors: null,
token: jwt.sign(payload, API_SECRET as jwt.Secret),
};
};
开发者ID:este,项目名称:este,代码行数:7,代码来源:userModel.ts
示例10: createToken
export function createToken(user: IUser, sessionToken: IToken): string {
const payload: IUserSession = { id: user.id, _id: user._id, token_id: sessionToken.id };
const token = jwt.sign(payload, conf.jwtSecret);
sessionCache.set(sessionToken.id, sessionToken.usuario.toString());
return token;
}
开发者ID:maticorv,项目名称:mascotas2018_foro,代码行数:7,代码来源:passport.ts
注:本文中的jsonwebtoken.sign函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论