The SCIM standard was created to simplify user management in the cloud by defining a schema for representing users and groups and a REST API for all the necessary CRUD operations.
It is intended to replace the older SPML protocol.
Are there any "mature" C# libraries out there?
Most of the stuff I've googled is for Java or else doesn't seem very active.
Update:
In response to the comment:
These libraries are usually of the form:
User = new User;
User.name = "name";
... etc ...
User.Create;
In other words, it hides the underlying implementation by using a model user. That way you don't have to worry about the details of the actual protocol.
I've updated my original answer to hopefully provide some better information.
A) This library should (hopefully) be what you're looking for:
Microsoft.SystemForCrossDomainIdentityManagement
https://www.nuget.org/packages/Microsoft.SystemForCrossDomainIdentityManagement/
One of the authors of the project recently updated it to include v1 and v2 SCIM object support and you were absolutely correct with your links to the blog posts which explains the library's purpose.
(The author has now added this to the summary on nuget so people who find the nuget library before reading the blog post won't be as confused as I was).
Here's an example of deserialzing a user based on a GET request (to Facebook), you can easily create a new user object and set it's properties etc. before POST or PUT'ing it into the system.
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
}
}
}
I initially ran into an issue using the Newtonsoft deserialzier rather than the MS one:
var jsonDictionary = await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject<Dictionary<string, object>>(json); });
Returned a Dictionary<string, object>
but the factory couldn't make proper use of it.
You can use the Core2User
or Core2EnterpriseUser
classes if you're using v2 of the SCIM spec.
Furthermore the library, I believe can handle the creation of requests if you want (rather than crafting them yourself which does seem to be pretty straightforward anyway), here's another snippet from the author of the project (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");
I hope this all helps, a massive amount of thanks are due to Craig McMurtry at Microsoft who has been very helpful in trying to get me up and running with the library - so I don't have to hand craft all my own model classes.
Please evaluate the open source project, https://github.com/PowerDMS/Owin.Scim. I've been leading this development effort. While it's missing a few features that Microsoft has implemented quite well, it is far more complete in most other areas of scim. See if it fits your needs and we welcome all feedback to help shape the future of owin.scim.
来源:https://stackoverflow.com/questions/16390464/scim-system-for-cross-domain-identity-management-library-for-c-sharp