Giter Club home page Giter Club logo

identityui's Introduction

IdentityUI

stable

IdentityUI is a simple platform for administrative management of users and admins with a graphical interface. It is easy to set up, has a clean API, and runs on all recent .NET Core releases.

Nuget

Install SSRD.IdentityUI NuGet package.

AppSettings:

"IdentityUI": {
  "BasePath": "http://localhost:5000",
  "Database": {
    "Type": "PostgreSql",
    "ConnectionString": "UserID={User};Password={Password};Host={IP};Port={Port};Database={DatabaseName};Pooling=true;"
  },
  "EmailSender": {
    "Ip": "{Ip}",
    "Port": "{Port}",
    "Username": "{Username}",
    "Password": "{Password}",
    "SenderName": "{Sender}"
  }
}

EmailSender options are optional if you provide custom implementation of IEmailSender or don't want to use an EmailSender.

Startup

In ConfigureServices add:

services.ConfigureIdentityUI(Configuration) // Configures IdentityUI. You can pass in your own identityUI options.
    .AddIdentityUI() // Adds IdentityManagement core services.
    .AddAuth() // Adds Authentication. You can pass in your own CookieAuthenticationOptions.
    .AddEmailSender() // Optional if you provide  custom implementation of IEmailSender
    .AddIdentityAdmin() // Adds services for IdentityAdminUI
    .AddAccountManagement(); // Adds services for AccountManagement.

In Configure add:

app.UseIdentityUI(); // Adds IdentityUI   

.NET Core 2:
In app.UseMvc() add

routes.MapAccountManagement(); // Adds AccountManagement UI
routes.MapIdentityAdmin(); // Adds IdentityAdmin UI

For adding admin app.SeedIdentityAdmin("admin", "Password");

Important: If you are using .NET Core 3 remove app.UseAuthorization();

IdentityAdmin Dashboard: {server}:{port}/IdentityAdmin/
Account management: {server}:{port}/Account/Manage/

Database

Supported databases: PostgreSQL, InMemory (only for testing).

InMemory database provider for .NetCore3+ may not be able translate all the queries and cause exceptions.

To create database:

serviceProvider.RunIdentityMigrations();

To seed IdentityUI required entities:

serviceProvider.SeedSystemEntities();

or

serviceProvider.SeedMissingSystemEntities();

All of this functions are available as extensions on IServiceProvider, IHost, IWebHost or IApplicationBuilder

Groups

From version 2.0, we are supporting a group/multi-tenant management. For this purpose, we created multiple group roles that are linked to permission inside group/tenant management.

Permission Description
group_can_manage_attributes Can manage group attributes
group_can_remove_users Can remove users from group
group_can_manage_roles User can assign roles inside the group
group_can_invite_users Can invite new users to this group
group_can_manage_invites Can see and edit invites
group_can_see_users User can see other members in group
identity_ui_can_manage_groups Can add new groups and can edit existing groups
group_can_add_existing_users Can add existing users. Note: This will expose all users from Identity server!

Advanced configuration

Configure IdentityUI

ConfigureIdentityUI(Configuration, endpoints => 
{
    endpoints.Home = "/";

    endpoints.Login = "/Account/Login/";
    endpoints.Logout = "/Account/Logout/";
    endpoints.AccessDenied = "/Account/AccessDenied/";

    endpoints.Manage = "/Account/Manage/";
    endpoints.ConfirmeEmail = "/Account/ConfirmEmail";
    endpoints.ResetPassword = "/Account/ResetPassword";

    endpoints.RegisterEnabled = true;
    endpoints.UseEmailSender = false;
}) // These are the default endpoints options.

Identity policy

AddIdentityUI(options =>
{
    options.Password.RequireDigit = false;
    options.Password.RequiredLength = 6;
    options.Password.RequiredUniqueChars = 0;
    options.Password.RequireLowercase = true;
    options.Password.RequireUppercase = true;
    options.Password.RequireNonAlphanumeric = false;

    options.SignIn.RequireConfirmedEmail = true;
    options.SignIn.RequireConfirmedPhoneNumber = false;

    options.Lockout.AllowedForNewUsers = true;
    options.Lockout.MaxFailedAccessAttempts = 5;
    options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
}) // These are the default identity options.

Identity options

AddAuth(options => 
{
    options.Cookie.HttpOnly = true;
    options.LoginPath = "/Account/Login/";
    options.AccessDeniedPath = "/Account/AccessDenied/";
    options.SlidingExpiration = true;
    options.LogoutPath = "/Account/Logout/";
}) // These are the default cookie options.

Configuring SMS gateway

To be able to use SMS sending functionality within IdentityUI you fill first need to configure the system to communication with your SMS gateway. In this example we will show how the Twilio API can be configured.

First you will need to create a Twilio account. You can do that here. When your account is ready, you will need update the appsettings.json file with API access token. For example:

"IdentityUI": {
  "SmsGateway": {
    "Sid": "",
    "Token": "",
    "FromNumber": ""
  }
}

The names of the property can differ from provider to provider, but in general:

  • Sid should contain the username/account ID
  • Token should contain the password/API access token
  • FromNumber should contain the phone number, which is used to send the SMS messages

After updating the appsettings.json file, you need to add and implementation of the ISmsSender interface to your project. A simple Twilio implementation can look something like this:

public class TwilioSmsSender : ISmsSender
{
    private readonly PhoneNumber _from;

    public TwilioSmsSender(string sid, string token, string from)
    {
        TwilioClient.Init(sid, token);
        _from = new PhoneNumber(from);
    }

    public Task<Result> Send(string to, string message)
    {
        try
        {
            MessageResource result = MessageResource.Create(
                from: _from,
                to: new PhoneNumber(to),
                body: message);

            return Task.FromResult(Result.Ok());
        }
        catch (Exception ex)
        {
            return Task.FromResult(Result.Fail("twilio_error", "Sending SMS failed"));
        }
    }
}

// add the class to the DI container
services.AddScoped<ISmsSender, TwilioSmsSender>(options =>
{
    string sid = Configuration["IdentityUI:SmsGateway:Sid"];
    string token = Configuration["IdentityUI:SmsGateway:Token"];
    string from = Configuration["IdentityUI:SmsGateway:FromNumber"];

    return new TwilioSmsSender(sid, token, from);
});

Finally, you need to tell the system that the sms gateway is configured. To do that, you need to update the configuration in the Setup.cs file and adding the following line:

services.ConfigureIdentityUI(Configuration, endpoints =>
{
  endpoints.UseSmsGateway = true;
})

With that, you should have SMS sending functionality available in your system.

Setting up an SMS gateway also enables SMS two-factor authentication for the users of your system.

Support

For custom feature request or technical support contact us at identity[at]ssrd.io

Credits

identityui's People

Contributors

gregorspagnolo avatar jtone123 avatar urbanvogrin avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.