Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Metrics/BlockLength:
- "spec/**/*"
- "config/environments/*"
- "config/routes.rb"
- "config/initializers/devise.rb"

Metrics/ClassLength:
CountAsOne: ["array", "hash", "heredoc"]
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ gem "multi_json", "1.15.0"
# gem "newrelic_rpm", "9.9.0"
# GitHub strategy for OmniAuth
gem "omniauth-github"
# GitHub strategy for Google
gem "omniauth-google-oauth2"
# Provides CSRF protection on OmniAuth request endpoint on Rails application.
gem "omniauth-rails_csrf_protection"
# GitHub strategy for Strava
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ GEM
omniauth-github (2.0.1)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.8)
omniauth-google-oauth2 (1.1.3)
jwt (>= 2.0)
oauth2 (~> 2.0)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.8)
omniauth-oauth2 (1.8.0)
oauth2 (>= 1.4, < 3)
omniauth (~> 2.0)
Expand Down Expand Up @@ -616,6 +621,7 @@ DEPENDENCIES
money (= 6.16.0)
multi_json (= 1.15.0)
omniauth-github
omniauth-google-oauth2
omniauth-rails_csrf_protection
omniauth-strava
packwerk (= 3.1.0)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :api,
:omniauthable, :confirmable, :lockable,
omniauth_providers: %i[github strava]
omniauth_providers: %i[github strava google_oauth2]

has_many :event_procedures, dependent: :destroy
has_many :medical_shifts, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>

<div class="submit">
<%= f.submit "Sign up" %>
<%= f.submit t("devise.registrations.new.sign_up") %>
</div>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<% end %>

<div class="submit">
<%= f.submit "Log in" %>
<%= f.submit t("devise.sessions.new.sign_in") %>
</div>
<% end %>

Expand Down
8 changes: 4 additions & 4 deletions app/views/devise/shared/_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</div>

<div class="oauth-buttons">
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<p><%= button_to t("devise.shared.links.sign_in_with_provider"){OmniAuth::Utils.camelize(provider)}, omniauth_authorize_path(resource_name, provider), data: { turbo: false } %></p>
<% end %>
<%- if devise_mapping.omniauthable? && resource_class.omniauth_providers.include?(:google_oauth2) %>
<p>
<%= button_to t("devise.shared.links.sign_in_with_provider", provider: "Google"), omniauth_authorize_path(resource_name, :google_oauth2), data: { turbo: false } %>
</p>
<% end %>
</div>
10 changes: 10 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@
config.omniauth :github, ENV.fetch("GITHUB_CLIENT_ID", nil), ENV.fetch("GITHUB_CLIENT_SECRET", nil),
scope: "user,public_repo"

config.omniauth :google_oauth2,
ENV.fetch("GOOGLE_CLIENT_ID", nil),
ENV.fetch("GOOGLE_CLIENT_SECRET", nil),
{
scope: "userinfo.email,userinfo.profile",
prompt: "select_account",
image_aspect_ratio: "square",
image_size: 50
}

config.omniauth :strava, ENV.fetch("STRAVA_CLIENT_ID", nil).to_i, ENV.fetch("STRAVA_CLIENT_SECRET", nil),
scope: "profile:read_all", token_params: {
client_id: ENV.fetch("STRAVA_CLIENT_ID", nil),
Expand Down
5 changes: 4 additions & 1 deletion packs/oauth/app/oauth/actors/find_or_create_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Actors
class FindOrCreateUser < Actor
ALLOWED_PROVIDERS_HASH = {
github: "github",
strava: "strava"
strava: "strava",
google: "google_oauth2"
}.freeze

input :auth, type: OmniAuth::AuthHash
Expand All @@ -28,6 +29,8 @@ def find_or_create_with_oauth_provider(auth)
find_or_create_user(auth, ALLOWED_PROVIDERS_HASH[:github], auth.info.email)
when ALLOWED_PROVIDERS_HASH[:strava]
find_or_create_user(auth, ALLOWED_PROVIDERS_HASH[:strava], strava_generated_email(auth))
when ALLOWED_PROVIDERS_HASH[:google]
find_or_create_user(auth, ALLOWED_PROVIDERS_HASH[:google], auth.info.email)
else
fail!(error: :invalid_oauth_provider)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def strava
oauth_sign_in
end

def google_oauth2
oauth_sign_in
end

def oauth_sign_in
result = Oauth::Actors::FindOrCreateUser.result(auth: omniauth_env)

Expand Down