Enable Basic authentication

Enable Basic authentication for your Quarkus project and allow users to authenticate with a username and password.

Prerequisites

  • You have installed at least one extension that provides an IdentityProvider based on username and password, such as Elytron JDBC.

Procedure

  1. Enable Basic authentication by setting the value of quarkus.http.auth.basic property to true.

    quarkus.http.auth.basic=true

An easy way to configure the required user credentials for Basic authentication to work is to configure the user name, secret, and roles directly in the application.properties file.

Example of Basic authentication properties
quarkus.http.auth.basic=true
quarkus.security.users.embedded.plain-text=true
quarkus.security.users.embedded.users.alice=alice
quarkus.security.users.embedded.users.bob=bob
quarkus.security.users.embedded.roles.alice=admin
quarkus.security.users.embedded.roles.bob=user

In this configuration the credentials for users alice and bob are configured: alice has a password alice and an admin role, bob has a password bob and a user role.

For more information, see Configuring User Information in the "Security Testing" guide.

Configuring user names, secrets, and roles in the application.properties file is only suitable for testing scenarios. If you are securing an application for production, always use a database to store this information.

To walk through how to configure Basic authentication together with Jakarta Persistence for storing user credentials in a database, see the Secure a Quarkus application with Basic authentication tutorial.