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