-
Notifications
You must be signed in to change notification settings - Fork 755
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
Conversation
app/models/user.rb
Outdated
@@ -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| |
There was a problem hiding this comment.
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.
app/models/user.rb
Outdated
@@ -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| |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) %> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great!
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
app/models/user.rb
Outdated
@@ -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| |
There was a problem hiding this comment.
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!
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)) %> |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
docker-entrypoint.sh
Outdated
@@ -0,0 +1,9 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏
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! |
- should be refactored to be reusable across different providers
- mvp version - skips validation of password when user is created via oauth
- to be refactored - working version
- uid uses "provider" + uid
- used english values for the meantime
There was a problem hiding this 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' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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!
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. |
Merging master has been cumbersome. I feel like it's easier for me to just rewrite on a new branch 😞 |
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. |
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
Specs
UserBuilder::Base.call
UserBuilder::Builder.build
Shared Links
I've rebased this branch to my other PR #1594
Corresponding Issue
#961
Screenshots
Reviewing this pull request? Check out our Code Review Practices guide if you haven't already!