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

AngularJS Examples

JavaScript SDK

Angular Integration

Step 1: Add SDK in angular.json

Include the Authyo SDK globally:


// angular.json
"scripts": [
  "https://app.authyo.io/js/v1/auth-2fasdk.js"
]

Step 2: Add the Container in Component

Use a simple div placeholder in your HTML:

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

Step 3: Initialize Authyo in Component

Use lifecycle hook to initialize with your app key:

   
declare global {
  interface Window { authyoResponse: any; }
}

export class AppComponent implements OnInit {
ngOnInit(): void {
const script = document.createElement('script');
script.src = "https://app.authyo.io/js/v1/auth-2fasdk.js";
script.setAttribute("data-appkey", "YOUR_APP_KEY");
script.setAttribute("data-emauilid", "abc@xyz.com");
document.body.appendChild(script);

window.authyoResponse = (response: any) => {
if (response.success) {
console.log("✅ Success", response.data);
} else {
console.error("❌ Error", response.message);
}
};
}

}

'

Example: Full Angular HTML + Component


// app.component.html
<div id="authyo-sdk"></div>

// app.component.ts
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
ngOnInit(): void {
const script = document.createElement('script');
script.src = "https://app.authyo.io/js/v1/auth-sdk.js";
script.setAttribute("data-appkey", "123456-app-key-xyz");
script.setAttribute("data-emauilid", "abc@xyz.com");
document.body.appendChild(script);

window.authyoResponse = (response: any) => {
if (response.success) {
console.log("User verified:", response.data);
} else {
console.error("Login failed:", response.message);
}
};
}
}

Two Factor Authenticate – Requests & Responses

1) AuthState
Response
{
  "success": true,
  "IsTOtpVerified": false,
  "message": "ok"
}
    
2) Enable 2FA
Response
{
  "success": true,
  "message": "qrcode generated successfully",
  "QRCoder": "data:image/png;base64,....",
  "maskId": "optional"
}
    
3) Verify Otp
Response
{ "success": true, "message": "verified" }
    
4) Disable 2FA
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:16:49
Previous
JavaScript
Next
PHP
Built with