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

[WIP] GitHub Authentication #1595

Closed
wants to merge 22 commits into from
Closed

[WIP] GitHub Authentication #1595

wants to merge 22 commits into from

Conversation

sbpipb
Copy link
Contributor

@sbpipb sbpipb commented Oct 20, 2019

Description

Integrates GitHub OmniAuth to allow users to register and login using their Github account.

More Details

Allows users to signin and sign up using Github

  • refactor views
  • refactor model methods

Specs

  • UserBuilder::Base.call
  • UserBuilder::Builder.build
  • Validation on password_complexity
  • Omni Auth providers to return expected list
  • Feature tests
  • Drying up Shared Links

I've rebased this branch to my other PR #1594

Corresponding Issue

#961

Screenshots

2019-10-20_13-55_1
2019-10-20_13-55


Reviewing this pull request? Check out our Code Review Practices guide if you haven't already!

@sbpipb sbpipb added the wip label Oct 20, 2019
@sbpipb sbpipb self-assigned this Oct 20, 2019
@@ -94,10 +96,22 @@ def self.find_for_google_oauth2(access_token)
user
end

# to refactor, could be single oauth method to begin with
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
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'd like some feedback regarding how we'd want to do this., compared to the Google version, this uses provider and UID, I'm okay to change this to email if that's what's required.

@@ -94,10 +96,22 @@ def self.find_for_google_oauth2(access_token)
user
end

# to refactor, could be single oauth method to begin with
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
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 uid is the correct option here than email

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with using UID here!

@@ -4,8 +4,12 @@
<%- resource_class.omniauth_providers.each do |provider| %>
<% if provider.to_s == "google_oauth2" && (current_page?(new_user_session_path) || current_page?(new_user_password_path)) %>
<%= button_to t('devise.shared.sign_in_google'), omniauth_authorize_path(resource_name, provider), method: :post, class: 'buttonGhostM' %>
<% elsif provider.to_s == "github" && (current_page?(new_user_session_path) || current_page?(new_user_password_path)) %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this part is a bit dirty, needs some refactoring

Copy link
Member

Choose a reason for hiding this comment

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

That would be great!

Copy link
Member

@julianguyen julianguyen left a comment

Choose a reason for hiding this comment

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

Looking good so far! Great job 👏

def google_access_token
google_access_token_expired? ? update_access_token : token
end

# TODO: refactor this and use one checker
Copy link
Member

Choose a reason for hiding this comment

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

Good call!

@@ -94,10 +96,22 @@ def self.find_for_google_oauth2(access_token)
user
end

# to refactor, could be single oauth method to begin with
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with using UID here!

@guilhermekbral
Copy link
Contributor

Hey @sbpipb 👋
Looks like the files from #1594 are present in this branch too. It would be better to remove that commit from this branch.
If for any reason #1594 won't be merged, but this PR will, we don't want that commit going to master accidentally! 🙈

@sbpipb
Copy link
Contributor Author

sbpipb commented Oct 25, 2019

Hey @sbpipb
Looks like the files from #1594 are present in this branch too. It would be better to remove that commit from this branch.
If for any reason #1594 won't be merged, but this PR will, we don't want that commit going to master accidentally!

I understand, I'll remove the docker setup related files when I finish this PR. For now i'll just leave it as is.

@@ -4,8 +4,12 @@
<%- resource_class.omniauth_providers.each do |provider| %>
<% if provider.to_s == "google_oauth2" && (current_page?(new_user_session_path) || current_page?(new_user_password_path)) %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO:
add a helper that handles showing of button links

show_signup_page? provider

show_register_page? provider

@julianguyen
Copy link
Member

Just checking in! Any updates?

@sbpipb
Copy link
Contributor Author

sbpipb commented Dec 9, 2019

Just checking in! Any updates?

Hello, It's been a while...

sorry, I'll be working on this by the holiday break. got busy over work.

end
end

def github
Copy link
Contributor

Choose a reason for hiding this comment

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

I am just curious why we have github auth, are our users mostly from github?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is something that @julianguyen can answer, but if I may try. since this is a platform that encourages collaboration, maybe a target audience of tech people are in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah GitHub authentication isn't a priority like Facebook would be for instance. This was requested by a contributor 🙃

But we could use this functionality to show links for filing GitHub issues just for folks signed in it.

Copy link
Member

Choose a reason for hiding this comment

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

We should also test this new method!

@@ -0,0 +1,9 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 👏

@sbpipb
Copy link
Contributor Author

sbpipb commented Apr 2, 2020

Hello, I'm sorry if this feature has taken quite some time, but I'm finally freed up to resume work. I'll have some updates by this week. 🙇‍♂️ apologies!

Copy link
Member

@julianguyen julianguyen left a comment

Choose a reason for hiding this comment

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

Great work! We're almost there and ready to merge 🎉

@@ -84,6 +85,7 @@ group :development, :test do

gem 'bullet'

gem 'awesome_print'
Copy link
Member

Choose a reason for hiding this comment

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

Is this gem necessary? What's it being used for?

end
end

def github
Copy link
Member

Choose a reason for hiding this comment

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

Yeah GitHub authentication isn't a priority like Facebook would be for instance. This was requested by a contributor 🙃

But we could use this functionality to show links for filing GitHub issues just for folks signed in it.

validate :password_complexity

# add unless statement here instead of the concern for readability
# TODO: refactor the Password validator concern
Copy link
Member

Choose a reason for hiding this comment

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

Will this be done in another PR? :) Feel free to create an issue for this as well just to document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the setbacks on making this PR short. I agree on having this as another ticket.

user = find_or_initialize_by(email: access_token.info.email)
user.name ||= access_token.info.name
# TODO: to refactor and to move to builder pattern
# UserBuilder::GoogleOauth2
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment as above.

@@ -0,0 +1,31 @@
# frozen_string_literal: true
module UserBuilder
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

class Builder
# Adds new omni auth providers here
SERVICE = {
# 'google_oauth' => GoogleOauth2
Copy link
Member

Choose a reason for hiding this comment

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

Should this be uncommented?

@@ -440,6 +440,7 @@ it:
nostra %{code_of_conduct_link}. Non sei più bannato.'
omniauth:
google: Google
github: Github
Copy link
Member

Choose a reason for hiding this comment

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

So I don't think we need to add another GitHub translation since we already have one at navigation.github. In general, we don't want to introduce duplication in our translation files.

end
end

def github
Copy link
Member

Choose a reason for hiding this comment

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

We should also test this new method!

@sbpipb
Copy link
Contributor Author

sbpipb commented May 11, 2020

hello! this is taking longer than expected, and the quarantine has been affecting me as well on taking some time.

I'm determined to finish this within this month. Thanks everyone for being patient.

@sbpipb
Copy link
Contributor Author

sbpipb commented May 11, 2020

Merging master has been cumbersome. I feel like it's easier for me to just rewrite on a new branch 😞

@julianguyen
Copy link
Member

Thanks so much for the update! Let me know if you need any help with the merge conflicts. I think creating a new branch and cherry-picking your commits should be a good way to resolve them faster.

@julianguyen julianguyen closed this Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants