class Devise::Strategies::SamlAuthenticatable

Public Instance Methods

authenticate!() click to toggle source
# File lib/devise_saml_authenticatable/strategy.rb, line 18
def authenticate!
  parse_saml_response
  retrieve_resource unless self.halted?
  unless self.halted?
    @resource.after_saml_authentication(@response.sessionindex)
    success!(@resource)
  end
end
store?() click to toggle source

This method should turn off storage whenever CSRF cannot be verified. Any known way on how to let the IdP send the CSRF token along with the SAMLResponse ? Please let me know!

# File lib/devise_saml_authenticatable/strategy.rb, line 30
def store?
  !mapping.to.skip_session_storage.include?(:saml_auth)
end
valid?() click to toggle source
# File lib/devise_saml_authenticatable/strategy.rb, line 7
def valid?
  if params[:SAMLResponse]
    OneLogin::RubySaml::Response.new(
      params[:SAMLResponse],
      response_options,
    )
  else
    false
  end
end

Private Instance Methods

failed_auth(msg) click to toggle source
# File lib/devise_saml_authenticatable/strategy.rb, line 52
def failed_auth(msg)
  DeviseSamlAuthenticatable::Logger.send(msg)
  fail!(:invalid)
  Devise.saml_failed_callback.new.handle(@response, self) if Devise.saml_failed_callback
end
parse_saml_response() click to toggle source
# File lib/devise_saml_authenticatable/strategy.rb, line 35
def parse_saml_response
  @response = OneLogin::RubySaml::Response.new(
    params[:SAMLResponse],
    response_options,
  )
  unless @response.is_valid?
    failed_auth("Auth errors: #{@response.errors.join(', ')}")
  end
end
response_options() click to toggle source
# File lib/devise_saml_authenticatable/strategy.rb, line 58
def response_options
  options = {
    settings: saml_config(get_idp_entity_id(params)),
    allowed_clock_drift: Devise.allowed_clock_drift_in_seconds,
  }

  if Devise.saml_validate_in_response_to
    options[:matches_request_id] = request.session[:saml_transaction_id] || "ID_MISSING"
  end

  options
end
retrieve_resource() click to toggle source
# File lib/devise_saml_authenticatable/strategy.rb, line 45
def retrieve_resource
  @resource = mapping.to.authenticate_with_saml(@response, params[:RelayState])
  if @resource.nil?
    failed_auth("Resource could not be found")
  end
end