Skip to content

Syncano/syncano-socket-two-factor-auth

Repository files navigation

Two-factor Auth Syncano Socket

CircleCI

This socket integrates two-factor authentication to syncano.

Install

syncano-cli add two-factor-auth

Dependencies

  • 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 rest-auth socket documentation

Socket Documentation

Link to two-factor-auth socket documentation

Demo

Demo web app repo using two-factor-auth socket

Endpoints

setup-two-factor

This endpoint sets up two-factor authentication for logged in user.

Parameters

Name Type Description Example
username string User email [email protected]
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"
}

verify-token

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 [email protected]
token string User token cb21fac8c7dda8fcd0129b0adb0254dea5c8e
two-factor-token string One-time passcode 897900

Response

{
  message: "Two-factor authentication enabled"
}

check-two-factor

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 [email protected]
token string User token cb21fac8c7dda8fcd0129b0adb0254dea5c8e

Response

{
  message: "Two-factor authentication is enabled on user account",
  is_two_factor: true
}

login

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 [email protected]
password string User password abcdefgh
two-factor-token string One-time passcode 897900

Response

{
  token: "cb21ff98ac8c7dda8fcd01",
  username: "[email protected]"
}

disable-two-factor

This endpoint disables two-factor authentication on user account

Parameters

Name Type Description Example
username string User email [email protected]
token string User token cb21fac8c7dda8fcd0129b0adb0254dea5c8e
two-factor-token string One-time passcode 897900

Response

{
  message: "Two-factor authentication disabled"
}

Contributing

How to Contribute

  • 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

Setting up environment variables

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

Testing

  • Ensure all your test are written on the test directory
  • Use the command npm test to run test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published