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.
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
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
-
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.
## 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.