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: Google OAuth for login & signup #6346

Merged
merged 98 commits into from
Feb 16, 2023
Merged

Conversation

scmmishra
Copy link
Member

@scmmishra scmmishra commented Jan 25, 2023

Description

This PR adds Google OAuth for all existing users; this will allow users to log in or signup via their Google account.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Depends on: chatwoot/utils#18

How Has This Been Tested?

Tested locally, needs to be verified on staging

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on 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

@pr-triage pr-triage bot added the PR: draft label Jan 25, 2023
@netlify
Copy link

netlify bot commented Jan 25, 2023

Deploy Preview for chatwoot-storybook canceled.

Name Link
🔨 Latest commit dc8e12c
🔍 Latest deploy log https://app.netlify.com/sites/chatwoot-storybook/deploys/63edbe9ad0a6b200075ee769

Comment on lines 5 to 8
if @resource.nil?
redirect_to "#{ENV.fetch('FRONTEND_URL', nil)}/app/login?error=oauth-no-user"
return
end
Copy link
Member Author

Choose a reason for hiding this comment

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

@sojan-official @pranavrajs need your thoughts on this approach, to reject a login

Copy link
Member

Choose a reason for hiding this comment

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

Can we show a toast when there is an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

We raise a toast that says "User not found. You need to sign up first"

Screenshot 2023-01-29 at 11 18 12 AM

@scmmishra scmmishra marked this pull request as ready for review January 25, 2023 11:43
config/routes.rb Outdated
@@ -1,11 +1,12 @@
Rails.application.routes.draw do
# AUTH STARTS
match 'auth/:provider/callback', to: 'home#callback', via: [:get, :post]
# match 'auth/:provider/callback', to: 'home#callback', via: [:get, :post]
Copy link
Member

Choose a reason for hiding this comment

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

👃

Copy link
Member Author

Choose a reason for hiding this comment

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

Wanted to know if this route is actually used? I couldn't trace back the controller for it

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding this back, yields this error, because the home_controller.rb does not exist and it overrides the routes created by devise token auth

image

@sojan-official @tejaswinichile let me know if you have an idea about this

Copy link
Contributor

@tejaswinichile tejaswinichile Jan 31, 2023

Choose a reason for hiding this comment

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

@scmmishra I think this has been initially added as a provider for Facebook messenger or Twitter. But we introduced Twitty later, and this endpoint is not used for Facebook. And as you said, the home_controller is also not present in the system.

But to make sure, please deploy this branch on staging, and check if the Facebook and twitter integrations are working. Or let me know; my Facebook account is already configured on staging.

Or if you could test it on local with ngrok, that will also work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted, I will test it locally with ngrok

Copy link
Member Author

Choose a reason for hiding this comment

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

@tejaswinichile is there any docs on setting up facebook and twitter locally?

@scmmishra scmmishra changed the base branch from develop to feat/google-oauth-integration January 31, 2023 09:21
@scmmishra
Copy link
Member Author

@sojan-official I've changed the base branch to a feature branch; we can merge this as required. I will work on the signup in a separate branch, will merge it to feat/google-oauth-integration

@scmmishra scmmishra requested a review from fayazara February 14, 2023 08:32
@scmmishra
Copy link
Member Author

@sojan-official the PR is good to go by Pranav, need your review on this. @fayazara it'd be great if you could review the frontend changes

Copy link
Member

@sojan-official sojan-official left a comment

Choose a reason for hiding this comment

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

Minor comment. Other wise looks good to me.


def account_signup_allowed?
# set it to true by default, this is the behaviour across the app
ActiveModel::Type::Boolean.new.cast(ENV.fetch('ENABLE_ACCOUNT_SIGNUP', true))
Copy link
Member

Choose a reason for hiding this comment

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

let's use GlobalConfigService.load('ENABLE_ACCOUNT_SIGNUP', 'false') instead.
Chatwoot also allows configuration from UI for this flag. hence we will have to account for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sojan-official made the changes, PTAL

Copy link
Contributor

@fayazara fayazara left a comment

Choose a reason for hiding this comment

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

@scmmishra Frontend code looks good 🔥 .

Have left some comments for minor css changes and some input sanitazation.

Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com>
@scmmishra
Copy link
Member Author

@sojan-official thanks for taking care of the merge conflict. Let me know if this requires any more changes

@sojan-official sojan-official merged commit 7be2ef3 into develop Feb 16, 2023
@sojan-official sojan-official deleted the feat/google-auth branch February 16, 2023 05:42
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants