-
Notifications
You must be signed in to change notification settings - Fork 0
F2F-1528 rtcv scraper protocol routes proxyen via app #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mjarkk
merged 12 commits into
main
from
F2F-1528-rtcv-scraper-protocol-routes-proxyen-via-app
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f048bd9
feat: add F2F_APP mode with challenge-response auth and route remapping
JanR2024 28dc275
refactor: replace route mapping module with inline path ternaries
74f0e6f
refactor: use single F2F_APP env var with URL format
eec34c1
fix: add error handling to challenge-response auth
ee17fc6
refactor: let alternative server decide its own CV document path
5654816
chore: fix AppAuth comments to reflect single F2F_APP env var
c19f98f
fix: update comment for RTCV_ALTERNATIVE_SERVER usage in RT-CV mode
JanR2024 15fb8cd
refactor: always send X-Scraper-Slug header
JanR2024 f8fc8ac
feat: use custom f2f:// protocol for F2F_APP env var
JanR2024 7a9d216
feat: support f2fs:// for HTTPS in F2F_APP
JanR2024 b50e343
feat: enforce f2f:// or f2fs:// protocol for F2F_APP
JanR2024 f175eba
docs: add F2F_APP env vars to .env.example
JanR2024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * Challenge-response authentication for the f2f-app. | ||
| * | ||
| * Flow: | ||
| * 1. POST /api/tokens/challenge {nameSlug} -> {challenge} | ||
| * 2. proof = lowercase(hex(sha512(challenge + secret))) | ||
| * 3. POST /api/tokens/exchange {nameSlug, proof} -> {token} | ||
| * 4. Cache token for 8 minutes (tokens are valid 10 min, 2 min buffer) | ||
| */ | ||
|
|
||
| const TOKEN_CACHE_DURATION_MS = 8 * 60 * 1000 | ||
|
|
||
| export interface AppAuth { | ||
| url: string // from F2F_APP origin | ||
| keyId: string // from F2F_APP, API token nameSlug | ||
| keySecret: string // from F2F_APP, API token secret | ||
| } | ||
|
|
||
| export class AppTokenManager { | ||
| private token: string | null = null | ||
| private tokenExpiresAt: number = 0 | ||
|
|
||
| constructor(private auth: AppAuth) {} | ||
|
|
||
| async getToken(): Promise<string> { | ||
| if (this.token && Date.now() < this.tokenExpiresAt) { | ||
| return this.token | ||
| } | ||
|
|
||
| return await this.authenticate() | ||
| } | ||
|
|
||
| private async authenticate(): Promise<string> { | ||
| const base = this.auth.url + "/api/tokens" | ||
| const headers = { "Content-Type": "application/json" } | ||
|
|
||
| // 1. Request challenge | ||
| const challengeRes = await fetch(`${base}/challenge`, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ nameSlug: this.auth.keyId }), | ||
| }) | ||
| if (!challengeRes.ok) throw new Error(`F2F App challenge failed (${challengeRes.status}): ${await challengeRes.text()}`) | ||
| const { challenge } = await challengeRes.json() as { challenge: string } | ||
|
|
||
| // 2. Calculate proof (SHA-512) | ||
| const msgUint8 = new TextEncoder().encode(challenge + this.auth.keySecret) | ||
| const hashBuffer = await crypto.subtle.digest("SHA-512", msgUint8) | ||
| const hashArray = Array.from(new Uint8Array(hashBuffer)) | ||
| const proof = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("") | ||
|
|
||
| // 3. Exchange for token | ||
| const tokenRes = await fetch(`${base}/exchange`, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ nameSlug: this.auth.keyId, proof }), | ||
| }) | ||
| if (!tokenRes.ok) throw new Error(`F2F App token exchange failed (${tokenRes.status}): ${await tokenRes.text()}`) | ||
| const { token } = await tokenRes.json() as { token: string } | ||
|
|
||
| // 4. Cache token | ||
| this.token = token | ||
| this.tokenExpiresAt = Date.now() + TOKEN_CACHE_DURATION_MS | ||
|
|
||
| return token | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.