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

feat: generate secret function and replaced few instances #7810

Merged

Conversation

Khaan25
Copy link
Contributor

@Khaan25 Khaan25 commented Oct 18, 2024

This PR fixes #4588

Copy link

github-actions bot commented Oct 18, 2024

Warnings
⚠️ Changes were made to the environment variables, but not to the documentation - Please review your changes and check if a change needs to be documented!

Welcome!

Hello there, congrats on your first PR! We're excited to have you contributing to this project.
By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement.

Generated by 🚫 dangerJS against 5477e18

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request introduces a new generateSecret function to centralize secret management using a single APP_SECRET environment variable, addressing issue #4588.

  • Implemented generateSecret function in packages/twenty-server/src/utils/generate-secret.ts
  • Modified token.service.ts to use generateSecret for transient and API key tokens
  • Replaced individual secret variables with APP_SECRET in environment files
  • Added error handling for missing APP_SECRET in generate-secret.ts
  • Updated secret generation logic to include workspace ID and token type

2 file(s) reviewed, 7 comment(s)
Edit PR Review Bot Settings | Greptile


export const generateSecret = (
workspaceId: string,
type: 'ACCESS' | 'LOGIN' | 'REFRESH' | 'FILE',
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider using an enum for type parameter

type: 'ACCESS' | 'LOGIN' | 'REFRESH' | 'FILE',
): string => {
return createHash('sha256')
.update(`${process.env.APP_SECRET}${workspaceId}${type}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: no separator between APP_SECRET, workspaceId, and type could lead to collisions

@@ -0,0 +1,14 @@
import { createHash } from 'crypto';

if (!process.env.APP_SECRET) {
Copy link
Member

@FelixMalfait FelixMalfait Oct 18, 2024

Choose a reason for hiding this comment

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

We should access env var through the dedicate service not directly through process.env ; you should probably do this in TokenService

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I'll see that.

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

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

Thank you! Please replace every instance in the codebase :)

@Khaan25
Copy link
Contributor Author

Khaan25 commented Oct 19, 2024

@FelixMalfait I've pushed a change to get APP_SECRET from the environment service.

Can you please open issue? We don't have workspaceId in some function, what do I pass there? e.g.

I've attached an image of a function:
image

Thank you very much!

@FelixMalfait
Copy link
Member

FelixMalfait commented Oct 22, 2024

Sorry I hijacked your PR but it was worth cleaning up a bit :)

@Khaan25
Copy link
Contributor Author

Khaan25 commented Oct 22, 2024

Haha, no worries. I'm also learning about the new techniques and codebase 🙌 Amazing Job

@Khaan25
Copy link
Contributor Author

Khaan25 commented Oct 22, 2024

I guess the PR is complete then? @FelixMalfait Thanks for the help though. I got the understanding of the codebase as well how things are linkedin togther, do you think we can close the PR now?

@FelixMalfait
Copy link
Member

/award 300
Yes PR is complete, @charlesBochet will review it again when he has time!

Copy link

oss-gg bot commented Oct 22, 2024

Awarding Khaan25: 300 points 🕹️ Well done! Check out your new contribution on oss.gg/Khaan25

@Khaan25
Copy link
Contributor Author

Khaan25 commented Oct 27, 2024

@FelixMalfait, hope I get points for the change as it's for developer docs as per side quest :)

Let me knowww

@charlesBochet charlesBochet merged commit 57d9b8e into twentyhq:main Oct 30, 2024
16 checks passed
Copy link

oss-gg bot commented Oct 30, 2024

Awarding Khaan25: 500 points 🕹️ Well done! Check out your new contribution on oss.gg/Khaan25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce APP_SECRET to replace SECRETS
3 participants