Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensureAuthorized token promise bug #1

Open
SeanCannon opened this issue Jul 29, 2024 · 0 comments
Open

ensureAuthorized token promise bug #1

SeanCannon opened this issue Jul 29, 2024 · 0 comments
Assignees

Comments

@SeanCannon
Copy link
Contributor

const token = sign(decoded, MASTER_PRIVATE_KEY.replace(/\\n/g, '\n'), {

This code is broken. sign returns a promise but it's being assigned to token. Needs to be refactored like this :

          const maybeOfferNewTokenHeader = () => Promise.resolve()
            .then(() => MASTER_PRIVATE_KEY ? sign(
              decoded,
              MASTER_PRIVATE_KEY.replace(/\\n/g, '\n'), {
                algorithm : 'RS256',
                expiresIn : process.env.JWT_TTL || '20s'
              }) : req.get('x-auth-token')
            )
            .then(token => {
              res.set('x-auth-token', token);
            });

          return Promise.resolve(secret)
            .then(verifyRSJWT(verify)(token))
            .then(maybeOfferNewTokenHeader)
            .then(setReqUser)
            .then(() => continueWithErrorIfNotPermitted(axios, checkPermission)(decoded, req, next));

@SeanCannon SeanCannon self-assigned this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant