Document Management
How To and Troubleshooting
A custom security provider is a compiled DLL file that implements the interfaces specified by Wyn Enterprise. It provides access to your users so that they can log in with their existing user names and passwords and so that you can use existing groups to provide access to specific data.
Start Visual Studio 2019.
In the Create a New Project dialog, choose Class Library (.NET Standard) template and then select Next.
In the Configure your new project dialog that appears, enter the project name and its location, and then click Create.
Right-click the Dependencies node under the Solution Explorer and select Manage Nuget Packages.
The interface implemented by the custom security provider is defined by several packages, so you need to add the following package dependencies in the project.
GrapeCity.Enterprise.Identity.SecurityProvider
GrapeCity.Enterprise.Identity.ExternalIdentityProvider
Browse the above package dependencies in the Nuget Package Manager dialog, and then select Install.
To implement the ISecurityProviderFactory, add a new class file and name it MySecurityProviderFactory.cs. This interface specifies two properties and one method:
Public string Description // Description string of this security provider.
Public string ProviderName // Name of this security provider
Public IEnumerable SupportedSettings // User configuration items supported by this security provider.
Implement the following function to create your security provider instance.
public Task<ISecurityProvider> CreateAsync(IEnumerable<ConfigurationItem> settings, ILogger logger) { return Task.FromResult<ISecurityProvider>(new MySecurityProvider(settings)); }
Implement the ISecurityProvider interface. There are interfaces such as IExternalUserDescriptor and IExternalUserContext. These interfaces only specify the attributes of the entity class, and these interfaces can be implemented using a custom class. For a detailed description of the interface, please refer ISecurityProvider Interface.
Note : In the implementation function of each interface, you must use the try-catch exception handling, where the exception handling part of catch must return the Task object. For example: return Task.FromResult\<T\>(null ); where T is a type, specified by the interface function.
Note : In the implementation function of each interface, you must use the try-catch exception handling, where the exception handling part of catch must return the Task object. For example:
return Task.FromResult\<T\>(null );
where T is a type, specified by the interface function.
Press F6 to build the solution. After the custom security provider library is built, you can configure the provider in the Wyn Enterprise Admin Portal. For more information about Security Providers, visit this topic.
Find the complete custom provider sample with SQL database on GitHub.
For a detailed description of the interfaces, refer to the tables below that lists the attributes and methods of an interface along with its description.
Interface Definition
public interface ISecurityProviderFactory { string ProviderName { get; } string Description { get; } IEnumerable<ConfigurationItem> SupportedSettings { get; } Task<ISecurityProvider> CreateAsync(IEnumerable<ConfigurationItem> settings); }
Interface Description
Note : These configuration items are displayed in the Admin portal, allowing the system administrator to do some configurations. A typical configuration item is the connection string to the user information database. By providing such configuration item, you avoid hard-coding in your security provider.
public interface ISecurityProvider { string ProviderName { get; } Task DisposeTokenAsync(string token); Task<string> GenerateTokenAsync(string username, string password, object customizedParam = null); Task<IExternalUserContext> GetUserContextAsync(string token); Task<IExternalUserDescriptor> GetUserDescriptorAsync(string token); Task<string[]> GetUserOrganizationsAsync(string token); Task<string[]> GetUserRolesAsync(string token); Task<bool> ValidateTokenAsync(string token); }
public interface IExternalUserDescriptor { string ExternalUserId { get; } string ExternalUserName { get; } string ExternalProvider { get; } }
public interface IExternalUserContext { IEnumerable<string> Keys { get; } Task<string> GetValueAsync(string key); Task<IEnumerable<string>> GetValuesAsync(string key); }
Note : Do not use the following string for the user context key: sub, name, auth_time, idp, userid, email.