One-Time Password

SAP Commerce supports the functionality of creating and validating one-time passwords, which is a form of two-factor authentication (2FA). These passwords can be used in various scenarios.

Customer Login with One-Time Verification Token

You can enhance security using the one-time password functionality. To enable one-time passwords for customers when logging into composable storefronts:

  • Update your composable storefront codebase and enable the one-time password functionality for customers. For more information on how to do this, see Patch Upgrade Notes.

When one-time verification token for customer login is enabled, the Customer User token can be retrieved from the Commerce Authorization Server only with the one-time password <Token Id> provided as <username> and one-time password <Token Code> provided as <password>. To be able to fetch a user token you first have to create a one-time login password for that Customer. After fetching one-time password <Token Id> from the OCC API and receiving <Token Code> in an email, you can request a Customer Token with the following command:
curl --location --request POST 'https://<COMMERCE_CLOUD_BACKOFFICE_URL>/authorizationserver/oauth/token' \
--header 'Accept: application/json, text/plain, */*' \
--header 'Authorization: Basic <BASE64_ENCODED_OAUTH_CLIENT_CREDENTIALS>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'X-Requested-With: XMLHttpRequest' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'scope=basic' \
--data-urlencode 'username=<TOKEN_ID>' \
--data-urlencode 'password=<TOKEN_CODE>'

Preventing Brute Force Attacks

Using the otp.customer.login.token.max.verification.attempts property, you can set the maximum number of failed login attempts for a one-time token. If the maximum number of failed login attempts is reached, the specific one-time token can no longer be used to authenticate as it was removed. By default, the token is removed after the third failed attempt. You can override it in local.properties, as shown in the example:
otp.customer.login.token.max.verification.attempts = 5

The Customer login one-time password functionality can be adjusted by overriding the default configuration properties, described below:

# Specifies if the one time password (OTP) functionality is enabled for customer login
otp.customer.login.enabled = false
# Specifies the token encoder to be used for one time password code encoding functionality, see the available options in passwordEncoders of de.hybris.platform.persistence.security.PasswordEncoderFactoryImpl
otp.customer.login.token.code.encoder = pbkdf2
# When OTP is enabled allows to specify the length of verification tokens for OTP login functionality
# the minimum allowed value is 6 characters, maximum allowed value is 34 characters
otp.customer.login.token.code.length = 8
# When OTP is enabled allows to set a specific character set with which the code for the OTP login functionality will be generated
# The minimal charset length should be 10 characters. If the provided charset is shorter, the default charset value 1234567890ABCDEFGHKLMNPRSTUWXYZabcdefghijklmnoprstuwxyz is used.
otp.customer.login.token.code.alphabet = 1234567890ABCDEFGHKLMNPRSTUWXYZabcdefghijklmnoprstuwxyz
# When OTP is enabled allows to specify time to live in seconds for the OTP login functionality
# the maximum allowed value is 900 seconds (15 minutes), minimum allowed value is 60 seconds
otp.customer.login.token.ttlseconds = 300
# Specifies the maximum number of failed verification attempts for a single token, after which the token is removed from the system. Valid range is 1-10
# 1 means that the token is removed after the first failed verification attempt ( no retries allowed )
otp.customer.login.token.max.verification.attempts = 3
# Number of bits used to generate the random part of the token id for the one time password (OTP) login functionality
# The minimum allowed value is 128 bits. Its recommended to use at least 256 bits. Max value is 1024 bits
otp.customer.login.token.id.generator.bits = 256
# This short name is used to quickly identify the tokens generated for the OTP login functionality.
# The token id format is <{shortName}[{randomPart}]>
# The short name should be unique for initial verification purpose and kept short (max 10 characters) as it does not add any security value.
# If the short name exceeds 10 characters, it will be fallback to default 'OTH' (other) short name.
otp.customer.login.token.purpose.short.name = LGN
# Specifies if there should be maximum number of active tokens which can be created.
otp.customer.login.token.maxcount.enabled=false
# Maximum number of active tokens which can exist at the moment. If this number is reached then the attempts to create the token will fail.
# The minimum allowed value is 1, max value is 20.
otp.customer.login.token.maxcount=5

Leveraging One-Time Password Feature

One-time passwords can be easily reused for other scenarios. To do so, you can define the new purpose of the one-time password by:
  • Extending de.hybris.platform.core.enums.SAPUserVerificationPurpose in *-items.xml with a new purpose, for example PASSWORDCHANGE, ORDER or other.

  • Use the de.hybris.platform.servicelayer.user.UserVerificationTokenService to create, lookup, and handle one-time token verification in your business logic.

Each de.hybris.platform.core.enums.SAPUserVerificationPurpose can have a custom set of additional configuration properties defined. Here's an example of a sample set of custom properties for the new PASSWORDCHANGE verification purpose type:
## The recipe for configuring new OTP purpose functionality is to create a set of properties according to rule: otp.customer.{SAPUserVerificationPurpose.code.toLowerCase()}.{detailedPropertyName}
## The same safe defaults as for customer login OTP are used for other OTP functionalities.
## Lets see this on example set of properties for a password change OTP after PASSWORDCHANGE code is added to SAPUserVerificationPurpose enum (and proper logic is implemented)
#otp.customer.registration.enabled = false
##otp.customer.passwordchange.enabled = false
#otp.customer.passwordchange.token.code.encoder = pbkdf2
#otp.customer.passwordchange.token.code.length = 8
#otp.customer.passwordchange.token.code.alphabet = 1234567890ABCDEFGHKLMNPRSTUWXYZabcdefghijklmnoprstuwxyz
#otp.customer.passwordchange.token.ttlseconds = 300
#otp.customer.passwordchange.token.max.verification.attempts = 3
#otp.customer.passwordchange.token.id.generator.bits = 256
#otp.customer.passwordchange.token.purpose.short.name = PWC
#otp.customer.passwordchange.token.maxcount.enabled=true
#otp.customer.passwordchange.token.maxcount=5

If some property value isn't provided for a new verification purpose type, the default value is applied.