Class: DeviseScim::Auth::OauthStrategy

Inherits:
BaseStrategy show all
Defined in:
lib/devise_scim/auth/oauth_strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/devise_scim/auth/oauth_strategy.rb', line 6

def authenticate(env)
  unless defined?(Doorkeeper)
    raise ConfigurationError,
          "auth_method :oauth requires the doorkeeper gem. Add `gem 'doorkeeper'` to your Gemfile."
  end

  raw = extract_token(env)
  return nil unless raw

  access_token = Doorkeeper::AccessToken.by_token(raw)
  return nil unless access_token&.accessible?

  config = DeviseScim.configuration

  if config.tenancy == :multi
    config.tenant_model.constantize.find_by(doorkeeper_application_id: access_token.application_id)
  else
    :ok
  end
end