Skip to content

Token security#10

Draft
detronetdip wants to merge 13 commits intoanomic30:mainfrom
detronetdip:token-security
Draft

Token security#10
detronetdip wants to merge 13 commits intoanomic30:mainfrom
detronetdip:token-security

Conversation

@detronetdip
Copy link
Contributor

@detronetdip detronetdip commented Sep 24, 2022

I am rewriting the token storage and validation logic in a more secure way.

Fixes #9

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@detronetdip detronetdip marked this pull request as draft September 24, 2022 20:05

//upload files to server
Axios.post(`${process.env.REACT_APP_SERVER_URL}/api/upload`, formData, {
withCredentials:true,
Copy link
Owner

Choose a reason for hiding this comment

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

Can you explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mentioning withCredentials:true will ensure that the cookies are sent to the server with every request.

})
console.log("saving user")
await user.save();
res.cookie('didToken',didToken,{httpOnly:true})
Copy link
Owner

Choose a reason for hiding this comment

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

Explain this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remember I commented the window.localStorage.setItem("didToken", newDidToken); well I did that for this. This is setting the token ass httpOnly cookie in the response header so whenever client receives this response , client will automatically save the token in the browser cookie and I have passed httpOnly:true because by mentioning this it will ensure that it will not be accessible from client javascript.

await setUser(userMetadata);
let newDidToken = await magic.user.getIdToken({ lifespan: 24 * 60 * 60 * 7 });
window.localStorage.setItem("didToken", newDidToken);
// window.localStorage.setItem("didToken", newDidToken);
Copy link
Owner

Choose a reason for hiding this comment

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

We need to store the didToken in the cookie storage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and we are doing that. window.localStorage.setItem("didToken", newDidToken); will save the token in the local storage but we want to store the token in the cookies. So I am sending the token to the server and when response comes back it will automatically set the token in the cookis.

@detronetdip
Copy link
Contributor Author

@anomic30 can you please tell me why the below code is returning null.

var d=await magic.auth.loginWithMagicLink({
        email,
});
console.log(d);

@detronetdip
Copy link
Contributor Author

@anomic30 please help me I could not understand why it is returning null.

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.

Secure Token Storage

2 participants