Skip to main content

Configuration

Most of AuthGuard internal work is customizable by its configuration. The server expects either JSON or YAML configuration files to be provided named application.json or application.yaml.

If you're building your own distribution, you can include a configuration file in its resources. Alternatively, you can provide an configuration file using the config parameter like this

--config /path/to/config/file.yaml

All configuration must be under the root 'authguard', whether it's JSON or YAML. Below is the break down of the configuration parameters. Note that other plugins also bring with them their own configuration which can also be added here.

Using environment variables

To read any configuration value from environment variables, you can set the property to "env:" followed by the name of the variable. For example, "env:MY_VARIABLE" will read the value of the variable MY_VARIABLE.

Injection#

Since AuthGuard will look for plugins when it starts, you need to tell it which packages it's allowed to search.

injection:
packages: [ "com.nexblocks.authguard" ]

One-Time Admin (OTA)#

A One-Time Admin (OTA) is an account with limited capabilities, it's meant only to create other full admins and generate API keys for them. It should be deleted afterwards.

Note that an OTA will only be created on startup if no other admins exist. In such case, AuthGuard will create the OTA based on the values of the environment variables set in the configuration.

Examples#

oneTimeAdmin:
usernameVariable: "AUTHGUARD_OTA_USERNAME"
passwordVariable: "AUTHGUARD_OTA_PASSWORD"

Server#

PropertyDescription
portThe port to use for HTTP
securePortThe port to use for HTTPS
enableSslEnable HTTPs port
enforeSslDon't allow HTTP traffic
keystorePathThe path to the keystore to use for TLS
keystorePasswordThe password to use to access the keystore
enableClientAuthenticationAccept connections only from trusted clients (only for TLS)
truststorePathThe path to store to use to authenticate clients
truststorePasswordThe password to use to access the trust store

Examples#

  1. Only HTTP
server:
port: 3000
  1. Basic HTTP and HTTPS
server:
port: 3000
securePort: 8443
enableSsl: true
  1. Basic Only HTTPS
server:
securePort: 8443
enableSsl: true
enforceSsl: true
keystorePath: /path/to/keystore
keystorePassword: changeit
  1. HTTPS with Client Authentication
server:
securePort: 8443 # port for HTTPS
enableSsl: true
enforceSsl: true # don't allow HTTP traffic
keystorePath: /path/to/keystore
keystorePassword: changeit
enableClientAuthentication: true
truststorePath: /path/to/truststore
truststorePassword: changeit

Exchange#

To configure auth exchanges, you need to provide a list of allowed providers and allowed exchanges.

PropertyDescription
providersA list of strings of the names of allowed providers
allowedA list of objects containing allowed exchanges (from and to)

Examples#

The example shows an exchange where users would use their identifier (e.g. username) and password to receive a one-time password, and the exchange that OTP for an access token.

exchange:
providers:
- "otp"
- "accessToken"
allowed:
- from: "basic"
to: "otp"
- from: "otp"
to: "accessToken"

Authentication#

This is used to configure an exchange shortcut from basic auth (identifier and password) to another token. It also tells the server what to expects for logout.

Examples#

In the following example the server will generate a passwordless token but, eventually, the user will logout while holding an access token.

authentication:
generateToken: "passwordless"
logoutToken: "accessToken"

Accounts#

PropertyDescription
authguardAdminRoleThe name of the role to use for admins of the server
requireEmailRequire a primary email to be supplied or not (true or false)
requirePhoneNumberRequire a phone number to be supplied or not
verifyEmailVerify an account email after it was created
verifyPhoneNumberVerify an account phone number after it was created
defaultRolesA list of roles to be added to an account if none were specified
defaultDomainThe domain to use when creating the default roles

Passwords#

Currently, only two password hashing algorithms are supported: bcrypt and scrypt. Support for Argon2 is in the works. You can configure the hashing algorithm, as well password conditions.

PropertyDescription
algorithmThe name of the algorithm to use 'bcrypt' or 'scrypt'
scryptConfiguration for scrypt (see below)
bcryptConfiguration for bcrypt (see below)
validForDuration after which a password will expire (e.g. '30d' for 30 days)
conditionsConditions a new password must meet
versionCurrent version number of password configuration (integer)
previousVersionsPrevious password configurations by version (explained below)
minimumVersionThe minimum acceptable version, any version below it is considered expired

SCrypt#

PropertyDescription
CPUMemoryCostParameterdefault 16384
blockSizedefault 8
parallelizationdefault 1
saltSizedefault 16
keySizedefault 50

BCrypt#

PropertyDescription
costdefault 4
saltSizedefault 16

Conditions#

PropertyDescription
includeDigitsMust include at least one digit (true/false)
includeCapsMust include at least one capital letter (true/false)
includeSpecialCharactersMust include at least one special character (true/false)
includeSmallLettersMust include at least one small character (true/false), default true
maxLengthMaximum length, default 30
minLengthMinimum length, default 6

Version and Previous Versions#

Whenever a user's credentials are stored, they get tagged by a version. The version indicates which password configuration was used to create that password. This, when paired with previous versions configuration, allows you to update the hashing configuration without affecting existing passwords. For example, if you are currently using BCrypt and decided to switch to use SCrypt, then you can move your existing BCrypt configuration into a previous versions item, set SCrypt as the new one and change the version number as follows.

passwords:
algorithm: scrypt
scrypt:
blockSize: 16
conditions:
minLength: 6
version: 2 # was previously 1
previousVersions:
- version: 1 # version 1 was moved here
algorithm: bcrypt

JWT#

If you intent to use the JWT plugin, you need to provide some general configuration for it. This is different from token-specific configuration for access tokens and ID tokens.

PropertyDescription
algorithmWhich algorithm to use. Check JWT documentation for a list of algorithms
privateKeyThe private key to use to sign tokens. If you're using symmetric keys then you can this field will be treated as just "key"
publicKeyThe public key to use to verify tokens (only applicable to asymmetric keys)
issuerThe value to use for the issuer
trustedIssuersAn array of trusted issuers to be checked when verifying tokens. Must be ["self"] for now
encryptionIf defined, AuthGuard will encrypt all JWTs before sending them

Examples#

  1. Without Encryption
jwt:
algorithm: "HMAC256"
privateKey: "keys/hmac256.pem"
issuer: "AuthGuard"
allowedAlgorithms: ["HMAC256"]
trustedIssuers: ["self"]
  1. With Encryption
jwt:
algorithm: "HMAC256"
privateKey: "keys/hmac256.pem"
issuer: "AuthGuard"
allowedAlgorithms: ["HMAC256"]
trustedIssuers: ["self"]
encryption:
algorithm: "AES_CBC"
privateKey: "keys/aes128.txt"

Access Tokens#

While general JWT configuration will still apply to access tokens, they have some specific configuration parameters of their own,

PropertyDescription
tokenLifeThe duration for which the token will be valid (e.g. 5m, 2h..etc)
refreshTokenLifeThe same thing, but for the refresh token
useJtiWhether or not to generate and store a JTI
includePermissionAdd permissions to the token
includeRolesAdd roles to the token
includeExternalIdAdd the external ID of the user in the token

Examples#

accessToken:
tokenLife: "5m"
refreshTokenLife: "1h"
useJti: true
includePermissions: true
includeRoles: true
includeExternalId: true

ID Tokens#

Similar to access tokens, ID tokens also need to be configured indepndently.

PropertyDescription
tokenLifeThe duration for which the token will be valid (e.g. 5m, 2h..etc)
refreshTokenLifeThe same thing, but for the refresh token
useJtiWhether or not to generate and store a JTI
includeExternalIdAdd the external ID of the user in the token

Examples#

idToken:
tokenLife: "1d"
useJti: true
includeExternalId: true

Authorization Code#

If you're planning on using an authorization code, then you need to configure that as well.

PropertyDescription
lifeTimeThe duration for which the code will be valid (e.g. 5m, 2h..etc)
randomSizeThe number of random bits to generate
authorizationCode:
lifeTime: "5m"
randomSize: 128

External Communication#

While AuthGuard can send emails and text messages, this configuration only covers which channels are allowed. Refer to the configuration of the particular plugin you want to use for its own configuration.

PropertyDescription
emailWhether to enable email providers or not (true or false)
smsWhether to enable sms providers or not (true or false)

Examples#

external:
email: true
sms: true

One-Time Passwords#

Use the email or sms plugin with an email provider to make AuthGuard send the token itself
PropertyDescription
lifeTimeHow long the password will be valid for
modeThe type of OTPs to generate: NUMERIC, ALPHANUMERIC, ALPHABETIC
lengthNumber of characters
generateTokenWhat type of token should be generated after a successful OTP verification

Examples#

otp:
lifeTime: "2m"
mode: "NUMERIC"
length: 6
generateToken: "accessToken"

Passwordless#

Use the email plugin with an email provider to make AuthGuard send the token itself
PropertyDescription
tokenLifeHow long the password will be valid for
randomSizeHow many random bits to generate
generateTokenWhat type of token should be generated after a successful passwordless token verification

Examples#

passwordless:
tokenLife: "10m"
randomSize: 128
generateToken: "accessToken" # what to generate upon a successful OTP verification

Internal Event Channels#

The Event Message Bus (EMB) is one of the core components of AuthGuard, and it makes it easier to add new functionality to it. Although a lot of channels are internally defined, you can decide which ones to allow.

PropertyDescription
channelsAn array of the names of channels to allow
subscribersAn array of fully-qualified name of subscriber classes to allow to subscribe

Locking down which subscribers are allowed to be automatically subscribed to channels was added to prevent unintentially adding an external plugin with subscribers to read data it is not meant to read.

Examples#

emb:
channels:
- accounts
- auth
- passwordless
subscribers:
- com.nexblocks.authguard.external.email.subscribers.EmailPasswordlessSubscriber

API Keys#

AuthGuard comes with a default API key provider but can also be configured to use a different one. For example, the JWT extension adds another provider for JWT-based API keys.

PropertyDescription
typeThe name/type of the provider to use ('default' or something else)
randomSizeSize of the key in bytes (default is 32 bytes)
hashThe hash configuration

Hash configuration:

PropertyDescription
algorithmOnly 'blake2b' is currently supported
keyThe secret key to use for hashing