Authyo Docs
  1. 2FA SDK
Authyo Docs
  • 🐶 Walk through Authyo
  • Error Codes
  • About Pricing
  • APIs
    • Send OTP
      GET
    • Send OTP
      POST
    • Verify OTP
      GET
    • Verify Token
      POST
    • Revoke User Session
      POST
  • Web SDKs
    • JavaScript
    • PHP
    • AngularJS Examples
    • TypeScript Examples
    • React JS
    • Vue JS Examples
  • 2FA SDK
    • JavaScript
    • AngularJS Examples
    • PHP
    • React JS
    • TypeScript Examples
    • Vue JS Examples
  • Native/Mobile SDKs
    • Flutter
  • Integration
    • Google Sheet
    • Firebase
  • Session Management
    • Introductions
    • JWT Token
  1. 2FA SDK

JavaScript

JavaScript SDK

JavaScript Integration

Step 1: Add the Container

Place a container element in your HTML to hold the Authyo widget.

<div id="authyo-2fasdk"></div>

Step 2: Include the SDK Script

Include the hosted Authyo SDK and pass your App Key using data-appkey:

<script src="https://app.authyo.io/js/v1/auth-2fasdk.js" data-appkey="YOUR_APP_KEY" data-emailid="abc@xyz.com" ></script>

Step 3: Optional – Capture the Response

Handle success or failure using window.authyoResponse:

<script>
  window.authyoResponse = function(response) {
    if (response.success) {
      alert('Success: ' + response.message);
    } else {
      alert('Error: ' + response.message);
    }
  };
</script>

Example: Complete Integration

<div id="authyo-2fasdk"></div>
 <script src="https://app.authyo.io/js/v1/auth-2fasdk.js" data-appkey="123456-app-key-xyz" data-emailid="abc@xyz.com" ></script>  
<script>
      window.authyoResponse = function(response) {
        if (response.success) {
          console.log("User verified:", response.data);
        } else {
          console.log("Login failed:", response.message);
        }
      };
</script>

Two Factor – Requests & Responses

1) POST /api/v1/authyoclient/authstate
Body
{ "domainUrl": "<origin>", "appKey": "<appkey>", "identity": "<email>" }
    
Response
{
  "success": true,
  "IsTOtpVerified": false,
  "message": "ok"
}
    
2) POST /api/v1/authyoclient/enable2fa
Body
{ "domainUrl": "<origin>", "appKey": "<appkey>", "identity": "<email>" }
    
Response
{
  "success": true,
  "message": "qrcode generated successfully",
  "QRCoder": "data:image/png;base64,....",
  "maskId": "optional"
}
    
3) POST /api/v1/authyoclient/verifyotp
Body
{ "appKey": "<appkey>", "domainUrl": "<ui-origin>", "identity": "<email>", "maskId": "optional", "otp": "123456" }
    
Response
{ "success": true, "message": "verified" }
    
4) POST /api/v1/authyoclient/disable2fa
Body
{ "domainUrl": "<origin>", "appKey": "<appkey>", "identity": "<email>" }
    
Response
{ "success": true, "message": "2FA disabled" }
    

Troubleshooting

ProblemFix
Widget not loadingEnsure #authyo-2fasdk div exists before the script
Blank screenEnsure valid data-appkey and data-emailid is used
No response callbackImplement window.authyoResponse
Styling offCheck App Key design settings in dashboard
Modified at 2025-10-06 13:10:22
Previous
Vue JS Examples
Next
AngularJS Examples
Built with