Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow writable complex types in extensions #61

Merged
merged 5 commits into from
Sep 21, 2023

Conversation

xjunior
Copy link
Contributor

@xjunior xjunior commented Sep 11, 2023

My goal is to be able to add groups to users, the same way we can add users to groups. Since that's not allowed by the SCIM default User schema, I have an extension type like this:

module Scim
  class UserExtension < Scimitar::Schema::Base
    def initialize(_options = {})
      super(
        name: "ExtendedUser",
        description: "Auth Service extension for a User",
        id: self.class.id,
        scim_attributes: self.class.scim_attributes
      )
    end

    def self.id
      "urn:ietf:params:scim:schemas:extension:authservice:2.0:User"
    end

    def self.scim_attributes
      [
        Scimitar::Schema::Attribute.new(name: "userGroups", multiValued: true, complexType: Scimitar::ComplexTypes::ReferenceGroup, mutability: "writeOnly"),
      ]
    end
  end
end

But I'm currently not able to use this type like this in my project:

      it "creates a user with department listed in the groups" do
        department = create(:group, :department, name: "The best department")
        groups = {
          Scim::UserExtension.id => {
            userGroups: [{ value: department.group_number.to_s }]
          }
        }

        post(api_scim_users_path, params: user_params.deep_merge(groups).to_json, headers:)

        expect(response).to have_http_status(:created)
        expect(response.parsed_body.dig(Scim::UserExtension.id, "userGroups")).to eq([{ value: department.group_number.to_s, display: "The best department" }])
      end

Without this patch, this is what I get:

  {
    "schemas": [
      "urn:ietf:params:scim:api:messages:2.0:Error"
    ],
    "detail": "Invalid resource: Usergroups has to follow the complexType format..",
    "status": "400",
    "scimType": "invalidValue"
  }

Because [{ value: "123" }] never gets cast to the complex type.

Ps.: this is the generated request in the above example:

{
    "schema": [
      "urn:ietf:params:scim:schemas:core:2.0:User",
      "urn:ietf:params:scim:schemas:extension:authservice:2.0:User"
    ],
    "externalId": 12345,
    "userName": "jane.doe",
    "displayName": "Jane Doe",
    "name": {
      "familyName": "Doe",
      "givenName": "Jane",
      "formatted": "Jane Doe"
    },
    "urn:ietf:params:scim:schemas:extension:authservice:2.0:User": {
      "userGroups": [
        {
          "value": "1"
        }
      ]
    }
  }

@pond
Copy link
Member

pond commented Sep 16, 2023

This looks interesting but a test fails. Hopefully an easy fix! Please ensure that bundle exec rspec works under Ruby 3.2.x.

I also have the same request as for #62 - it needs docs in README.md. In this case, your PR description (parts about the faults prior to your mods aside) looks like it could fit the bill as another example under the Extension section at around line 378 of README.md in v2.4.3. Extension support in one of the gems that were a foundation for Scimitar was not documented and IMHO confusingly implemented, so I've never had that strong a grasp of it even as the majority author of this descendent gem; I did the best I could with docs for Scimitar but it's always been a bit underwhelming.

@xjunior
Copy link
Contributor Author

xjunior commented Sep 17, 2023

@pond I'll be giving some more love to this work after this wed, thanks for reviewing!

@xjunior
Copy link
Contributor Author

xjunior commented Sep 20, 2023

This looks interesting but a test fails. Hopefully an easy fix! Please ensure that bundle exec rspec works under Ruby 3.2.x.

I also have the same request as for #62 - it needs docs in README.md. In this case, your PR description (parts about the faults prior to your mods aside) looks like it could fit the bill as another example under the Extension section at around line 378 of README.md in v2.4.3. Extension support in one of the gems that were a foundation for Scimitar was not documented and IMHO confusingly implemented, so I've never had that strong a grasp of it even as the majority author of this descendent gem; I did the best I could with docs for Scimitar but it's always been a bit underwhelming.

I agree… Reading through the docs gave me the sense that it deserves some reorganization, updates and to dig a bit further on some topics. This is in my backlog, but might be a bit down the list.

Copy link
Member

@pond pond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good now - thanks for the docs additions.

@pond pond merged commit bd31724 into RIPAGlobal:main Sep 21, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants