Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/dotnet-build-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ jobs:
- name: Install dependencies
run: dotnet restore src/WebEid.AspNetCore.Example.sln --source "https://gitlab.com/api/v4/projects/35362906/packages/nuget/index.json" --source "https://api.nuget.org/v3/index.json"

- name: Download RIA repository public key
run: wget https://github.com/web-eid/web-eid-asp-dotnet-example/raw/main/src/ria_public_key.gpg

- name: Copy RIA repository key to keyrings
run: sudo cp ria_public_key.gpg /usr/share/keyrings/ria-repository.gpg
run: sudo cp src/ria_public_key.gpg /usr/share/keyrings/ria-repository.gpg

- name: Add RIA repository to APT
run: |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Additional information regarding the Web eID project can be found on the officia

Complete the steps below to add support for secure authentication with eID cards to your ASP.NET Core web application backend. Instructions for the frontend are available [here](https://github.com/web-eid/web-eid.js).

See full example [here](https://github.com/web-eid/web-eid-asp-dotnet-example).
See full example [here](https://github.com/web-eid/web-eid-authtoken-validation-dotnet/tree/main/example).

## 1. Add the library to your project

Expand Down Expand Up @@ -185,7 +185,7 @@ return new AuthTokenValidatorBuilder()

A REST endpoint that issues challenge nonces is required for authentication. The endpoint must support `GET` requests.

In the following example, we are using the [ASP.NET Web APIs RESTful Web Services framework](https://dotnet.microsoft.com/apps/aspnet/apis) to implement the endpoint, see also full implementation [here](https://github.com/web-eid/web-eid-asp-dotnet-example/blob/main/src/WebEid.AspNetCore.Example/Controllers/Api/AuthController.cs).
In the following example, we are using the [ASP.NET Web APIs RESTful Web Services framework](https://dotnet.microsoft.com/apps/aspnet/apis) to implement the endpoint, see also full implementation [here](https://github.com/web-eid/web-eid-authtoken-validation-dotnet/blob/main/example/src/WebEid.AspNetCore.Example/Controllers/Api/AuthController.cs).

```cs
using Microsoft.AspNetCore.Mvc;
Expand Down
54 changes: 44 additions & 10 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ The ASP.NET web application makes use of the following technologies:

Complete the steps below to run the example application in order to test authentication and digital signing with Web eID.

```sh
cd example/src
docker compose up
```
This will start a prebuilt docker image with self-signed certificate on https://localhost:8443

## Setup for Development

### 1. Add the Web eID authentication token validation library to your project

#### When using Visual Studio
Expand Down Expand Up @@ -69,7 +77,7 @@ Note that the URL **must not end with a slash** `/` and the URL must be the same

### 3. Configure the trusted certificate authority certificates

The algorithm, which performs the validation of the Web eID authentication token, needs to know which intermediate certificate authorities (CA) are trusted to issue the eID authentication certificates. CA certificates are loaded from `.cer` files in the profile-specific subdirectory of the [`Certificates` resource directory](https://github.com/web-eid/web-eid-asp-dotnet-example/tree/main/src/WebEid.AspNetCore.Example/Certificates). By default, Estonian eID test CA certificates are included in the `Development` profile and production CA certificates in the `Production` profile.
The algorithm, which performs the validation of the Web eID authentication token, needs to know which intermediate certificate authorities (CA) are trusted to issue the eID authentication certificates. CA certificates are loaded from `.cer` files in the profile-specific subdirectory of the [`Certificates` resource directory](https://github.com/web-eid/web-eid-authtoken-validation-dotnet/tree/main/example/src/WebEid.AspNetCore.Example/Certificates). By default, Estonian eID test CA certificates are included in the `Development` profile and production CA certificates in the `Production` profile.

In case you need to provide your own CA certificates, add the `.cer` files to the `src/WebEid.AspNetCore.Example/Certificates/{Dev,Prod}` profile-specific directory.

Expand All @@ -91,7 +99,7 @@ Set up the `libdigidocpp` library as follows:

1. Add RIA repository to install the official _libdigidocpp-csharp_ package:
```sh
wget https://github.com/web-eid/web-eid-asp-dotnet-example/raw/main/src/ria_public_key.gpg
wget https://raw.githubusercontent.com/web-eid/web-eid-authtoken-validation-dotnet/refs/heads/main/example/src/ria_public_key.gpg
cp ria_public_key.gpg /usr/share/keyrings/ria-repository.gpg
echo "deb [signed-by=/usr/share/keyrings/ria-repository.gpg] https://installer.id.ee/media/ubuntu/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/ria-repository.list
```
Expand Down Expand Up @@ -175,9 +183,10 @@ See the [Web eID Java example application documentation](https://github.com/web-

You are running in the `Development` profile, but you have not created an empty file named `EE_T.xml` for TSL cache. Creating the file is mandatory and is described in more detail in the [_Using test TSL lists_](https://github.com/open-eid/libdigidocpp/wiki/Using-test-TSL-lists#preconditions) section of the `libdigidocpp` wiki.

## Building and running with Docker on Ubuntu Linux
## Building and running example web application with Docker on Ubuntu Linux

This section covers the steps required to build the application on an Ubuntu Linux environment and run it using Docker.
In case you want to use web-eid-authtoken-validation-dotnet in your web app,
then please follow these steps in this chapter to build a Docker image in Ubuntu Linux environment.

### Prerequisites

Expand All @@ -186,13 +195,24 @@ Before you begin, ensure you have the following installed on your system:
- .NET SDK 8.0
- libdigidocpp-csharp

You can install them using the following command:
You can install them using the following commands:

Add RIA repository to install the official _libdigidocpp-csharp_ package:
```sh
cp src/ria_public_key.gpg /usr/share/keyrings/ria-repository.gpg
echo "deb [signed-by=/usr/share/keyrings/ria-repository.gpg] https://installer.id.ee/media/ubuntu/ $(lsb_release -cs) main" | sudo -s tee /etc/apt/sources.list.d/ria-repository.list
sudo apt update
```
then install the packages
```sh
sudo apt install dotnet-sdk-8.0 libdigidocpp-csharp
```
Add a NuGet package source for web-eid-authtoken-validation-dotnet library:

Note: Before installing `libdigidocpp-csharp` you have to have added the RIA repository as a package source. See [For Ubuntu Linux section](#for-ubuntu-linux) for information.
```sh
dotnet nuget add source https://gitlab.com/api/v4/projects/35362906/packages/nuget/index.json --name "Web eID GitLab"
```
If last command ends with error message, then it is already added and you can move to next step: `error: The name specified has already been added to the list of available package sources. Provide a unique name.`

### Building the application

Expand All @@ -201,7 +221,7 @@ To build the application, follow these steps:
1. Navigate to the `src` directory:

```sh
cd src
cd example/src
```

2. Copy the necessary DigiDoc C# library files into your project:
Expand All @@ -216,10 +236,9 @@ To build the application, follow these steps:
dotnet publish --configuration Release WebEid.AspNetCore.Example.sln
```

4. Update the `OriginUrl` in the `appsettings.json` to match your production environment:

4. Update the `OriginUrl` in the `appsettings.json` to match your production environment. Please replace https://localhost:8443 with your actual domain name where you intend to run the application:
```sh
sed -i 's#"OriginUrl": "https://localhost:44391"#"OriginUrl": "https://example.com"#' WebEid.AspNetCore.Example/bin/Release/net6.0/publish/appsettings.json
sed -i 's#"OriginUrl": "https://localhost:44391"#"OriginUrl": "https://localhost:8443"#' WebEid.AspNetCore.Example/bin/Release/net8.0/publish/appsettings.json
```

### Building the Docker image
Expand All @@ -232,6 +251,21 @@ docker build -t web-eid-asp-dotnet-example .

This command builds a Docker image named `web-eid-asp-dotnet-example` using the `Dockerfile` in the current directory.

In order to test the created image, use the example/src/docker-compose.yml.
You will need to replace the official image with the one you just built.
Comment out the official image and add local:
```
...
#image: registry.gitlab.com/web-eid/service/web-eid-authentication-token-validation-dotnet/web-eid-asp-dotnet-example
image: web-eid-asp-dotnet-example:latest
...
```

Then just run:
```sh
docker compose up
```

## Running the Docker container with HTTPS support

To enable HTTPS support for the .NET application, you have two primary options:
Expand Down
6 changes: 5 additions & 1 deletion example/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ RUN echo "deb [signed-by=/usr/share/keyrings/ria-repository.gpg] https://install

COPY ./WebEid.AspNetCore.Example/bin/Release/net8.0/publish/ .

COPY ./WebEid.AspNetCore.Example/Certificates/Dev/self-signed-server-certificate.pfx /https/self-signed-server-certificate.pfx

ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS="https://+:443"
ENV ASPNETCORE_Kestrel__Certificates__Default__Path=/https/self-signed-server-certificate.pfx

EXPOSE 80
EXPOSE 443

ENTRYPOINT ["dotnet", "WebEid.AspNetCore.Example.dll"]
Binary file not shown.
7 changes: 5 additions & 2 deletions example/src/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
version: '2'
services:
web-eid-asp-dotnet-example:
image: registry.gitlab.com/web-eid/service/web-eid-authentication-token-validation-dotnet/web-eid-asp-dotnet-example
restart: always
environment:
- ASPNETCORE_Kestrel__Certificates__Default__Password=your-cert-password
- OriginUrl=https://localhost:8443
ports:
- '127.0.0.1:8480:80'
- '127.0.0.1:8443:443'


Loading