
There's no general purpose SCIM SDK for Ruby on Rails. As a result,anyone implementing SCIM will need to take care of the SCIM schema andprotocol, which may take a significant overhead compared theimplementation of the actual APIs. This project aims to extract SCIMspecifics as a rails engine that can be plugged into a Ruby on Railsproject.
In your Gemfile, add:
gem 'scim_engine'
Mount this engine in config/routes:
namespace:scimdomountScimEngine::Engine=>'/'end
This will provide you with routes for ServerProviderConfig, Schemas,and ResourceTypes under/scim
prefix.
You can decide which SCIM resources you want to support, and provideroutes / controllers accordingly. For example, to support theUser
resource type, add the following to your routes:
namespace:scimdoget'Users/:id',to:'users#show',as::userpost'Users',to:'users#create'put'Users/:id',to:'users#update'delete'Users/:id',to:'users#destroy'mountScimEngine::Engine=>'/'end
Add your controller:
# app/controllers/scim/users_controller.rbmoduleScim# ScimEngine::ResourcesController uses a template method so that the# subclasses can provide the fillers with minimal effort solely focused on# application code leaving the SCIM protocol and schema specific code within the# engine.classUsersController <ScimEngine::ResourcesControllerdefshowsuperdo |user_id|user=find_user(user_id)user.to_scim(location:url_for(action::show,id:user_id))endenddefcreatesuper(resource_type, &method(:save))enddefupdatesuper(resource_type, &method(:save))enddefdestroysuperdo |user_id|user=find_user(user_id)user.deleteendendprotecteddefsave(scim_user,is_create:false)#convert the ScimEngine::Resources::User to your application object#and saverescueActiveRecord::RecordInvalid=>exception# Map the enternal errors to a ScimEngine errorraiseScimEngine::ResourceInvalidError.new()end# tell the base controller which resource you're handlingdefresource_typeScimEngine::Resources::Userenddeffind_user(user_id)# find your userendendend
To support customResource
types, simply add a controller and providethe custom resource type via theresource_type
method.