gristlabs / grist-core

Grist is the evolution of spreadsheets.
https://www.getgrist.com/
Apache License 2.0
7.04k stars 311 forks source link

SCIM users endpoint #1199

Open fflorent opened 3 weeks ago

fflorent commented 3 weeks ago

Context

As an IT asset administrator, I can create account of my users using a centralized solution like an SSO so they can log on Grist. It's quite convenient because I don't have to worry about creating accounts specifically for them.

Also Grist handles the update of Users when reconnect.

There are things the administrator cannot do though:

Proposed solution

SCIM is a standard proposed by the IETF through RFC7644 and RFC7643 which aims to through a simple Rest API provide solution for the above use cases.

Here is the abstract of the RFC7644 which introduces SCIM:

The System for Cross-domain Identity Management (SCIM) specification is an HTTP-based protocol that makes managing identities in multi-domain scenarios easier to support via a standardized service. Examples include, but are not limited to, enterprise-to-cloud service providers and inter-cloud scenarios. The specification suite seeks to build upon experience with existing schemas and deployments, placing specific emphasis on simplicity of development and integration, while applying existing authentication, authorization, and privacy models. SCIM's intent is to reduce the cost and complexity of user management operations by providing a common user schema, an extension model, and a service protocol defined by this document.

This PR provides the implementation of SCIM for Users Resources (Group will come in a future PR), and supports:

To do that, I take advantage of two libraries: scimmy and scimmy-routers. Scimmy is lightweight (0 dependency), and scimmy-routers will also be dependency-free be in a future version (reported in that issue and already fixed).

Two variables are introduced:

Assumption regarding the SCIM implementation

How to test manually?

I can document the API in grist-help upon request (otherwise I will do that after this PR is merged).

You may:

  1. run a local Grist server setting either the GRIST_DEFAULT_EMAIL, GRIST_SUPPORT_EMAIL or GRIST_SCIM_USER env variable without omitting to enable SCIM using GRIST_ENABLE_SCIM:
    GRIST_SCIM_USER="you@example.com" GRIST_ENABLE_SCIM=1 yarn start
  2. Generate a bearer for you@example.com
  3. then you may start using SCIM:
    $ export BEARER=<paste the bearer here>
    $ curl -H 'Content-Type: application/scim+json' -H "Authorization: Bearer $BEARER" -X POST -d '{"schemas": ["urn:ietf:params:scim:api:messages:2.0:SearchRequest"], "sortBy": "userName", "sortOrder": "descending"}' https://localhost:8484/api/scim/v2/Users/.search

I described some examples of the SCIM API usage here (they need to be adaptated for the context of Grist): https://github.com/scimmyjs/scimmy-routers/blob/8ffa2221b542054c3f0cfb765ea6957f29ebe5e1/example/README.md#play-with-the-scim-server

Limitations of the current implementation

Related issues

It partly implements #870 (Users resource only for now).

Has this been tested?

fflorent commented 2 weeks ago

Thanks @hexaltation for you feedback!

Thanks for this huge job. I think It could be great to have a documentation/scim.md file documenting at least :

* What part of the SCIM RFCs are not yet implemented,

* What part of the RFCs are "adapted" to work with grist current logic

It could be a huge time saver for administrators of instances when doing the interconnection.

I am rather planing on documenting the API in the grist-help repository and probably add a new page to explain how to setup SCIM and what is currently supported.