elimity-com/scim

GitHub: elimity-com/scim

一个基于 Go 语言的 SCIM v2 规范实现库,用于快速搭建符合标准的身份资源管理 REST API 服务端。

Stars: 227 | Forks: 65

![scim-logo](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/5de58fd3d0231333.png) [![GoVersion](https://img.shields.io/github/go-mod/go-version/elimity-com/scim.svg)](https://github.com/elimity-com/scim) [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/elimity-com/scim) [![Tag](https://img.shields.io/github/tag/elimity-com/scim.svg)](https://gitHub.com/elimity-com/scim/releases) 这是一个用于 Golang 的 [SCIM v2.0](http://www.simplecloud.info/#Specification) 规范的开源实现。 SCIM 定义了一种灵活的 schema 机制和 REST API,用于管理身份数据。 其目标是通过提供使用 HTTP 交换 schema 的模式,来降低用户管理操作的复杂性。 在此实现中,利用提供的结构可以轻松添加*自定义* schema 和扩展。 传入的资源在传递给其回调函数之前,将由其相应的 schema 进行*验证*。 支持以下功能: - `/Schemas`、`/ServiceProviderConfig` 和 `/ResourceTypes` 的 GET 操作 - 针对您自己的资源类型(即 `/Users`、`/Groups`、`/Employees` 等)的 CRUD(POST/GET/PUT/DELETE 和 PATCH)操作 此版本**不**支持其他可选功能,如排序、批量等。 ## 安装说明 假设您已经安装了(较新版本的)Go 版本,您可以使用 go get 获取代码: ``` $ go get github.com/elimity-com/scim ``` ## 用法 **!** 为简单起见,错误处理已被忽略。 ### 1. 创建服务提供商配置 [RFC Config](https://tools.ietf.org/html/rfc7643#section-5) | [示例配置](https://tools.ietf.org/html/rfc7643#section-8.5) ``` config := scim.ServiceProviderConfig{ DocumentationURI: optional.NewString("www.example.com/scim"), } ``` **!** 此版本不支持额外的功能/操作。 ### 2. 创建所有支持的 schema 和扩展 [RFC Schema](https://tools.ietf.org/html/rfc7643#section-2) | [User Schema](https://tools.ietf.org/html/rfc7643#section-4.1) | [Group Schema](https://tools.ietf.org/html/rfc7643#section-4.2) | [Extension Schema](https://tools.ietf.org/html/rfc7643#section-4.3) ``` schema := schema.Schema{ ID: "urn:ietf:params:scim:schemas:core:2.0:User", Name: optional.NewString("User"), Description: optional.NewString("User Account"), Attributes: []schema.CoreAttribute{ schema.SimpleCoreAttribute(schema.SimpleStringParams(schema.StringParams{ Name: "userName", Required: true, Uniqueness: schema.AttributeUniquenessServer(), })), }, } extension := schema.Schema{ ID: "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", Name: optional.NewString("EnterpriseUser"), Description: optional.NewString("Enterprise User"), Attributes: []schema.CoreAttribute{ schema.SimpleCoreAttribute(schema.SimpleStringParams(schema.StringParams{ Name: "employeeNumber", })), schema.SimpleCoreAttribute(schema.SimpleStringParams(schema.StringParams{ Name: "organization", })), }, } ``` ### 3. 创建所有资源类型及其回调 [RFC 资源类型](https://tools.ietf.org/html/rfc7643#section-6) | [示例资源类型](https://tools.ietf.org/html/rfc7643#section-8.6) #### 3.1 回调(`ResourceHandler` 的实现) [简单的内存示例](resource_handler_test.go) ``` var userResourceHandler scim.ResourceHandler // initialize w/ own implementation ``` **!** 每个资源类型都应拥有自己的资源处理器。 #### 3.2 资源类型 ``` resourceTypes := []ResourceType{ { ID: optional.NewString("User"), Name: "User", Endpoint: "/Users", Description: optional.NewString("User Account"), Schema: schema, SchemaExtensions: []SchemaExtension{ {Schema: extension}, }, Handler: userResourceHandler, }, }, ``` ### 4. 创建服务器 ``` serverArgs := &ServerArgs{ ServiceProviderConfig: config, ResourceTypes: resourceTypes, } serverOpts := []ServerOption{ WithLogger(logger), // optional, default is no logging } server, err := NewServer(serverArgs, serverOpts...) ``` ## 向后兼容性 尽管 SCIM 包已经在一些生产环境中运行,但它仍处于早期阶段,并非所有功能都受支持。因此请注意,次版本号的变更可能会破坏您的实现。我们不会进行任何需要数小时才能修复的重大更改,但某些函数的名称或签名可能会发生变化。 `v0.1` 到 `v0.2.0` 的情况就是如此。 ## 属性的字符串值 默认情况下,SCIM 服务器**不会**对所有属性使用 `string` 类型,因为这不符合 SCIM 规范。仍然可以通过切换 `schema` 包中的标志来启用此行为。 ``` import "github.com/elimity-com/scim/schema" schema.SetAllowStringValues(true) ``` ## 额外检查/测试 并非所有内容都可以由 SCIM 服务器本身进行检查。 以下列出了一些我们期望实现能够覆盖的内容。 **!** 此列表目前尚不完整! 我们希望将此列表保持在尽可能短的程度。 如果您有想法如何在服务器本身中强制执行这些规则,请随时提交 [issue](https://github.com/elimity-com/scim/issues/new) 或 PR。 ### 可变性 #### 不可变属性 *PUT Handler*:如果属性已设置一个或多个值,则输入值必须与之匹配。 #### 只写属性 *所有 Handler*:属性值不得返回。\ 注意:这些属性通常也具有 "never" 的返回设置。 ## 贡献指南 [![Contributors](https://img.shields.io/github/contributors/elimity-com/scim.svg)](https://gitHub.com/elimity-com/scim/contributors/) 我们很乐意审查 Pull Request, 但在进行更改之前,请先通过 issue、电子邮件或任何其他方法与本仓库的所有者讨论您希望进行的更改。 如果您想提议更改,请确保以下几点: - GitHub Actions 的所有检查均通过 ([GolangCI-Lint](https://github.com/golangci/golangci-lint):`misspell`、`godot` 和 `whitespace`) - 所有现有的测试均通过。 - 您已经编写了覆盖您所编写代码的测试,确保包含边缘情况。 - 至少为您添加的所有公共函数提供了文档。 - 新的公共函数和结构体保持在最低限度。 - 应用了相同的实践(例如方法的解剖结构、名称等)。 - 您的更改符合 SCIM v2.0(作为 [RFC7642](https://tools.ietf.org/html/rfc7642)、 [RFC7643](https://tools.ietf.org/html/rfc7643) 和 [RFC7644](https://tools.ietf.org/html/rfc7644) 在 [IETF](https://ietf.org/) 下发布)。
标签:API 实现, CRUD 接口, EVTX分析, Golang, Go 语言, Homebrew安装, HTTP 服务, IAM, REST API, Schema 验证, SCIM v2, SCIM 协议, SSO, Streamlit, 云标准, 安全编程, 开源库, 搜索引擎爬虫, 日志审计, 用户管理, 系统对接, 访问控制, 资源管理, 跨域身份管理, 身份管理