OAuth2 Walkthrough using Identity Server and ASP.NET

Extending Identity Server with Identity Manager (pre-release)

Index

Creating an identity server using Aspnet Identity and Entity Framework storage
Extending Identity Server with Identity Manager (pre-release)
Configuring and loading client and scope data with the CLI
Creating an MVC Client using Resource Authorization

Introduction

With just a few extra packages and services added, Identity Server can be extended, providing a Angular user interface for the ASP.NET Identity model.

Note: The management packages are pre-release at the time of authoring

Required Packages

Add the required package below, noting the pre-release switch

install-package IdentityManager.AspNetIdentity -pre

Add the Manager Service

Add a IdentityManagerService.cs class to the Services folder, pasting the code below

using IdentityManager.AspNetIdentity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace OAuth2Demo.IdentityServer.Services {
    public class IdentityManagerService : AspNetIdentityManagerService {
        public IdentityManagerService(UserManager userManager, RoleManager roleManager)
            : base(userManager, roleManager) {
        }
    }
}

Add the Manager Service Extension Method

Add a IdentityManagerServiceExtensions .cs class to the Extensions folder, pasting the code below

using OAuth2Demo.IdentityServer;
using OAuth2Demo.IdentityServer.Services;

namespace IdentityManager.Configuration {
    public static class IdentityManagerServiceExtensions {
        public static IdentityManagerServiceFactory Configure(this IdentityManagerServiceFactory factory, string connectionString) {

            factory.Register(new Registration<Context>(resolver => new Context(connectionString)));
            factory.Register(new Registration<UserStore>());
            factory.Register(new Registration<RoleStore>());
            factory.Register(new Registration<UserManager>());
            factory.Register(new Registration<RoleManager>());

            factory.IdentityManagerService = new IdentityManager.Configuration.Registration<IIdentityManagerService, IdentityManagerService>();

            return factory;
        }
    }
}

Register the Manager

Within the start up class, adding the following code will register the manger.

        public void Configuration(IAppBuilder app) {
            string connectionString = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;

            app.Map("/identity", id => {
                id.UseIdentityServer(new IdentityServerOptions {
                    SiteName = "Demo Identity Server",
                    Factory = new IdentityServerServiceFactory().Configure(connectionString),
                    SigningCertificate = LoadCertificate()
                });

            });

            app.Map("/admin", adminApp => {
                adminApp.UseIdentityManager(new IdentityManagerOptions() {
                    Factory = new IdentityManagerServiceFactory().Configure(connectionString)
                });
            });

        }

Spin it up...

Starting the application and navigating to /admin you are now presented with an Angular replacement to the old ASP.NET Web Site Administration Tool for a relatively few lines of code...

Identity Manager Users Identity Manager Edit User

Resources

https://github.com/IdentityManager/IdentityManager

Source Code

git clone https://github.com/mindfulsoftware/oauth2Demo.git