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

Endpoint for getting auth token #103

Merged
merged 4 commits into from
Jan 5, 2022
Merged

Conversation

ChaxuGarg
Copy link
Contributor

No description provided.

Comment on lines 457 to 459
verify(requestToken, keys.privateKey, {
algorithms: ['HS256'],
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to keys.publicKey, and algorithms to ['RS256']. This is because the token was originally signed by CASI's private key and should be verified by its public key.

Reference

verify(requestToken, keys.privateKey, {
algorithms: ['HS256'],
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verification is to be done here, after requestToken and client are verified.

Comment on lines 355 to 378
const createAuthToken = (user) => {
const payload = {
user: {
id: user.id,
email: user.email,
firstname: user.firstname,
lastname: user.lastname,
username: user.username,
roles: user.roles,
privilege: getUserPrivilege(user),
isverified: user.isverified,
},
};
const exp = keys.authExpTime;
// create a token
const token = jwt.sign(payload, keys.privateKey, {
expiresIn: exp, // in seconds
issuer: keys.iss,
algorithm: 'RS256',
});

return token;
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the createJWTCookie method in utils.js. Link.

Instead of creating a separate method for token creation, split the createJWTCookie method into two methods - First for token creation (similar to this createAuthToken), second for cookie creation (the latter part of createJWTCookie). Use the tokenName argument to choose the expiry time of the token.

Comment on lines 435 to 436
const { q } = req.query;
const { requestToken } = decode(q);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is q a JWT token? If yes then you need to verify it. If no, then just use const {reqToken} = req.body. I think there is no need for JWT signing at this stage since this parameter will be publicly visible in the URL. The /getAuthToken method would then check if the request token correctly maps to the client that is trying to exchange it. This would ensure that even if the request token is compromised, a malicious entity would not be able to get access to the auth token.

}
});

router.post('/getToken', async (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change this name to /getAuthToken or something similar? It is kind of confusing >.<


router.post('/getToken', async (req, res) => {
try {
const { token } = req.body;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to verify this token with client.accessToken

@Harsh14901 Harsh14901 merged commit 4e3d1d5 into devclub-iitd:master Jan 5, 2022
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

Successfully merging this pull request may close these issues.

2 participants