README.md 17.3 KB
Newer Older
1
![Logo](docs/Images/Skoruba.IdentityServer4.Admin-Logo-ReadMe.png)
2

3
4
# Skoruba.IdentityServer4.Admin

5
> The administration of the IdentityServer4 and Asp.Net Core Identity
6

7
## Project Status
8

Jan Škoruba's avatar
Jan Škoruba committed
9
[![Build status](https://ci.appveyor.com/api/projects/status/5yg59bn70399hn6s/branch/master?svg=true)](https://ci.appveyor.com/project/JanSkoruba/identityserver4-admin/branch/master)
10
[![Build Status](https://dev.azure.com/skoruba/IdentityServer4.Admin/_apis/build/status/IdentityServer4.Admin-CI?branchName=master)](https://dev.azure.com/skoruba/IdentityServer4.Admin/_build/latest?definitionId=2?branchName=master)
Jan Škoruba's avatar
Jan Škoruba committed
11
[![Join the chat at https://gitter.im/skoruba/IdentityServer4.Admin](https://badges.gitter.im/skoruba/IdentityServer4.Admin.svg)](https://gitter.im/skoruba/IdentityServer4.Admin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
12

13
This is currently in **beta version**
14

Jan Škoruba's avatar
Jan Škoruba committed
15
The application is written in the **Asp.Net Core MVC - using .NET Core 2.2**
Jan Škoruba's avatar
Jan Škoruba committed
16

Jan Škoruba's avatar
Jan Škoruba committed
17
**NOTE:** Works only with **IdentityServer4 version 2.3.0 and higher** 🚀
18

Jan Škoruba's avatar
Jan Škoruba committed
19
## Requirements
20

Jan Škoruba's avatar
Jan Škoruba committed
21
- [Install](https://www.microsoft.com/net/download/windows#/current) the latest .NET Core 2.x SDK (using older versions may lead to 502.5 errors when hosted on IIS or application exiting immediately after starting when self-hosted)
22

23
24
25
26
27
## Installation via dotnet new template

- Install the dotnet new template:

```sh
28
dotnet new -i Skoruba.IdentityServer4.Admin.Templates::1.0.0-beta6
29
30
```

janskoruba's avatar
janskoruba committed
31
- Create new project:
32
33

```sh
34
dotnet new skoruba.is4admin --name MyProject --title MyProject --adminrole MyRole --adminclientid MyClientId --adminclientsecret MyClientSecret
35
36
```

janskoruba's avatar
janskoruba committed
37
38
39
40
41
42
Project template options:

```
--name: [string value] for project name
--title: [string value] for title and footer of the administration in UI
--adminrole: [string value] for name of admin role, that is used to authorize the administration
43
44
--adminclientid: [string value] for client name, that is used in the IdentityServer4 configuration for admin client
--adminclientsecret: [string value] for client secret, that is used in the IdentityServer4 configuration for admin client
janskoruba's avatar
janskoruba committed
45
46
```

47
## How to configure the Administration - IdentityServer4 and Asp.Net Core Identity
janskoruba's avatar
janskoruba committed
48

49
- [Follow these steps for setup project to use existing IdentityServer4 and Asp.Net Core Identity](docs/Configure-Administration.md)
janskoruba's avatar
janskoruba committed
50

51
52
### Template uses following list of nuget packages

janskoruba's avatar
janskoruba committed
53
- [Available nuget packages](https://www.nuget.org/profiles/skoruba)
54

Jan Škoruba's avatar
Jan Škoruba committed
55
56
57
58
59
60
### Running in Visual Studio

- Set Startup projects:
  - Skoruba.IdentityServer4.Admin
  - Skoruba.IdentityServer4.STS.Identity

Jan Škoruba's avatar
Jan Škoruba committed
61
62
63
64
65
## Configuration of Administration for Deployment

- [Configuration of Admin for deploy on Azure](docs/Configure-Azure-Deploy.md)
- [Configuration of Admin on Ubuntu with PostgreSQL database](docs/Configure-Ubuntu-PostgreSQL-Tutorial.md)

janskoruba's avatar
janskoruba committed
66
67
68
69
## Administration UI preview

- This administration uses bootstrap 4

70
71
- Admin UI

janskoruba's avatar
janskoruba committed
72
![Admin-preview](docs/Images/App/Skoruba-Home-Preview.PNG)
janskoruba's avatar
janskoruba committed
73

74
75
76
77
- Security token service (STS)

![Admin-preview](docs/Images/App/Skoruba-STS-Home-Preview.PNG)

janskoruba's avatar
janskoruba committed
78
- Forms:
janskoruba's avatar
janskoruba committed
79

janskoruba's avatar
janskoruba committed
80
![Admin-preview-form](docs/Images/App/Skoruba-Forms-Preview.PNG)
janskoruba's avatar
janskoruba committed
81

82
## Cloning
83

84
85
86
```sh
git clone https://github.com/skoruba/IdentityServer4.Admin
```
87

88
## Installation of the Client Libraries
89

90
91
92
```sh
cd src/Skoruba.IdentityServer4.Admin
npm install
Jan Škoruba's avatar
Jan Škoruba committed
93
94
95

cd src/Skoruba.IdentityServer4.STS.Identity
npm install
96
```
97

98
## Bundling and Minification
99

100
101
102
103
104
105
106
107
108
The following Gulp commands are available:

- `gulp fonts` - copy fonts to the `dist` folder
- `gulp styles` - minify CSS, compile SASS to CSS
- `gulp scripts` - bundle and minify JS
- `gulp clean` - remove the `dist` folder
- `gulp build` - run the `styles` and `scripts` tasks

## EF Core & Data Access
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
- The solution uses these `DbContexts`:

  - `AdminIdentityDbContext`: for Asp.Net Core Identity
  - `AdminLogDbContext`: for logging
  - `IdentityServerConfigurationDbContext`: for IdentityServer configuration store
  - `IdentityServerPersistedGrantDbContext`: for IdentityServer operational store

- Run entity framework migrations:

### Visual Studio command line (Nuget package manager):

#### Migrations for Asp.Net Core Identity DbContext:

```powershell
124
Add-Migration AspNetIdentityDbInit -context AdminIdentityDbContext -output Data/Migrations/Identity
125
126
127
128
129
130
Update-Database -context AdminIdentityDbContext
```

#### Migrations for Logging DbContext:

```powershell
131
Add-Migration LoggingDbInit -context AdminLogDbContext -output Data/Migrations/Logging
132
133
134
135
136
137
Update-Database -context AdminLogDbContext
```

#### Migrations for IdentityServer configuration DbContext:

```powershell
138
Add-Migration IdentityServerConfigurationDbInit -context IdentityServerConfigurationDbContext -output Data/Migrations/IdentityServerConfiguration
139
140
141
142
143
144
Update-Database -context IdentityServerConfigurationDbContext
```

#### Migrations for IdentityServer persisted grants DbContext:

```powershell
145
Add-Migration IdentityServerPersistedGrantsDbInit -context IdentityServerPersistedGrantDbContext -output Data/Migrations/IdentityServerGrants
146
147
148
149
150
151
152
153
Update-Database -context IdentityServerPersistedGrantDbContext
```

### Or via `dotnet CLI`:

#### Migrations for Asp.Net Core Identity DbContext:

```powershell
154
dotnet ef migrations add AspNetIdentityDbInit -c AdminIdentityDbContext -o Data/Migrations/Identity
155
156
157
158
159
160
dotnet ef database update -c AdminIdentityDbContext
```

#### Migrations for Logging DbContext:

```powershell
161
dotnet ef migrations add LoggingDbInit -c AdminLogDbContext -o Data/Migrations/Logging
162
163
164
165
dotnet ef database update -c AdminLogDbContext
```

#### Migrations for IdentityServer configuration DbContext:
166

167
```powershell
168
dotnet ef migrations add IdentityServerConfigurationDbInit -c IdentityServerConfigurationDbContext -o Data/Migrations/IdentityServerConfiguration
169
dotnet ef database update -c IdentityServerConfigurationDbContext
170
171
```

172
#### Migrations for IdentityServer persisted grants DbContext:
173
174

```powershell
175
dotnet ef migrations add IdentityServerPersistedGrantsDbInit -c IdentityServerPersistedGrantDbContext -o Data/Migrations/IdentityServerGrants
176
dotnet ef database update -c IdentityServerPersistedGrantDbContext
177
178
```

179
Migrations are not a part of the repository - they are ignored in `.gitignore`.
180

Jan Škoruba's avatar
Jan Škoruba committed
181
### We suggest to use seed data:
182

183
184
185
- In `Program.cs` -> `Main`, uncomment `DbMigrationHelpers.EnsureSeedData(host)` or use dotnet CLI `dotnet run /seed`
- The `Clients` and `Resources` files in `Configuration/IdentityServer` are the initial data, based on a sample from IdentityServer4
- The `Users` file in `Configuration/Identity` contains the default admin username and password for the first login
186

187
### Using other database engines - PostgreSQL, SQLite, MySQL etc.
188
189
190

- [Follow these steps for setup other database engines](docs/EFMigration.md)

191
## Authentication and Authorization
192

193
194
195
- Change the specific URLs and names for the IdentityServer and Authentication settings in `Constants/AuthenticationConsts` or `appsettings.json`
- `Constants/AuthorizationConsts.cs` contains configuration of constants connected with authorization - definition of the default name of admin policy
- In the controllers is used the policy which name is stored in - `AuthorizationConsts.AdministrationPolicy`. In the policy - `AuthorizationConsts.AdministrationPolicy` is defined required role stored in - `AuthorizationConsts.AdministrationRole`.
196
- With the default configuration, it is necessary to configure and run instance of IdentityServer4. It is possible to use initial migration for creating the client as it mentioned above
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
### Login Configuration

- In `Skoruba.IdentityServer4.STS.Identity` - in `appsettings.json` is possible to specify which column will be used for login (`Username` or `Email`):

```
  "LoginConfiguration": {
    "ResolutionPolicy": "Username"
  }
```

or using `Email`:

```
  "LoginConfiguration": {
    "ResolutionPolicy": "Email"
  }
```

### Register Configuration

- In `Skoruba.IdentityServer4.STS.Identity` - in `appsettings.json` is possible to disable user registration (`default: true`):

```
 "RegisterConfiguration": {
    "Enabled": false
  }
```

226
## Localizations - labels, messages
227
228

- All labels and messages are stored in the resources `.resx` - locatated in `/Resources`
229

Jan Škoruba's avatar
Jan Škoruba committed
230
231
232
  - Client label descriptions from - http://docs.identityserver.io/en/latest/reference/client.html
  - Api Resource label descriptions from - http://docs.identityserver.io/en/latest/reference/api_resource.html
  - Identity Resource label descriptions from - http://docs.identityserver.io/en/latest/reference/identity_resource.html
233

Jan Škoruba's avatar
Jan Škoruba committed
234
235
## Tests

236
- The solution contains unit and integration tests.
Jan Škoruba's avatar
Jan Škoruba committed
237
- **Stage environment is used for integration tests**:
238

Jan Škoruba's avatar
Jan Škoruba committed
239
240
241
  - `DbContext` contains setup for InMemory database
  - `Authentication` is setup for `CookieAuthentication` - with fake login url only for testing purpose
  - `AuthenticatedTestRequestMiddleware` - middleware for testing of authentication.
242

Jan Škoruba's avatar
Jan Škoruba committed
243
- If you want to use `Stage environment` for deploying - it is necessary to change these settings in `StartupHelpers.cs`.
244

245
## Overview
246

Jan Škoruba's avatar
Jan Škoruba committed
247
### Solution structure:
248

Jan Škoruba's avatar
Jan Škoruba committed
249
- STS:
250

251
  - `Skoruba.IdentityServer4.STS.Identity` - project that contains the instance of IdentityServer4 and combine these samples - [Quickstart UI for the IdentityServer4 with Asp.Net Core Identity and EF Core storage](https://github.com/IdentityServer/IdentityServer4.Samples/tree/master/Quickstarts/Combined_AspId_and_EFStorage) and [damienbod - IdentityServer4 and Identity template](https://github.com/damienbod/IdentityServer4AspNetCoreIdentityTemplate)
Jan Škoruba's avatar
Jan Škoruba committed
252
253

- Admin UI:
254
255
256

  - `Skoruba.IdentityServer4.Admin` - ASP.NET Core MVC application that contains Admin UI

257
258
259
260
261
262
263
264
265
  - `Skoruba.IdentityServer4.Admin.BusinessLogic` - project that contains Dtos, Repositories, Services and Mappers for the IdentityServer4

  - `Skoruba.IdentityServer4.Admin.BusinessLogic.Identity` - project that contains Dtos, Repositories, Services and Mappers for the Asp.Net Core Identity

  - `Skoruba.IdentityServer4.Admin.BusinessLogic.Shared` - project that contains shared Dtos and ExceptionHandling for the Business Logic layer of the IdentityServer4 and Asp.Net Core Identity

  - `Skoruba.IdentityServer4.Admin.EntityFramework` - EF Core data layer that contains Entities for the IdentityServer4

  - `Skoruba.IdentityServer4.Admin.EntityFramework.Identity` - EF Core data layer that contains Entities for the Asp.Net Core Identity
266

267
  - `Skoruba.IdentityServer4.Admin.EntityFramework.DbContexts` - project that contains DbContexts for the IdentityServer4, Logging and Asp.Net Core Identity
268

Jan Škoruba's avatar
Jan Škoruba committed
269
270
- Tests:

271
272
273
  - `Skoruba.IdentityServer4.Admin.IntegrationTests` - xUnit project that contains the integration tests for AdminUI

  - `Skoruba.IdentityServer4.Admin.UnitTests` - xUnit project that contains the unit tests for AdminUI
274

275
  - `Skoruba.IdentityServer4.STS.IntegrationTests` - xUnit project that contains the integration tests for STS
276

Jan Škoruba's avatar
Jan Škoruba committed
277
### The admininistration contains the following sections:
278

279
![Skoruba.IdentityServer4.Admin App](docs/Images/Skoruba.IdentityServer4.Admin-Solution.png)
skoruba's avatar
skoruba committed
280

281
## IdentityServer4
282

283
**Clients**
skoruba's avatar
skoruba committed
284

285
It is possible to define the configuration according the client type - by default the client types are used:
286

287
288
- Empty
- Web Application - Server side - Hybrid flow
289
- Single Page Application - Javascript - Authorization Code Flow with PKCE
290
291
- Native Application - Mobile/Desktop - Hybrid flow
- Machine/Robot - Resource Owner Password and Client Credentials flow
Jan Škoruba's avatar
Jan Škoruba committed
292
- TV and Limited-Input Device Application - Device flow
293

294
295
- Actions: Add, Update, Clone, Remove
- Entities:
296
297
298
299
300
301
302
303
  - Client Cors Origins
  - Client Grant Types
  - Client IdP Restrictions
  - Client Post Logout Redirect Uris
  - Client Properties
  - Client Redirect Uris
  - Client Scopes
  - Client Secrets
304

Tomáš Hübelbauer's avatar
Tomáš Hübelbauer committed
305
**API Resources**
306
307

- Actions: Add, Update, Remove
308
309
310
311
312
- Entities:
  - Api Claims
  - Api Scopes
  - Api Scope Claims
  - Api Secrets
Jan Škoruba's avatar
Jan Škoruba committed
313
  - Api Properties
314

Tomáš Hübelbauer's avatar
Tomáš Hübelbauer committed
315
**Identity Resources**
316

317
318
- Actions: Add, Update, Remove
- Entities:
319
  - Identity Claims
Jan Škoruba's avatar
Jan Škoruba committed
320
  - Identity Properties
321

322
## Asp.Net Core Identity
323

324
**Users**
325

326
327
- Actions: Add, Update, Delete
- Entities:
328
329
330
  - User Roles
  - User Logins
  - User Claims
331

332
**Roles**
333

334
335
- Actions: Add, Update, Delete
- Entities:
336
  - Role Claims
337
338
339
340
341
342

## Application Diagram

![Skoruba.IdentityServer4.Admin Diagram](docs/Images/Skoruba.IdentityServer4.Admin-App-Diagram.png)

## Plan & Vision
343

janskoruba's avatar
janskoruba committed
344
345
346
### 1.0.0:

- [x] Create the Business Logic & EF layers - available as a nuget package
Jan Škoruba's avatar
Jan Škoruba committed
347
- [x] Create a project template using dotnet CLI - `dotnet new template`
janskoruba's avatar
janskoruba committed
348
  - [x] First template: The administration of the IdentityServer4 and Asp.Net Core Identity
349
- [x] Add logging into
Jan Škoruba's avatar
Jan Škoruba committed
350
  - [x] Database
Jan Škoruba's avatar
Jan Škoruba committed
351
  - [x] File
janskoruba's avatar
janskoruba committed
352
353
354
- [x] Add localization for other languages
  - [x] English
  - [x] Chinese
355
  - [x] Russian
Jan Škoruba's avatar
Jan Škoruba committed
356
  - [x] Persian
357
  - [x] Swedish
Jan Škoruba's avatar
Jan Škoruba committed
358
359
- [x] Manage profile
- [x] Password reset
360
- [x] Link account to an external provider (example with Github)
Jan Škoruba's avatar
Jan Škoruba committed
361
- [x] Two-Factor Authentication (2FA)
Jan Škoruba's avatar
Jan Škoruba committed
362
- [x] User registration
363
- [x] Email service
364

Jan Škoruba's avatar
Jan Škoruba committed
365
366
### 1.1.0:

Jan Škoruba's avatar
Jan Škoruba committed
367
- [ ] Docker support ([#121](https://github.com/skoruba/IdentityServer4.Admin/issues/121))
368
- [ ] Add audit logs to track changes ([#61](https://github.com/skoruba/IdentityServer4.Admin/issues/61))
Jan Škoruba's avatar
Jan Škoruba committed
369
370
- [ ] Create a project template using dotnet CLI - `dotnet new template`
  - [ ] Second template: The administration of the IdentityServer4 (without Asp.Net Core Identity) ([#79](https://github.com/skoruba/IdentityServer4.Admin/issues/79))
janskoruba's avatar
janskoruba committed
371

Jan Škoruba's avatar
Jan Škoruba committed
372

Jan Škoruba's avatar
Jan Škoruba committed
373
### 2.0.0:
374

Jan Škoruba's avatar
Jan Škoruba committed
375
- [ ] Add API ([#105](https://github.com/skoruba/IdentityServer4.Admin/issues/105))
Jan Škoruba's avatar
Jan Škoruba committed
376
377
378
379
  - [ ] IdentityServer4
  - [ ] Asp.Net Core Identity
  - [ ] Add swagger support

janskoruba's avatar
janskoruba committed
380
381
### Future:

Jan Škoruba's avatar
Jan Škoruba committed
382
383
384
385
- Add UI tests ([#97](https://github.com/skoruba/IdentityServer4.Admin/issues/97), [#116](https://github.com/skoruba/IdentityServer4.Admin/issues/116))
- Add more unit and integration tests :blush:
- Extend administration for another protocols
- Create separate UI using `Razor Class Library` ([#28](https://github.com/skoruba/IdentityServer4.Admin/issues/28), [#133](https://github.com/skoruba/IdentityServer4.Admin/issues/133))
386

387
## Licence
388

389
This repository is licensed under the terms of the [**MIT license**](LICENSE.md).
390

391
**NOTE**: This repository uses the source code from https://github.com/IdentityServer/IdentityServer4.Quickstart.UI which is under the terms of the
392
393
[**Apache License 2.0**](https://github.com/IdentityServer/IdentityServer4.Quickstart.UI/blob/master/LICENSE).

394
## Acknowledgements
395

396
This web application is based on these projects:
397

398
- ASP.NET Core
399
- IdentityServer4.EntityFramework
400
- ASP.NET Core Identity
401
402
403
404
405
406
- XUnit
- Fluent Assertions
- Bogus
- AutoMapper
- Serilog

407
Thanks to [Tomáš Hübelbauer](https://github.com/TomasHubelbauer) for the initial code review.
408

409
Thanks to [Dominick Baier](https://github.com/leastprivilege) and [Brock Allen](https://github.com/brockallen) - the creators of IdentityServer4.
410

janskoruba's avatar
janskoruba committed
411
412
413
414
415
## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

<!-- prettier-ignore-start -->
Jan Škoruba's avatar
Jan Škoruba committed
416
| [<img src="https://avatars3.githubusercontent.com/u/35664089?s=460&v=3" width="100px;"/><br /><sub> Jan Škoruba</sub>](https://github.com/skoruba) <br /> 💻 💬 📖 💡 🤔 | [<img src="https://avatars0.githubusercontent.com/u/6831144?s=460&v=3" width="100px;"/><br /><sub> Tomáš Hübelbauer</sub>](https://github.com/TomasHubelbauer) <br /> 💻 👀 📖  🤔 | [<img src="https://avatars0.githubusercontent.com/u/1004852?s=460&v=3" width="100px;"/><br /><sub>Michał Drzał </sub>](https://github.com/xmichaelx) <br />💻 👀 📖 💡 🤔 | [<img src="https://avatars0.githubusercontent.com/u/2261603?s=460&v=3" width="100px;"/><br /><sub>cerginio </sub>](https://github.com/cerginio) <br /> 💻 🐛 💡 🤔 | [<img src="https://avatars3.githubusercontent.com/u/13407080?s=460&v=3" width="100px;"/><br /><sub>Sven Dummis </sub>](https://github.com/svendu) <br /> 📖| [<img src="https://avatars1.githubusercontent.com/u/1687087?s=460&v=3" width="100px;"/><br /><sub>Seaear</sub>](https://github.com/Seaear) <br />💻 🌍|
janskoruba's avatar
janskoruba committed
417
| :---: | :---: | :---: | :---: | :---: | :---: |
Jan Škoruba's avatar
Jan Škoruba committed
418
|[<img src="https://avatars1.githubusercontent.com/u/1150473?s=460&v=3" width="118px;"/><br /><sub>Rune Antonsen </sub>](https://github.com/ruant) <br />🐛|[<img src="https://avatars1.githubusercontent.com/u/5537607?s=460&v=3" width="118px;"/><br /><sub>Sindre Njøsen </sub>](https://github.com/Sindrenj) <br />💻|[<img src="https://avatars1.githubusercontent.com/u/40323674?s=460&v=3" width="118px;"/><br /><sub>Alevtina Brown </sub>](https://github.com/alev7ina) <br />🌍|[<img src="https://avatars3.githubusercontent.com/u/29726153?s=460&v=3" width="118px;"/><br /><sub>Brice </sub>](https://github.com/Brice-xCIT) <br />💻|[<img src="https://avatars0.githubusercontent.com/u/17114154?s=460&v=3" width="118px;"/><br /><sub>TheEvilPenguin </sub>](https://github.com/TheEvilPenguin) <br />💻|[<img src="https://avatars3.githubusercontent.com/u/15545395?s=460&v=3" width="118px;"/><br /><sub>Saeed Rahmani </sub>](https://github.com/saeedrahmo) <br />🌍|
419
|[<img src="https://avatars0.githubusercontent.com/u/15867612?s=460&v=3" width="118px;"/><br /><sub>Andy Yu </sub>](https://github.com/Zyxious) <br />🌍|
janskoruba's avatar
janskoruba committed
420
421
422
423
424
<!-- prettier-ignore-end -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
Contributions of any kind are welcome!

425
## Contact and Suggestion
426

427
I am happy to share my attempt of the implementation of the administration for IdentityServer4 and ASP.NET Core Identity.
428

429
Any feedback is welcome - feel free to create an issue or send me an email - [jan@skoruba.com](mailto:jan@skoruba.com). Thank you :blush: