Skip to content

Commit

Permalink
g access
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Jul 20, 2024
1 parent c947dea commit 45d28cb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ gem "omniauth", "~> 2.0"
# gem 'omniauth-zoom'
# gem "omniauth-github"
gem "omniauth-twitter"
gem "omniauth-google-oauth2"
# gem 'omniauth-stripe'
gem "omniauth-discord"
gem "omniauth-twitch"
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ GEM
method_source (1.1.0)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.1)
mrsk (0.15.1)
activesupport (>= 7.0)
Expand Down Expand Up @@ -396,11 +397,8 @@ GEM
net-protocol
net-ssh (7.2.0)
nio4r (2.7.3)
nokogiri (1.16.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
nokogiri (1.16.6)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oauth (1.1.0)
oauth-tty (~> 1.0, >= 1.0.1)
Expand All @@ -422,6 +420,10 @@ GEM
omniauth-discord (1.1.0)
omniauth (~> 2.1.0)
omniauth-oauth2
omniauth-google-oauth2 (0.8.0)
jwt (>= 2.0)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.6)
omniauth-oauth (1.2.0)
oauth
omniauth (>= 1.0, < 3)
Expand Down Expand Up @@ -643,10 +645,7 @@ GEM
zeitwerk (2.6.16)

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-23
x86_64-linux
ruby

DEPENDENCIES
aasm (~> 5.2)
Expand Down Expand Up @@ -684,6 +683,7 @@ DEPENDENCIES
mrsk (~> 0.15.1)
omniauth (~> 2.0)
omniauth-discord
omniauth-google-oauth2
omniauth-rails_csrf_protection
omniauth-twitch
omniauth-twitter
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def twitch
callback_handler
end

def google_oauth2
logger.info("Callback Google")
# logger.info(session.to_json)
callback_handler
end

private

def callback_handler
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ def icon_for(kind)
</svg>
HTML

when :google_oauth2
<<-HTML
<svg class="w-6 h-5" fill="currentColor" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="100" height="100" viewBox="0 0 48 48">
<path d="M23 21.5v5c0 .828.671 1.5 1.5 1.5h10.809c-.499 1.416-1.256 2.698-2.205 3.805l6.033 5.229C42.159 33.529 44 28.98 44 24c0-.828-.064-1.688-.202-2.702C43.697 20.555 43.062 20 42.312 20H24.5C23.671 20 23 20.672 23 21.5zM12.612 27.761C12.22 26.577 12 25.314 12 24s.22-2.577.612-3.761l-6.557-5.014C4.752 17.878 4 20.849 4 24s.752 6.122 2.056 8.775L12.612 27.761zM30.865 33.835C28.906 35.204 26.532 36 24 36c-4.212 0-7.917-2.186-10.059-5.478l-6.362 4.865C11.195 40.585 17.202 44 24 44c4.968 0 9.508-1.832 13.009-4.84L30.865 33.835zM37.515 9.297C33.813 5.881 29.013 4 24 4c-6.798 0-12.805 3.415-16.421 8.614l6.362 4.865C16.083 14.186 19.788 12 24 12c2.944 0 5.776 1.081 7.974 3.043.593.53 1.498.504 2.06-.059l3.525-3.524c.289-.288.447-.683.439-1.091C37.99 9.961 37.815 9.574 37.515 9.297z"></path>
</svg>
</svg>
HTML

when :twitter
<<-HTML
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
Expand Down
12 changes: 11 additions & 1 deletion app/models/user/omni_auth_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module ClassMethods
#
def find_by_identity_for(provider, data, current_user)
identity = OauthCredential.find_by(provider: provider, uid: data["uid"])

if identity
logger.info("UPDATE DATA! #{data.to_json}")

Expand All @@ -31,6 +30,17 @@ def find_by_identity_for(provider, data, current_user)
token: data["credentials"]["token"],
secret: data["credentials"]["secret"])
current_user
elsif !current_user
current_user = User.find_by(email: data["info"]["email"])
if current_user
current_user.identities.create!(
provider: provider,
uid: data["uid"],
token: data["credentials"]["token"],
secret: data["credentials"]["secret"]
)
end
current_user
end
end

Expand Down
12 changes: 11 additions & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,19 @@
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'

# require "omniauth-github"

config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
{
name: 'google_oauth2',
scope: 'email, profile',
prompt: 'select_account',
image_aspect_ratio: 'square',
image_size: 50,
strategy_class: OmniAuth::Strategies::GoogleOauth2
}
config.omniauth :zoom, ENV["ZOOM_CLIENT_ID"], ENV["ZOOM_CLIENT_SECRET"], scope: "read_stream, user_groups, user_online_presence, user_photos, friends_photos, publish_stream, user_status, email"
# config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], :scope=>"read_stream, user_groups, user_online_presence, user_photos, friends_photos, publish_stream, user_status, email"
config.omniauth :twitter, ENV["TWITTER_CLIENT_ID"], ENV["TWITTER_CLIENT_SECRET"], scope: "tweet.read users.read offline.access"
# config.omniauth :twitter, ENV["TWITTER_CLIENT_ID"], ENV["TWITTER_CLIENT_SECRET"], scope: "tweet.read users.read offline.access"
config.omniauth :discord, ENV["DISCORD_CLIENT_ID"], ENV["DISCORD_CLIENT_SECRET"], scope: "email identify"
config.omniauth :twitch, ENV["TWITCH_CLIENT_ID"], ENV["TWITCH_CLIENT_SECRET"], scope: "channel:manage:broadcast channel:manage:videos user:read:email channel:read:stream_key"
config.omniauth :stripe_connect, ENV["STRIPE_CLIENT_ID"], ENV["STRIPE_CLIENT_SECRET"], scope: "read_write"
Expand Down

0 comments on commit 45d28cb

Please sign in to comment.