This quickstart will walk you through a basic implementation of a SCIM Client.
NuGet Installation
To start, you will need to install our SCIM component from NuGet:
install-package Rsk.AspNetCore.Scim -pre
This component requires a license which you can get by signing up for a demo or purchasing via sales@identityserver.com.
Adding a SCIM Client
To modify your application to become a SCIM Client using the SCIM component, call the AddScimClient
method on IServiceCollection
. The AddScimClient
call will return a ScimClientBuilder
that exposes methods for registering new SCIM resources as well as service providers. When using the SCIM Client, you will need to provide mappers for the SCIM resources that you wish to register. These mappers will need to implement the IResourceMapper<TCustomResource, TScimResource>
interface, where TCustomResource
is the client's representation of the resource and TScimResource
is the formal representation of the resource and must inherit from Resource
.
Getting Started
The easiest way to test the SCIM component as a client is to create a custom resource that represents a SCIM user, create a mapper and register these resources with the SCIM component alongside a service provider.
public class ClientUser
{
public string UserName { get; set; }
public Name Name { get; set; }
public string DisplayName { get; set; }
public string NickName { get; set; }
public string ScimId { get; set; }
}
public class UserMapper : IResourceMapper<ClientUser, User>
{
public User ToScimResource(ClientUser resource)
{
return new User
{
UserName = resource.UserName,
DisplayName = resource.DisplayName,
NickName = resource.NickName,
Name = new Rsk.AspNetCore.Scim.Models.Name
{
GivenName = resource.Name.GivenName
},
Id = resource.ScimId
};
}
public ClientUser FromScimResource(User scimResource)
{
return new ClientUser
{
UserName = scimResource.UserName,
DisplayName = scimResource.DisplayName,
NickName = scimResource.NickName,
Name = new Name
{
GivenName = scimResource.Name.GivenName
},
ScimId = scimResource.Id
};
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddScimClient()
.AddUser<ClientUser, UserMapper>()
.AddServiceProvider("ServiceProviderName", "http://localhost:5000/SCIM/");
}
Once you have configured your client and service provider, you can access a SCIM Client through dependency injection. Inject the ScimClient<TCustomResource, TScimResource>
, where TCustomResource is the client representation of the resource and TScimResource is the SCIM resource. This should match your registration. For example, if you called AddUser<ClientUser, UserMapper>
or AddResource<ClientUser, User, UserMapper>
, you would inject IScimClient<ClientUser, User>
.
public class UserService
{
public UserService(IScimClient<ClientUser, User> scimClient)
{
this.scimClient = scimClient ?? throw new ArgumentNullException(nameof(scimClient));
}
public async Task Create(ClientUser user)
{
var scimResult = await scimClient.Create(user, default);
if(scimResult.IsSuccess)
{
...
}
else
{
...
}
}
}