swp-fu-eid / eid-fu-swp

Docker-based REST API implemented with Django and restframework.
MIT License
2 stars 1 forks source link

EID-Based Single Sign-On Service

Authentication via username and password has a couple of disadvantages. Hence, enterprises and governments attempt to replace the authentication by username and password with an alternative solution such as the use of hardware tokens. In Germany, the government introduced nPa as an official hardware token that can be used for authentication and that fulfills high standards in security and privacy.

In the course of this project, an authentication service is designed and implemented that enables third parties to authenticate their users using eid, i.e. the "neuen Personalausweis" ("new" german id card) or the electronic residency permit, instead of using username and password.

Getting Started

Install Docker

This project uses Docker CE and Docker Compose to run all services. Installing Docker depends on the platform and is hence not included here. Docker Compose has to be installed separately.

Source Code

To obtain the source code, please clone this repository.

git clone https://github.com/nils-wisiol/django-rest-boilerplate

Running

Running this project requires a fully configured .env file. A template for .env can be found in .env.default. Below, all values are documented.

Optional for using the example oidc client:

After populating .env with all appropriate values, the service can be started with

docker-compose up

and be reached at your chosen domain name. Remember to have your domain name point at $BOILERPLATE_IPV4_16PREFIX.0.128 (for the default configuration this is 172.16.0.128). At $BOILERPLATE_DOMAIN/api/admin/, the generic django administration backend is available.

Project Design

This project uses Docker CE and Docker Compose to run all services. All components of the project are within docker containers and docker-compose scripts are provided to start all necessary services.

OIDC Provider

Before third parties can use this service, they have to register as clients. Therefore, see the [[OIDC Provider|Software Architecture#oidc-provider]] section.

After registering the client, this service can be used to authenticate their users according to the OpenID Connect process by calling $BOILERPLATE_DOMAIN/api/openid as authority URL. For further information concerning the OpenID Connect process see the OpenID Connect section in the WIKI. This project also includes an example OIDC client.

OIDC example client

Start example client

Environment variables to be set in .env:

Generate a client id

You have to register your client in your openID provider, during this registration process a provider unique client id will be created. This is the id you can use as value for CLIENT_ID.

Set Urls

The redirect url is the url which will be used if the authorization process was successfull. You have to set a set of possible redirect urls during the registration process mentioned above. Therefore the redirect url used in the variable has to be an element of the former defined set. In our case a valid value could be http://localhost:3000.

The authority url is the url to the open id provider server, that will be used to authenticate. In our case a valid value could be something like https://eid.localhost/api/openid.

For more information about the used javascript library see here. If you are interested in the documentation of the used openid provider see here.

Step-by-Step Guide

Open a console:

git clone git@github.com:swp-fu-eid/eid-fu-swp.git
cd eid-fu-swp
mkdir certs
cd certs
openssl req -newkey rsa:2048 -nodes -keyout www.key -x509 -days 365 -out www.cer
openssl req -newkey rsa:2048 -nodes -keyout MAIN.key -x509 -days 365 -out MAIN.cer
cd ..
cp .env.default .env

Edit .env:

BOILERPLATE_DOMAIN=eid.local

# network
BOILERPLATE_IPV4_16PREFIX=172.16
BOILERPLATE_IPV6_SUBNET=bade:affe:dead:beef:b011::/80
BOILERPLATE_IPV6_ADDRESS=bade:affe:dead:beef:b011:0642:ac10:0080

#certificates
BOILERPLATE_WWW_CERTS=./certs

# API-related
BOILERPLATE_API_SECRETKEY=1234
BOILERPLATE_DB_PASSWORD=1234

Open a console:

echo -e "\n172.16.0.128\teid.local" | sudo tee --append /etc/hosts
docker-compose up --build
docker-compose exec api python manage.py createsuperuser
docker-compose exec api python manage.py creatersakey

Open a browser and go to: https://eid.local/api/admin.

Login as superuser.

Choose "Add Client".

Create a new client with Name=test, Client Type=Public, Response Type=id_token token (Implicit Flow), Redirect URIs=http://localhost:3000, JWT Algorithm=RS256, Require Consent?=true, Reuse Consent?=true, Save.

Copy the <Client ID>.

Logout.

Append to .env:

# Example OIDC-Client
CLIENT_ID=<Client ID>
AUTHORITY_URL=https://eid.local/api/openid
REDIRECT_URL=http://localhost:3000

Stop the `docker-compose up --build' and restart it in order to load the new .env-file.

Open another console:

docker-compose -f docker-compose.example.yml up

Open a browser and go to: http://localhost:3000.

As the eid server in this project is not working you can not execute the whole process. But you have now setup the provider and registered a client which could use the service.

License

All work in this repository is licensed under the MIT license. For details, see the LICENSE file.