我已经更新了原来的答案,希望提供一些更好的信息。
A)这个库应该(希望)是您正在寻找的:
Microsoft.SystemFor跨域身份管理
https://www.nuget.org/packages/Microsoft.SystemForCrossDomainIdentityManagement/ https://www.nuget.org/packages/Microsoft.SystemForCrossDomainIdentityManagement/
该项目的一位作者最近更新了它,以包括 v1 和 v2 SCIM 对象支持,并且您对解释该库用途的博客文章的链接绝对正确。
http://blogs.technet.com/b/ad/archive/2015/11/23/azure-ad-helping-you-adding-scim-support-to-your-applications.aspx http://blogs.technet.com/b/ad/archive/2015/11/23/azure-ad-helping-you-adding-scim-support-to-your-applications.aspx
(作者现在已将此添加到 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 = "[email protected] /cdn-cgi/l/email-protection";
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 反序列化器而不是 MS 时遇到了一个问题:
var jsonDictionary = await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject<Dictionary<string, object>>(json); });
返回了一个Dictionary<string, object>
但工厂却无法正确利用它。
您可以使用Core2User
or Core2EnterpriseUser
如果您使用的是 SCIM 规范的 v2,则为类。
此外,我相信如果您愿意,该库可以处理请求的创建(而不是自己制作它们,这看起来确实非常简单),这是该项目作者(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,他在尝试让我启动并运行该库方面提供了很大帮助 - 所以我不必手工制作所有我自己的模型类。