SamlCamel - (not production ready)

Installation

Add this line to your application's Gemfile:

  gem 'saml_camel'

And then execute:

$ bundle

Usage

IMPORTANT!

  1. in your environments config (config/development.rb for example) ensure that you have caching configured as follows

    config.action_controller.perform_caching = true
    config.cache_store = :memory_store
    
  2. run rake saml_camel:generate_saml to generate metadata files for each environment. you can also specify a specifc/custom environment like this rake saml_camel:generate_saml environment=acceptance

Note: these steps will use development as an example, if you use seperate metadata per environemtn, you will repeat each step for your chosed environement

  1. from the root of your app open saml/development/settings.json and specify an entity ID of your choice. this is a unique identifier used by the Identity Provider(idp) to recognize your app. Typically it should take the form of a url, however note that it is just an identifier and does not have to be routeable (e.g. https://my-app-name/not/a/real/route)

  2. Go to https://idms-web.oit.duke.edu/spreg/sps and register your metadata with the identity provider. You will need the values from saml/development/settings.json in addition to the saml/development/saml_certificate.crt

  • copy the entity_id you chose in the settings.json file and paste it into the "Entity Field"
  • fill out functional purpose, responsible dept, function owner dept, and audience with information relevent to your application
  • copy the cert from saml/development/saml_certificate.crt and paste it into the Certificate Field
  • copy the acs value and paste it into the Location field in the Assertion Consumer Service box
    • note that the default host value for ACS is http://locahost:3000 which is the default rails s host. If you're using a differnet host (such as in production or using docker) you will want to replace the host value with what is relevent for your situation(e.g. https://my-app.duke.edu/saml/consumeSaml), but keep the path /saml/consumeSaml
  1. In your app mount the engine in config/routes.rb

    mount SamlCamel::Engine, at: "/saml"
    
  2. include saml helpers in app/controllers/application_controller.rb

    class ApplicationController < ActionController::Base
    include SamlCamel::SamlHelpers
    end
    
  3. now simply provide the saml protect method in your controllers (via before_action) to protect paths

class DashboardController < ApplicationController
  before_action :saml_protect, except: [:home]

  def home
  end

  def index
  end

end
  1. to logout simply make a post to localhost:3000/saml/logout. This will kill the local saml session, and the session with the identity provider.

  2. response attributes found in session[:saml_attributes]

  3. It is recommended to set config.force_ssl = true in the config/environments/production.rb file

  4. Logging is turned on by default. Logging is configured in saml/development/settings.json. To utilize logging saml_logging should be set to true (default), and primary_id must have a value. primary_id is the saml attribute you consider to be a primary identifier for a user

  5. Users can go to http://localhost:3000/saml/attributes to view attributes being passed through

License

The gem is available as open source under the terms of the MIT License.