Coder Social home page Coder Social logo

scim_engine's Introduction

ScimEngine

Build Status

Why ScimEngine Exists?

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 and protocol, which may take a significant overhead compared the implementation of the actual APIs. This project aims to extract SCIM specifics as a rails engine that can be plugged into a Ruby on Rails project.

How to Use?

In your Gemfile, add:

gem 'scim_engine'

Mount this engine in config/routes:

namespace :scim do
  mount ScimEngine::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 provide routes / controllers accordingly. For example, to support the User resource type, add the following to your routes:

namespace :scim do
  get 'Users/:id', to: 'users#show', as: :user
  post 'Users', to: 'users#create'
  put 'Users/:id', to: 'users#update'
  delete 'Users/:id', to: 'users#destroy'
  mount ScimEngine::Engine => '/'
end

Add your controller:

# app/controllers/scim/users_controller.rb

module Scim

  # 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.

  class UsersController < ScimEngine::ResourcesController

    def show
      super do |user_id|
        user = find_user(user_id)
        user.to_scim(location: url_for(action: :show, id: user_id))
      end
    end

    def create
      super(resource_type, &method(:save))
    end

    def update
      super(resource_type, &method(:save))
    end

    def destroy
      super do |user_id|
        user = find_user(user_id)
        user.delete
      end
    end


    protected

    def save(scim_user, is_create: false)
      #convert the ScimEngine::Resources::User to your application object
      #and save
    rescue ActiveRecord::RecordInvalid => exception
      # Map the enternal errors to a ScimEngine error
      raise ScimEngine::ResourceInvalidError.new()
    end

    # tell the base controller which resource you're handling
    def resource_type
      ScimEngine::Resources::User
    end

    def find_user(user_id)
      # find your user
    end

  end
end

To support custom Resource types, simply add a controller and provide the custom resource type via the resource_type method.

scim_engine's People

Contributors

smnasehi avatar smsohan avatar ryanmojo avatar dependabot[bot] avatar michdsouza avatar

Stargazers

Ivan Nemytchenko avatar Ian Eccles avatar Samridh Srinath avatar Tomáš Hromada avatar Jean-Marc Lagacé avatar Ryan Taylor Long avatar Josh Chan avatar Snake avatar Mason Hensley avatar

Watchers

 avatar  avatar James Cloos avatar Rodolfo avatar Duck Dodgers avatar  avatar Prakash Patel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.