ruby authentication client for forgerock OpenAM server (http://forgerock.com/products/open-identity-stack/openam/), this ruby client will work with OpenAM Policy Agent for Nginx https://bitbucket.org/hamano/nginx-mod-am
Read more about OpenAM REST api
https://wikis.forgerock.org/confluence/display/openam/Use+OpenAM+RESTful+Services
Add this line to your application's Gemfile:
gem 'openam_auth'
And then execute:
$ bundle
Or install it yourself as:
$ gem install openam_auth
rspec
- install the gem (as described above)
- create a file in
config/initializers
#config/initializers/openam_config.rb
OpenamConfig.config do
openam_url <Path to your openam server>
end- openam_auth assumes you have a
Usermodel in you project and it has the following two methods implemented
class User
# sends the token (from openam server) as a parameter
def self.existing_user_by_token(token)
# this method should return a user object, if matching record found
# or nil if there are not matching record found
end
# authentication token from OpenAm server
# user hash
# ex: { "sn" => ["admin"] }
# NOTE: hash will have the key and value array
def self.update_openam_user(token, hash)
#this method should either update the existing user token, if user found
#or create a new user and return that user
end
endNote, you may want to add some more columns for the existing users table to accomodate the values passed by the hash. Read the section 3.5. Token Validation, Attribute Retrieval http://openam.forgerock.org/openam-documentation/openam-doc-source/doc/dev-guide/#rest-api-auth for more info.
- in your controller ,
Ex: ApplicationController, include theOpenamAuth::Authenticatemodule
class ApplicationController < ActionController::Base
include OpenamAuth::Authenticate
end5 . Finally implement the before_filter for authenticate_user!
before_filter :authenticate_user! 6 . For logout you could use openam_logout with current user token from your controller
openam_logout(<current user token>)https://github.com/tychobrailleur/openam-sample
http://speakmy.name/2011/05/29/simple-configuration-for-ruby-apps/
http://say26.com/rspec-testing-controllers-outside-of-a-rails-application
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request