This socket integrates two-factor authentication to syncano.
syncano-cli add two-factor-auth
-
rest-auth socket
Since there can be no authentication without first registering to a system, it is important to use the
rest-auth
socket for basic registration.
Link to two-factor-auth socket documentation
Demo web app repo using two-factor-auth socket
This endpoint sets up two-factor authentication for logged in user.
Parameters
Name | Type | Description | Example |
---|---|---|---|
username | string | User email | you@domain.com |
token | string | User token | cb21fac8c7dda8fcd0129b0adb0254dea5c8e |
Response
On success it returns the otpURL and dataURL(image url) for QR code.
The dataURL
is the image url in base64 which is expected to be used to display a Google Authenticator–compatible QR code
which can be scanned by a two-factor app like
Google Authenticator
{
message: "Verify OTP",
tempSecret: "LBGDOZBIKARWIRZI",
otpURL: "otpauth://totp/SecretKey?secret=LB",
dataURL: "data:image/png;base64,iVBORw0KGgoAAAANS"
}
This endpoint Verifies a two-factor token before enabling two-factor authentication on a user account to prevent locking user
Parameters
Name | Type | Description | Example |
---|---|---|---|
username | string | User email | you@domain.com |
token | string | User token | cb21fac8c7dda8fcd0129b0adb0254dea5c8e |
two-factor-token | string | One-time passcode | 897900 |
Response
{
message: "Two-factor authentication enabled"
}
This endpoint checks if two factor authentication is enabled on user account. This helps to determine on the client side if the option to setup or disable two-factor authentication will be made available to user
Parameters
Name | Type | Description | Example |
---|---|---|---|
username | string | User email | you@domain.com |
token | string | User token | cb21fac8c7dda8fcd0129b0adb0254dea5c8e |
Response
{
message: "Two-factor authentication is enabled on user account",
is_two_factor: true
}
This endpoint logs in a user and supports both, normal auth and two-factor authentication User with two-factor auth enabled will be required to input two-factor token along with username and password
Parameters
Name | Type | Description | Example |
---|---|---|---|
username | string | User email | you@domain.com |
password | string | User password | abcdefgh |
two-factor-token | string | One-time passcode | 897900 |
Response
{
token: "cb21ff98ac8c7dda8fcd01",
username: "you@domain.com"
}
This endpoint disables two-factor authentication on user account
Parameters
Name | Type | Description | Example |
---|---|---|---|
username | string | User email | you@domain.com |
token | string | User token | cb21fac8c7dda8fcd0129b0adb0254dea5c8e |
two-factor-token | string | One-time passcode | 897900 |
Response
{
message: "Two-factor authentication disabled"
}
- Fork this repository
- Clone from your fork
- Make your contributions (Make sure your work is well tested)
- Create Pull request from the fork to this repo
- Create a
.env
on parent folder - Copy contents of
.env-sample
file to newly created.env
file and assign appropriate values to the listed variables.
- Ensure all your test are written on the
test
directory - Use the command
npm test
to run test