當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。