Bring Your Own Authentication (BYO Auth)
Use your existing authentication system and integrate Volr SDK seamlessly. BYO Auth allows you to mint a Volr session only when needed, deferring wallet creation until the user actually needs to make a payment.
Which method should I use?
Choose the integration method that best fits your existing authentication setup:
Quick Decision Guide
Do you have a backend server?
- ✅ Yes → Use Server Session Injection (recommended)
- ❌ No → Use OIDC Token Exchange
Are you using OIDC/JWT authentication?
- ✅ Yes → Use OIDC Token Exchange
- ❌ No → Use Server Session Injection
Comparison
| Feature | Server Session Injection | OIDC Token Exchange |
|---|---|---|
| Security | High (server-side) | Medium (client-side exchange) |
| Implementation | Easy | Medium |
| Best for | Backend server available | Already using OIDC/JWT |
| Requires | Backend API endpoint | OIDC issuer configuration |
Server Session Injection
Is this the right method for you?
✅ You have a backend server (Node.js, Python, etc.)
✅ You can make server-side API calls
✅ You want the highest security (server-side token creation)
How it works
Step-by-step guide
Follow these steps to integrate Server Session Injection. Check off each step as you complete it.
✅ Step 1: Generate Server Secret
Checklist:
- Go to your project settings in the Volr Dashboard
- Navigate to Settings > Authentication > BYO Auth
- Select Server Session Injection
- Click Generate Secret or Rotate Secret
- Copy the secret immediately (it's shown only once)
- Store it securely in your server environment variables (e.g., AWS Secrets Manager)
⚠️ Never expose the server secret to the client!
Code to store secret:
# Example: Store in environment variables
export VOLR_SERVER_SECRET=volr_ssk_...
✅ Step 2: Create backend endpoint
Create an endpoint in your backend that calls Volr API to create a session.
- Node.js/Express
- Next.js API Route
- Python/FastAPI
app.post('/api/auth/volr-session', async (req, res) => {
// Get authenticated user from your auth middleware
const { userId, email, name } = req.user;
const response = await fetch('https://api.volr.io/auth/external/session', {
method: 'POST',
headers: {
'X-API-Key': process.env.VOLR_API_KEY,
'X-Volr-Server-Secret': process.env.VOLR_SERVER_SECRET,
'Content-Type': 'application/json',
},
body: JSON.stringify({
externalUserId: userId,
email: email,
name: name,
}),
});
if (!response.ok) {
return res.status(500).json({ error: 'Failed to create Volr session' });
}
const { accessToken, refreshToken } = await response.json();
res.json({ accessToken, refreshToken });
});
// pages/api/auth/volr-session.ts (or app/api/auth/volr-session/route.ts)
import type { NextApiRequest, NextApiResponse } from 'next';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
// Get authenticated user from your session/auth
const user = await getAuthenticatedUser(req);
if (!user) {
return res.status(401).json({ error: 'Unauthorized' });
}
try {
const response = await fetch('https://api.volr.io/auth/external/session', {
method: 'POST',
headers: {
'X-API-Key': process.env.VOLR_API_KEY!,
'X-Volr-Server-Secret': process.env.VOLR_SERVER_SECRET!,
'Content-Type': 'application/json',
},
body: JSON.stringify({
externalUserId: user.id,
email: user.email,
name: user.name,
}),
});
if (!response.ok) {
const error = await response.text();
return res.status(response.status).json({ error });
}
const { accessToken, refreshToken } = await response.json();
res.json({ accessToken, refreshToken });
} catch (error) {
console.error('Volr session creation failed:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
from fastapi import FastAPI, Depends, HTTPException
import httpx
import os
app = FastAPI()
@app.post("/api/auth/volr-session")
async def create_volr_session(user: dict = Depends(get_authenticated_user)):
async with httpx.AsyncClient() as client:
response = await client.post(
"https://api.volr.io/auth/external/session",
headers={
"X-API-Key": os.getenv("VOLR_API_KEY"),
"X-Volr-Server-Secret": os.getenv("VOLR_SERVER_SECRET"),
"Content-Type": "application/json",
},
json={
"externalUserId": user["id"],
"email": user.get("email"),
"name": user.get("name"),
},
)
if response.status_code != 200:
raise HTTPException(status_code=500, detail="Failed to create Volr session")
data = response.json()
return {"accessToken": data["accessToken"], "refreshToken": data["refreshToken"]}
✅ Step 3: Inject session in client
Checklist:
- After user logs in with your existing auth, call your backend endpoint
- Receive Volr tokens (
accessToken,refreshToken) from backend - Call
setSession()with the tokens - Verify that Volr SDK is ready
After your user logs in, call your backend endpoint and inject the Volr session.
React example:
import { useVolrSession } from '@volr/react';
import { useEffect } from 'react';
function App() {
const { setSession } = useVolrSession();
useEffect(() => {
// After your existing login succeeds
yourLoginFunction().then(async (user) => {
// Get Volr session from your backend
const res = await fetch('/api/auth/volr-session', {
credentials: 'include', // Include your session cookie
});
if (!res.ok) {
console.error('Failed to get Volr session');
return;
}
const { accessToken, refreshToken } = await res.json();
// Inject into Volr SDK
await setSession({ accessToken, refreshToken });
// Now Volr SDK is ready to use!
});
}, [setSession]);
}