当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jwt-simple.encode函数代码示例

本文整理汇总了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);
};
开发者ID:ghiscoding,项目名称:Realtime-TODO-Aurelia-RethinkDB,代码行数:8,代码来源:authUtils.ts

示例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);
    }
开发者ID:fedoranimus,项目名称:typescript-mean-stack,代码行数:9,代码来源:AuthUtils.ts

示例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 })
     }
 })
开发者ID:zalox,项目名称:Texd,代码行数:11,代码来源:login.ts

示例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;
	}
开发者ID:jnamla,项目名称:herokuTestCymplar,代码行数:12,代码来源:login_service.ts

示例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;
	}
开发者ID:australdev,项目名称:app,代码行数:12,代码来源:login_service.ts

示例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 });
     }
 })
开发者ID:roderickmonk,项目名称:rod-monk-sample-repo,代码行数:13,代码来源:Server.ts

示例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)
     });
 })
开发者ID:roderickmonk,项目名称:rod-monk-sample-repo-ng2,代码行数:13,代码来源:Server.ts

示例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');
};
开发者ID:DavidOnGitHub,项目名称:questionApp_backend,代码行数:16,代码来源:authUtil.ts

示例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);
	}
开发者ID:freezy,项目名称:node-vpdb,代码行数:17,代码来源:authentication.util.ts

示例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);
	}
开发者ID:freezy,项目名称:node-vpdb,代码行数:23,代码来源:authentication.util.ts


注:本文中的jwt-simple.encode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。