NinjaAuth

Request the user's Ninjapay account verification. This can be used for authentication or linking of user's wallet. Using NinjaAuth is an easy and convenient way for users to log into and grant data access to your apps and games across multiple platforms.

Step1: Method


POST https://api.ninjapay.me/api/v1/auth

Parameters


Body (application/json)
 {
  ninjatag: <string>; // sends a six digit OTP to the linked account email
  kyc?: <bool> // Add <true> if you want the user's kyc in response (only given if user approves)
}

Response


{
    "status": <bool>,
    "data": {
        "secret": <string> // Use this secret along with OTP sent to user's email/phone to verify in the next step, this secret is expires after 60 seconds
    },
    "message": <string>
}

Step2: Method


POST https://api.ninjapay.me/api/v1/auth/verify

Parameters


{
  "secret": <string>, // secret from previous response
  "otp": <int> // OTP is sent to user's linked account email 
}

Response

{
    "status": true, //bool
       "data": {
        "user_id": "Mlsqm72edi9NOMnMDSpMKactuRw49",
        "ninjatag": "ninja",
        "profile": {
            "full_name": "satoshi nakamoto",
            "email": "sample@sample.com",
            "phone": "+917995232267",
            "country": "INDIA"
        },
        "kyc_level": 1,
        "kyc_status": "",
        "is_verified": true,
        "id_type": "",
        "personal_kyc": {
            "id1": "https://useridfile.com",
            "id2": "https://useridfile.com",
            "id3": "https://useridfile.com"
        },   
        "company_kyc": {
            "company_name": "satoshi nakamoto",
            "email": "sample@sample.com",
            "company_phone": "+917995232267",
            "country": "UAE",
            "doc1": "https://userdocfile.com",
            "doc2": "https://userdocfile.com",
            "doc3": "https://userdocfile.com",
            "doc4": "https://userdocfile.com"
        },
       "message": "Here is user data"
}

Code Example

// Declare a function for the first step
async function initiateVerification(ninjatag) {
  const accountVerificationOptions = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': 'API_KEY'
    },
    body: JSON.stringify({
      "ninjatag": ninjatag,
      "kyc": true
    })
  };

  const response = await fetch('https://prod.ninjapay.me/api/v1/auth', accountVerificationOptions);
  const data = await response.json();

  return data.secret;
}

// Declare a function for the second step
async function verifyAccount(secret, OTP) {
  const verifyOptions = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': 'API_KEY'
    },
    body: JSON.stringify({
      "secret": secret,
      "otp": OTP
    })
  };

  const response = await fetch('https://api.ninjapay.me/api/v1/auth/verify', verifyOptions);
  const data = await response.json();

  return data;
}

// Example of how to use these functions
async function authenticateUser(ninjatag) {
  try {
    const secret = await initiateVerification(ninjatag);

    // Here you would pause and wait for the user to provide the OTP from their email
    const OTP = prompt("Please enter the OTP you received via email");

    const verificationResult = await verifyAccount(secret, OTP);

    console.log(verificationResult);
  } catch (error) {
    console.error(error);
  }
}

// Call the function
authenticateUser("nakamoto");

Last updated