Spaces:
Running
Running
Commit ·
2ae6728
1
Parent(s): d140e69
feat: add ALLOWED_USERS allowlist for OAuth login
Browse files- .env.example +6 -2
- app/api/auth/callback/route.js +12 -0
.env.example
CHANGED
|
@@ -4,5 +4,9 @@ HF_TOKEN=your_hf_token_here
|
|
| 4 |
# Optional: Override the default HF dataset repo
|
| 5 |
# HF_DATASET_REPO=rafmacalaba/wbg_annotation_data
|
| 6 |
|
| 7 |
-
# Optional: Number of documents to scan on initial load (default:
|
| 8 |
-
# MAX_DOCS_TO_SCAN=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Optional: Override the default HF dataset repo
|
| 5 |
# HF_DATASET_REPO=rafmacalaba/wbg_annotation_data
|
| 6 |
|
| 7 |
+
# Optional: Number of documents to scan on initial load (default: 50)
|
| 8 |
+
# MAX_DOCS_TO_SCAN=50
|
| 9 |
+
|
| 10 |
+
# Optional: Comma-separated list of allowed HF usernames for OAuth login
|
| 11 |
+
# If not set, any HF user can sign in
|
| 12 |
+
# ALLOWED_USERS=rafmacalaba,rafamacalaba
|
app/api/auth/callback/route.js
CHANGED
|
@@ -67,6 +67,18 @@ export async function GET(request) {
|
|
| 67 |
const userInfo = await userRes.json();
|
| 68 |
const username = userInfo.preferred_username || userInfo.name || 'user';
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
// Set session cookie with username
|
| 71 |
const response = NextResponse.redirect(host);
|
| 72 |
response.cookies.set('hf_user', JSON.stringify({
|
|
|
|
| 67 |
const userInfo = await userRes.json();
|
| 68 |
const username = userInfo.preferred_username || userInfo.name || 'user';
|
| 69 |
|
| 70 |
+
// Check allowlist (if ALLOWED_USERS is set)
|
| 71 |
+
const allowedUsers = process.env.ALLOWED_USERS;
|
| 72 |
+
if (allowedUsers) {
|
| 73 |
+
const allowlist = allowedUsers.split(',').map(u => u.trim().toLowerCase());
|
| 74 |
+
if (!allowlist.includes(username.toLowerCase())) {
|
| 75 |
+
return NextResponse.json(
|
| 76 |
+
{ error: `Access denied. User "${username}" is not in the allowed list.` },
|
| 77 |
+
{ status: 403 }
|
| 78 |
+
);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
// Set session cookie with username
|
| 83 |
const response = NextResponse.redirect(host);
|
| 84 |
response.cookies.set('hf_user', JSON.stringify({
|