SDK Quickstart

Get SilentAuth integrated in under 5 minutes.

Installation

Install the SilentAuth SDK for your platform:

JavaScript / TypeScript

npm install @silentauth/sdk

Python

pip install silentauth

Go

go get github.com/silentauth/silentauth-go

PHP

composer require silentauth/silentauth-php

Client-Side Setup

Add the SilentAuth widget to your page:

import { SilentAuth } from '@silentauth/sdk';

const sa = new SilentAuth({
projectId: 'your_project_id',
});

// Get a verification token
const token = await sa.verify({
action: 'login',
});

// Send the token with your form submission
fetch('/api/login', {
method: 'POST',
body: JSON.stringify({ ...formData, saToken: token }),
});

Server-Side Verification

Always verify tokens on your server:

import { SilentAuth } from '@silentauth/node';

const sa = new SilentAuth({
projectId: process.env.SA_PROJECT_ID,
secretKey: process.env.SA_SECRET_KEY,
});

app.post('/api/login', async (req, res) => {
const result = await sa.verify({
token: req.body.saToken,
action: 'login',
});

if (!result.success || result.risk_score > 0.5) {
return res.status(403).json({ error: 'Verification failed' });
}

// Proceed with login...
});

React Integration

import { SilentAuthProvider, useSilentAuth } from '@silentauth/react';

function App() {
return (
<SilentAuthProvider projectId="your_project_id">
<LoginForm />
</SilentAuthProvider>
);
}

function LoginForm() {
const { verify } = useSilentAuth();

const handleSubmit = async (e) => {
e.preventDefault();
const token = await verify({ action: 'login' });
// Submit form with token
};

return <form onSubmit={handleSubmit}>...</form>;
}

Next Steps

← Back to Documentation