This project demonstrates use of verifiable credentials and presentations to enable user authentication for an application. See the DIDKit repository's examples folder for code snippets.
This project has the following key dependencies to consider:
- Java 11
- DIDKit compiled locally & linked from the classpath
- The DIDKit Java artifact (
didkit.jar), usually built by DIDKit installation.
- A MySQL database
To run this example you will need Java 11 installed.
For example, on Ubuntu you could install OpenJDK:
The web application makes use of DIDKit to handle credentials and presentations,
please refer to the project's documentation to build the library for your platform,
libdidkit.so on UNIX-like systems,
didkit.dll on Windows,
on MacOS, etc.
Then you will have to add it to the classpath of your platform. On UNIX systems,
for example, you can copy (or symlink)
/usr/local/lib. In the instructions below, we will list commands to create a
symlink to the local build folder.
You will then require the Java artifact (
didkit.jar). This example project
already has a symlink in the build directory. All you have to do is run the
following commands in the root folder to build everything and ensure proper
If you are trying to use DIDKit with an external Java project, you will have to
point your build tool (Gradle, Maven, etc) to the
didkit.jar file. Also
ensure that the static library (e.g.,
libdidkit.so is in the
java.library.path or specified using the proper environment variables, such
LD_LIBRARY_PATH on UNIX-like. Please refer to the full documentation for
those tools. Here is an excerpt of how we have listed it on this project's
pom.xml for Maven:
This project uses a MySQL database to store the user entity. We will use the
root user for simplicity because this is only an example. In your actual
deployments, it is very important that you configure the correct accounts,
policies, and permissions for your SQL installations.
One easy way to run an instance is by using docker:
Here are some commands to use a local instance of the MySQL-compatible MariaDB on Ubuntu:
To ensure that mysql is working, try the following command:
If you need to modify the database credentials you will need to update the
relevant fields in
This project makes use of Redis to store single use tokens and authentication information for the QR code flows.
One easy way, just like MySQL, to have it running locally is to use docker:
Here are some commands to install and run Redis on Ubuntu:
To ensure that mysql is working, try the following commands:
We are now ready to build and run the installation. To download the required Java dependencies, build the project, and then run it, you can execute the following commands from the root project directory:
You can then load
http://localhost:8081 to see the web application.
To verify that DIDKit has been setup correctly, you can then run:
And you should expect to see a version string in the response.
- Visit http://localhost:8081 with your web browser.
- Create a user by clicking "Sign Up" on the navigation bar.
- Log in with your newly created user by clicking "Sign In" on the navigation bar.
- Issue yourself a credential to use for login instead of username and password. You can receive credentials in the example CHAPI wallet or using the QR code workflow and Credible mobile wallet.