Module: Sessions::Adapters::Omniauth
- Defined in:
- lib/sessions/adapters/omniauth.rb
Overview
OmniAuth integration.
Successes need NO hook here: the OAuth callback always lands in an app-side controller that creates the session through whichever adapter is active, and the classifier sniffs ‘env` at that moment (→ docs/research/05-oauth.md §1.2).
Failures are the part nobody records: every strategy failure funnels through the swappable ‘OmniAuth.config.on_failure` rack endpoint. We COMPOSE-wrap it (record, then call the original — Devise’s dispatcher or OmniAuth’s FailureEndpoint both keep working) from ‘config.after_initialize`, so it wraps whatever the app’s own initializers installed. Captured: the error type symbol (:invalid_credentials, :access_denied = the user hit Cancel, :authenticity_error = CSRF), the provider, the originating page, and IP/UA. Not capturable (documented): which local user, and abandonments at the provider.
Class Method Summary collapse
- .install! ⇒ Object
- .installed? ⇒ Boolean
- .record_failure(env) ⇒ Object
- .reset_installation! ⇒ Object
Class Method Details
.install! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sessions/adapters/omniauth.rb', line 25 def install! return if @installed return unless defined?(::OmniAuth) && ::OmniAuth.respond_to?(:config) @installed = true original = ::OmniAuth.config.on_failure ::OmniAuth.config.on_failure = lambda do |env| Sessions::Adapters::Omniauth.record_failure(env) original.call(env) end end |
.installed? ⇒ Boolean
37 38 39 |
# File 'lib/sessions/adapters/omniauth.rb', line 37 def installed? !!@installed end |
.record_failure(env) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sessions/adapters/omniauth.rb', line 45 def record_failure(env) Sessions.safely("omniauth.failure") do next unless Sessions.config.track_failed_logins request = ActionDispatch::Request.new(env) strategy = env["omniauth.error.strategy"] provider = strategy.respond_to?(:name) ? strategy.name.to_s : nil Sessions.record_failed_attempt( request, reason: env["omniauth.error.type"], method: :oauth, provider: Sessions::Classifier.normalize_provider(provider), detail: { origin: env["omniauth.origin"] }.compact ) end end |
.reset_installation! ⇒ Object
41 42 43 |
# File 'lib/sessions/adapters/omniauth.rb', line 41 def reset_installation! @installed = false end |