Commit 7a26d98
Changed files (4)
app
controllers
scim
config
initializers
spec
requests
scim
app/controllers/scim/v2/schemas_controller.rb
@@ -6,22 +6,19 @@ module Scim
skip_before_action :authenticate!
def index
- render json: [schema.user, schema.group].to_json
+ render json: schemas.values.to_json
end
def show
+ current_schema = schemas[params[:id]]
+ raise ActiveRecord::RecordNotFound unless current_schema
render json: current_schema.to_json
end
private
- def current_schema(url = request.original_url)
- return schema.group if url.include?(Scim::Kit::V2::Schemas::GROUP)
- return schema.user if url.include?(Scim::Kit::V2::Schemas::USER)
- end
-
- def schema
- SCIM::Schema
+ def schemas
+ Scim::Kit::V2.configuration.schemas
end
end
end
config/initializers/scim_kit.rb
@@ -17,5 +17,54 @@ ActiveSupport::Notifications.subscribe 'proof.routes_loaded' do
x.schema = Scim::Kit::V2::Schemas::GROUP
x.endpoint = url_helpers.scim_v2_groups_url
end
+ config.schema(id: Scim::Kit::V2::Schemas::USER, name: "User", location: url_helpers.scim_v2_schema_url(id: Scim::Kit::V2::Schemas::USER)) do |schema|
+ schema.add_attribute(name: 'userName') do |x|
+ x.required = true
+ x.uniqueness = :server
+ end
+ schema.add_attribute(name: 'password') do |x|
+ x.mutability = :write_only
+ x.required = false
+ x.returned = :never
+ end
+ schema.add_attribute(name: 'emails') do |x|
+ x.multi_valued = true
+ x.add_attribute(name: 'value')
+ x.add_attribute(name: 'primary', type: :boolean)
+ end
+ schema.add_attribute(name: 'groups') do |x|
+ x.multi_valued = true
+ x.mutability = :read_only
+ x.add_attribute(name: 'value') do |y|
+ y.mutability = :read_only
+ end
+ x.add_attribute(name: '$ref', type: :reference) do |y|
+ y.reference_types = %w[User Group]
+ y.mutability = :read_only
+ end
+ x.add_attribute(name: 'display') do |y|
+ y.mutability = :read_only
+ end
+ end
+ schema.add_attribute(name: 'timezone')
+ schema.add_attribute(name: 'locale')
+ end
+ config.schema(id: Scim::Kit::V2::Schemas::GROUP, name: "Group", location: url_helpers.scim_v2_schema_url(id: Scim::Kit::V2::Schemas::GROUP)) do |schema|
+ schema.add_attribute(name: 'displayName')
+ schema.add_attribute(name: 'members') do |x|
+ x.multi_valued = true
+ x.add_attribute(name: 'value') do |y|
+ y.mutability = :immutable
+ end
+ x.add_attribute(name: '$ref') do |y|
+ y.reference_types = %w[User Group]
+ y.mutability = :immutable
+ end
+ x.add_attribute(name: 'type') do |y|
+ y.canonical_values = %w[User Group]
+ y.mutability = :immutable
+ end
+ end
+ end
end
end
config/routes.rb
@@ -43,7 +43,7 @@ Rails.application.routes.draw do
get :Schemas, to: 'schemas#index'
get 'Schemas/:id', to: "schemas#show"
- resources :schemas, only: [:index, :show]
+ resources :schemas, only: [:index, :show], constraints: { id: /.+/ }
get :ServiceProviderConfig, to: "service_providers#show"
spec/requests/scim/v2/resource_types_spec.rb
@@ -5,8 +5,8 @@ require 'rails_helper'
RSpec.describe "/scim/v2/ResourceTypes" do
let(:headers) do
{
- 'Accept' => 'application/scim+json',
- 'Content-Type' => 'application/scim+json',
+ 'Accept' => Mime[:scim].to_s,
+ 'Content-Type' => Mime[:scim].to_s,
}
end