Look just like you, I was scoring the internet for Authentik -Directus integration example, only to find myself in the deep rabbit hole of StackOverflow, error codes and github issues page. It is actually not impossible and I will try to be as direct on this long path.
Installing Directus
Method 1: Docker
Create a new empty folder on your Desktop called directus
. Within this new folder, create the three empty folders database
, uploads
, and extensions
.
Copy and paste the following and save the file as docker-compose.yml
:
Method 2: Directus CLI & PM2
Install Node.js v18, specifically version 18.17 >= 19.11 (less than v20) use NVM to change versions, YARN and PM2 .
For server-side CLI, all functionality can be accessed by running npx directus <command>
in your project folder.
Initialize a New Project
or reconfigure existing project via npx directus init
After configuring through the interface deploy in development mode by starting the Directus server over 0.0.0.0:8055.
Deploying Directus in production via PM2
In production, you may need persistence,scaling and monitoring ability, which cli lack in features. Its recommended to use PM2 , a lighweight and popular application server over PhusionPassenger.
Install PM2 as shown, then Change directory into Directus project folder.
To initiate creation of ecosystem.config.js file use the ecosystem command and edit the files as shown:
Installing Authentik
To download the latest docker-compose.yml
open your terminal and navigate to the directory of your choice. Run the following command:
If this is a fresh authentik installation, you need to generate a password and a secret key. If you don't already have a password generator installed, you can run this command to install pwgen, a popular generator:
# You can also use openssl instead: `openssl rand -base64 36`
sudo apt-get install -y pwgen
By default, authentik listens internally on port 9000 for HTTP and 9443 for HTTPS. To change the exposed ports to 80 and 443, you can set the following variables in .env
:
COMPOSE_PORT_HTTP=80
COMPOSE_PORT_HTTPS=443
Afterwards, run these commands to finish or follow more on offical docs:
Configuring Authentik OpenID
After configuring Authentik server, login into the Admin Settings and create new Application and Provider for Directus as OAuth2/OpenID Provider
Configuring Directus SSO to Authentik
Copy Provider Client ID ,Client Secret and validate Redirect URI matches that of Directus domain.
Directus supports four standard types of SSO mechanisms:
These are well supported within Authentik. Using the default Directus Admin Login into the Dashboard -> Users ->Administrator. Note the URL https://your.domain/admin/users/1113322-aba6-1c9c-1234-123423681234
To add Single Sign On (SSO) to Directus, obtain a client ID and client secret from your authentication provider and add them to your env configuration file along with the required parameters below.
- AUTH_AUTHENTIK_DRIVER="openid"
- AUTH_AUTHENTIK_CLIENT_ID=(from Authentic Provider shown above)
- AUTH_AUTHENTIK_CLIENT_SECRET=
- AUTH_AUTHENTIK_ISSUER_URL= (location of /.well-known/openid-configuration ie https://your.domain/application/o/directus/.well-known/openid-configuration)
- AUTH_AUTHENTIK_IDENTIFIER_KEY=email
- AUTH_AUTHENTIK_ALLOW_PUBLIC_REGISTRATION (true or false)
- AUTH_AUTHENTIK_DEFAULT_ROLE_ID (Role ID from Directus ie;1113322-aba6-1c9c-1234-123423681234)
Common issues
Authentik fails with error "The request fails due to a missing, invalid, or mismatching redirection URI (redirect_uri)." This means to check redirect URL in OpenID Provider within Authentik
Directus fails to login with INVALID_FOREIGN_KEY "https://your.domain/admin/login?reason=INVALID_FOREIGN_KEY". This means the used AUTH_AUTHENTIK_DEFAULT_ROLE_ID is invalid, check the admin URL to validate.
Directus fails to login with INVALID_PROVIDER"https://your.domain/admin/login?reason=INVALID_PROVIDER". Check that the .env has correct AUTH_PROVIDERS that is 'authentik' is included without # sign for line there.
Directus fails to login with INVALID_CREDENTIALS "https://your.domain/admin/login?reason=INVALID_CREDENTIALS". Check that the the Directus user/administators have unique email to your OpenID users. If the email exists SSO user will fail to authenticate (password preceedes SSO)
Conclusion
Successfully logged in to Directus with Authentik. New account appears within Administrators and heaven is happy. Holla to know this helped [email protected]