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: oauth for chrome extension #4870

Merged
merged 19 commits into from
Apr 24, 2024

Conversation

AdityaPimpalkar
Copy link
Contributor

@AdityaPimpalkar AdityaPimpalkar commented Apr 8, 2024

Previously we had to create a separate API key to give access to chrome extension so we can make calls to the DB. This PR includes logic to initiate a oauth flow with PKCE method which redirects to the Authorise screen to give access to server tokens.

Implemented in this PR-

  1. make redirectUrl a non-nullable parameter
  2. Add NODE_ENV to environment variable service
  3. new env variable CHROME_EXTENSION_REDIRECT_URL on server side
  4. strict checks for redirectUrl
  5. try catch blocks on utils db query methods
  6. refactor Apollo Client to handle unauthorized condition
  7. input field to enter server url (for self-hosting)
  8. state to show user if its already connected
  9. show error if oauth flow is cancelled by user

Follow up PR -
Renew token logic

Copy link

github-actions bot commented Apr 8, 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!

TODOs/FIXMEs:

  • //TODO: replace this with renewToken mutation: packages/twenty-chrome-extension/src/utils/apolloClient.ts
  • //TODO: replace this with renewToken mutation: packages/twenty-chrome-extension/src/utils/apolloClient.ts

Generated by 🚫 dangerJS against d9b8a70

@@ -1,4 +1,8 @@
import Crypto from 'crypto-js';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot use node:crypto to create a codeVerifier and codeChallenge since this project is outside of node scope, hence the different alternative crypto-js

Comment on lines +22 to +26
// export const RenewToken = async (appToken: string): Promise<Tokens | null> => {
// const data = await callQuery<Tokens>(RENEW_TOKEN, { appToken });
// if (isDefined(data)) return data;
// else return null;
// };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its best to implement this in a follow up PR

Comment on lines 33 to 35
{isAuthenticating ? (
<Loader />
) : (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the loader in here because we don't need a separate loading page now

@charlesBochet
Copy link
Member

@AdityaPimpalkar could you add a PR description here too, it will help the review :)


host_permissions: ['https://www.linkedin.com/*'],
host_permissions: ['https://www.linkedin.com/*', 'http://localhost:3001/*'],
Copy link
Member

Choose a reason for hiding this comment

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

Only add Localhost in dev env

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise add twenty.com (app or api?)

@FelixMalfait FelixMalfait merged commit c63ee51 into twentyhq:main Apr 24, 2024
6 of 7 checks passed
arnavsaxena17 pushed a commit to arnavsaxena17/twenty that referenced this pull request Oct 6, 2024
Previously we had to create a separate API key to give access to chrome
extension so we can make calls to the DB. This PR includes logic to
initiate a oauth flow with PKCE method which redirects to the
`Authorise` screen to give access to server tokens.

Implemented in this PR- 
1. make `redirectUrl` a non-nullable parameter 
2. Add `NODE_ENV` to environment variable service
3. new env variable `CHROME_EXTENSION_REDIRECT_URL` on server side
4. strict checks for redirectUrl
5. try catch blocks on utils db query methods
6. refactor Apollo Client to handle `unauthorized` condition
7. input field to enter server url (for self-hosting)
8. state to show user if its already connected
9. show error if oauth flow is cancelled by user

Follow up PR -
Renew token logic

---------

Co-authored-by: Félix Malfait <[email protected]>
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.

3 participants