You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey everyone, so I got this working but I feel like it's so hacky. I was wondering if someone can tell me if there's a cleaner approach to this?
require"sequel/core"require"omni_auth/strategies/apple"require"omni_auth/strategies/google"classRodauthMain < Rodauth::Rails::Authconfiguredo# List of authentication features that are loaded.enable:create_account,:verify_account,:verify_account_grace_period,:login,:logout,:remember,:reset_password,:change_password,:change_login,:verify_login_change,:close_account,:jwt,:json,:internal_request,:omniauthjwt_secretRails.application.credentials.secret_key_baseafter_create_account{verify_account}before_close_accountdoRemoveFromBentoJob.perform_later(rails_account.email)ifrails_account&.email.present?# closes w/o password confirmation if oauthifrails_account.account_identities.exists?close_accountendendonly_json?truedelete_account_on_close?true
...
# ==> Remember Feature# Remember all logged in users.after_login{remember_login}# Or only remember users that have ticked a "Remember Me" checkbox on login.# after_login { remember_login if param_or_nil("remember") }# Extend user's remember period when remembered via a cookieextend_remember_deadline?true
....# Omniauth integrationomniauth_provider:google,Rails.application.credentials.dig(:omniauth,:google,:client_id),Rails.application.credentials.dig(:omniauth,:google,:client_secret),name: :googleomniauth_provider:apple,Rails.application.credentials.dig(:omniauth,:apple,:client_id),# This is your Service ID (e.g. com.myapp.login)"",# Apple uses a generated JWT, not a static secret. OmniAuth handles this if params are passed.{scope: "email",provider_ignores_state: true,team_id: Rails.application.credentials.dig(:omniauth,:apple,:team_id),key_id: Rails.application.credentials.dig(:omniauth,:apple,:key_id),authorized_client_ids: [Rails.application.credentials.dig(:omniauth,:apple,:client_id)],pem: Rails.application.credentials.dig(:omniauth,:apple,:private_key)}# sets up proper redirect URL for mobile appomniauth_setupdoomniauth_strategy.options[:provider_ignores_state]=true# allows mobile app loginifomniauth_strategy.to_s.include?("Google")omniauth_strategy.options[:platform]=request.params["platform"]omniauth_strategy.options[:redirect_uri]=request.params["platform"] == "web" ? "https://web.my.app" : nilomniauth_strategy.options[:token_params][:platform]=request.params["platform"]endendomniauth_before_callback_phasedoifomniauth_strategy.to_s.include?("Google")ifsession.present?# assigns jwt only when session existsquery=Rack::Utils.build_query("state"=>request.params["state"],"token"=>session_jwt)redirect_base=request.params["platform"] == "web" ? "https://web.myapp.app" : "myapp://oauth"response.status=request.params["platform"] == "web" ? 200 : 302response.headers["Location"]="#{redirect_base}?#{query}"endendendafter_omniauth_create_accountdoremember_login# remembers login so they can actually use the jwt for the `remember` plugin#assigns session so I can actually send a valid `session_jwt` in the query response once omniauth account is created@session={
**session.to_h,"account_id": account_id,"authenticated_by": ["omniauth"]}query=Rack::Utils.build_query("state"=>request.params["state"],"token"=>session_jwt)redirect_base=request.params["platform"] == "web" ? "https://web.myapp.app" : "myapp://oauth"response.status=request.params["platform"] == "web" ? 200 : 302response.headers["Location"]="#{redirect_base}?#{query}"endendend
I hope this is readable, sorry if it's incoherent.
I feel like I'm hacking around defaults when it comes the omniauth hooks. Would love a peer review if it's not too big of an ask and perhaps this can serve as an example for others
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone, so I got this working but I feel like it's so hacky. I was wondering if someone can tell me if there's a cleaner approach to this?
I hope this is readable, sorry if it's incoherent.
I feel like I'm hacking around defaults when it comes the omniauth hooks. Would love a peer review if it's not too big of an ask and perhaps this can serve as an example for others
Beta Was this translation helpful? Give feedback.
All reactions