[英]SCIM (System for Cross-domain Identity Management) library for C#
SCIM 標准旨在通過定義表示用戶和組的模式以及用於所有必要 CRUD 操作的 REST API 來簡化雲中的用戶管理。
它旨在取代舊的 SPML 協議。
是否有任何“成熟”的 C# 庫?
我在 google 上搜索的大部分內容都是針對 Java 的,否則似乎不太活躍。
更新:
回應評論:
這些庫通常采用以下形式:
User = new User;
User.name = "name";
... etc ...
User.Create;
換句話說,它通過使用模型用戶隱藏了底層實現。 這樣您就不必擔心實際協議的細節。
我已經更新了我的原始答案,希望能提供一些更好的信息。
A)這個庫應該(希望)是你正在尋找的:
Microsoft.SystemForCrossDomainIdentityManagement
https://www.nuget.org/packages/Microsoft.SystemForCrossDomainIdentityManagement/
該項目的一位作者最近對其進行了更新,以包含 v1 和 v2 SCIM 對象支持,並且您對解釋該庫用途的博客文章的鏈接完全正確。
(作者現在已將此添加到關於 nuget 的摘要中,因此在閱讀博客文章之前找到 nuget 庫的人不會像我一樣困惑)。
這是一個基於 GET 請求(到 Facebook)反序列化用戶的示例,您可以輕松地創建一個新的用戶對象並在將其 POST 或 PUT 輸入系統之前設置其屬性等。
public static async Task GetUser()
{
var oauthToken = "123456789foo";
var baseUrl = "https://www.facebook.com/company/1234567890/scim/";
var userName = "foo@bar.com";
using (var client = new HttpClient())
{
// Set up client and configure for things like oauthToken which need to go on each request
client.BaseAddress = new Uri(baseUrl);
// Spoof User-Agent to keep Facebook happy
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", oauthToken);
try
{
var response = await client.GetAsync($"Users?filter=userName%20eq%20%22{userName}%22");
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
// This is the part which is using the nuget library I referenced
var jsonDictionary = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(json);
var queryResponse = new QueryResponseJsonDeserializingFactory<Core1EnterpriseUser>().Create(jsonDictionary);
var user = queryResponse.Resources.First();
}
catch (Exception ex)
{
// TODO: handle exception
}
}
}
我最初使用 Newtonsoft deserialzier 而不是 MS 時遇到了一個問題:
var jsonDictionary = await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject<Dictionary<string, object>>(json); });
返回一個Dictionary<string, object>
但工廠無法正確使用它。
如果您使用的是 SCIM 規范的 v2,則可以使用Core2User
或Core2EnterpriseUser
類。
此外,我相信圖書館可以根據需要處理請求的創建(而不是自己制作它們,這看起來確實很簡單),這是項目作者(Craig McMurtry)的另一個片段
/*
* SampleProvider() is included in the Service library.
* Its SampleResource property provides a 2.0 enterprise user with values
* set according to the samples in the 2.0 schema specification.
*/
var resource = new SampleProvider().SampleResource;
// ComposePostRequest() is an extension method on the Resource class provided by the Protocols library.
request = resource.ComposePostRequest("http://localhost:9000");
我希望這一切都會有所幫助,非常感謝 Microsoft 的 Craig McMurtry,他在嘗試讓我啟動和運行庫方面非常有幫助 - 所以我不必手工制作我自己的所有模型類。
請評估開源項目, https://github.com/PowerDMS/Owin.Scim 。 我一直在領導這項開發工作。 雖然它缺少一些 Microsoft 已經很好地實現的功能,但它在 scim 的大多數其他領域中要完整得多。 看看它是否符合您的需求,我們歡迎所有反饋,以幫助塑造 owin.scim 的未來。
我推薦SimpleIdServer.Scim
https://github.com/simpleidserver/SimpleIdServer作為替代方案。 我最終沒有使用 web api,但它仍然可以滿足我的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.