Spring Boot Java AuthN Service
#
IntroductionThis 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.
#
Set up & InstallationThis 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
#
JavaTo run this example you will need Java 11 installed.
For example, on Ubuntu you could install OpenJDK:
#
Build DIDKitThe 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, libdidkit.dylib
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) libdidkit.so
to /usr/lib
or
/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
linking:
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
as 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:
#
Database Setup (MySQL)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.
#
(a) Docker MySQL DatabaseOne easy way to run an instance is by using docker:
#
(b) System MySQL DatabaseHere are some commands to use a local instance of the MySQL-compatible MariaDB on Ubuntu:
#
(Optional) Test MySQLTo ensure that mysql is working, try the following command:
#
Database Connection ConfigurationIf you need to modify the database credentials you will need to update the
relevant fields in src/main/resources/application.properties
.
#
RedisThis project makes use of Redis to store single use tokens and authentication information for the QR code flows.
#
(a) Docker RedisOne easy way, just like MySQL, to have it running locally is to use docker:
#
(b) System RedisHere are some commands to install and run Redis on Ubuntu:
#
(Optional) Test RedisTo ensure that mysql is working, try the following commands:
#
Building and RunningWe 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.
#
Java Example App Walkthrough- 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.