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


TypeScript jsonwebtoken.decode函数代码示例

本文整理汇总了TypeScript中jsonwebtoken.decode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript decode函数的具体用法?TypeScript decode怎么用?TypeScript decode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了decode函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: return

        return (req: express.Request, res: express.Response) => {
            // Get bearer token
            let authHeaderMatch = /^Bearer (.*)/i.exec(req.header("authorization"));
            if (!authHeaderMatch) {
                console.error("No Authorization token provided");
                res.sendStatus(401);
                return;
            }

            // Decode token and get signing key
            const encodedToken = authHeaderMatch[1];
            const decodedToken = jwt.decode(encodedToken, { complete: true });
            msaOpenIdMetadata.getKey(decodedToken["header"].kid, (key) => {
                if (!key) {
                    console.error("Invalid signing key or OpenId metadata document");
                    res.sendStatus(500);
                }

                // Verify token
                const verifyOptions: jwt.VerifyOptions = {
                    algorithms: ["RS256", "RS384", "RS512"],
                    issuer: `https://sts.windows.net/${decodedToken["payload"].tid}/`,
                    audience: config.get("app.appId"),
                    clockTolerance: 300,
                };
                try {
                    let token = jwt.verify(encodedToken, key.key, verifyOptions);
                    res.status(200).send(token);
                } catch (e) {
                    console.error("Invalid bearer token", e);
                    res.sendStatus(401);
                }
            });
        };
开发者ID:gvprime,项目名称:microsoft-teams-sample-complete-node,代码行数:34,代码来源:ValidateAADToken.ts

示例2: function

router.post("/logout", auth, function(req: express.Request, res: express.Response) {

    var token = getToken(req);
    var dtoken = jwt.decode(token, { complete: true }) || {};

    // Update user status online
    var params = {
        id: dtoken.payload.id,
        status: ManagerModel.MANAGER_STATUS_OFFLINE
    };

    var managerModel = new ManagerModel();

    managerModel.setStatus(params, function(error: any, result: any) {
        if (error) {
            return res.status(400).send({status: false, error: error});
        }
        res.json({
            status: true
        });

        var msg = {
            author: {
                id: params.id
            },
            type: MessageModel.MESSAGE_TYPE_CHANGE_STATUS,
            status: ManagerModel.MANAGER_STATUS_OFFLINE
        };
        server.io.emit( params.id, msg);
    });
});
开发者ID:hoangnguyenba,项目名称:chat-server,代码行数:31,代码来源:index.ts

示例3: return

 return (req: Request, res: Response) => {
     const { cookies: { token: requestToken } } = req;
     const decodedTokenPayload = jwt.decode(requestToken);
     if (decodedTokenPayload) {
         const { username } = decodedTokenPayload;
         log.debug("Logout request for " + username);
     }
     res.status(204).clearCookie('token').end();
 };
开发者ID:PhilipDavis,项目名称:react-redux,代码行数:9,代码来源:logout.ts

示例4: function

export const validateJWT = async function(req: ValidateRequest, res: Response) {
	const decoded = jsonwebtoken.decode(req.query.jwt, { complete: true }) as JWTContent;
	try {
		const publicKey = await getPublicKey(decoded.header.kid);
		jsonwebtoken.verify(req.query.jwt, publicKey); // throws
		res.status(200).json({ is_valid: true });
	} catch (e) {
		res.status(200).json({ is_valid: false, error: e });
	}
} as any as RequestHandler;
开发者ID:nrudenko,项目名称:kin-devplatform-jwt-service,代码行数:10,代码来源:services.ts

示例5: it

    it('sets the subject authResult[entity][entityService.id]', async () => {
      const { accessToken } = await app.service('authentication').create({
        strategy: 'first',
        username: 'David'
      });

      const decoded = jwt.decode(accessToken);

      assert.strictEqual(decoded.sub, Strategy1.result.user.id.toString());
    });
开发者ID:feathersjs,项目名称:feathers,代码行数:10,代码来源:service.test.ts

示例6: isAdmin

function isAdmin(req): boolean {
    if (config.server.admin == "") {
        return true;
    }
    if (req.headers.authorization) {
        var visitor = visitorFactory.getByEmail(jwt.decode(req.headers.authorization.substr(7)).email);
        return visitor.isAdmin();
    }
    else
        return false;
}
开发者ID:smithgeek,项目名称:DevCommunity,代码行数:11,代码来源:partials.ts

示例7: setRavenUserContext

 setRavenUserContext() {
   if (this.cmd && this.cmd.env && this.cmd.env.cloudSessionKey) {
     const data = jwt.decode(this.cmd.env.cloudSessionKey)
     Raven.mergeContext({
       user: {
         fid: getFid(),
         id: data.userId,
         isGlobal: getIsGlobal(),
       },
     })
   }
 }
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:12,代码来源:CLI.ts

示例8: decode

 /**
  * @summary decodes a signed JWT
  * @param {string} signedToken
  * @returns {{}|null} The JWT payload
  */
 decode(signedToken) {
   try {
     return jwt.verify(signedToken, this.configuration.sharedSecret, {
       ignoreExpiration: true,
       issuer: 'urn:app:' + this.configuration.appId,
     });
   } catch (error) {
     // tslint:disable-next-line
     console.error(error, jwt.decode(signedToken));
     return null;
   }
 }
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:17,代码来源:authenticator.ts

示例9: refreshToken

export default function refreshToken(req: Request, res: Response, next: Function) {
    const { cookies: { token: requestToken } } = req;
    const decodedTokenPayload = jwt.decode(requestToken);
    const { username } = decodedTokenPayload;

    // TODO: verify the issuer and secret? (e.g. in multitenant setup)

    const updatedToken = jwt.sign({ username: username }, secret, {
        issuer: 'react-redux-starter-kit',
        expiresIn: expiry,
    });

    res.cookie('token', updatedToken, { secure: false /* TODO: change this */, maxAge: 60 * 60 * 1000 });
    next();
};
开发者ID:PhilipDavis,项目名称:react-redux,代码行数:15,代码来源:refreshToken.ts


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