Configure-Ubuntu-PostgreSQL-Tutorial.md 3.04 KB
Newer Older
1
2
# Introduction

3
Tutorial covers configuration of Admin on Ubuntu 19.04 with fresh instance of PostgreSQL database.
4
5
6

# Prerequisites

7
## .NET Core 3.1 SDK
8

9
Instructions from: https://docs.microsoft.com/en-us/dotnet/core/install/linux-package-manager-ubuntu-1904
10
11

```
12
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
13
14
sudo dpkg -i packages-microsoft-prod.deb

15
sudo apt-get update
16
17
sudo apt-get install apt-transport-https
sudo apt-get update
18
sudo apt-get install dotnet-sdk-3.1
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
```

## PostgreSQL

Instructions from: https://linuxize.com/post/how-to-install-postgresql-on-ubuntu-18-04/

```
sudo apt update
sudo apt install postgresql postgresql-contrib
```

Throughout tutorial we will use PostgreSQL running on localhost and default port 5432 with username/password combination postgres/postgres. You can update connection strings with your own or if you want to follow everything exactly then after installing PostgreSQL you will need to change password of `postgres` user:

```
sudo -u postgres psql
ALTER USER postgre WITH PASSWORD 'postgres';
```

## IDE

Console commands will be used throghout the tutorial but for code editing it is recommended to use dedicated IDE. I've got good experience with [Visual Studio Code](https://code.visualstudio.com/) and [Rider](https://www.jetbrains.com/rider/).

# Cloning Admin

```
git clone https://github.com/skoruba/IdentityServer4.Admin
```

# Adjustments for PostgreSQL

By default everything is configured for Microsoft SQL Server, but fortunately it's pretty easy to change.

## Replace connection strings
First change connection strings in `src/Skoruba.IdentityServer4.Admin/appsettings.json` and  `src/Skoruba.IdentityServer4.STS.Identity/appsettings.json` and replace them with following connection string:

```
Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true
```

58
## Swith to PostgreSQL
59

60
61
62
63
64
65
It is possible to change database provider in `appsettings.json` in following projects:
 - Skoruba.IdentityServer4.Admin
 - Skoruba.IdentityServer4.Admin.Api
 - Skoruba.IdentityServer4.STS.Identity
 
Change parameter `ProviderType` in section to:
66
```
67
68
69
"DatabaseProviderConfiguration": {
    "ProviderType": "PostgreSQL"
  }
70
71
```

72
# Final setup 
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
## Run STS and Admin

First run STS in `src/Skoruba.IdentityServer4.STS.Identity` launch:

```
dotnet run
```

Admin also needs to seed the database so seperate terminal in `src/Skoruba.IdentityServer4.Admin` we add additional seed parameter:

```
dotnet run /seed
```

88
After that we should have STS listening on http://localhost:5000 and Admin on http://localhost:9000.  We can go to the latter and we should be redirected to our STS for authentication. You can find the default credentials in `identitydata.json` in project called `Skoruba.IdentityServer4.Admin`.
89
90
91

# Final thoughts

92
There are many more steps required before IS4 and Admin panel are sufficiently hardened to be used in production scenario. Please bear in mind that this tutorial serves only as a quickstart.