-
Notifications
You must be signed in to change notification settings - Fork 12
feat(agent-bff): mode 1 oauth session core (issue tokens) #1715
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
Open
Tonours
wants to merge
20
commits into
feature/prd-647-scaffold-the-agent-bff-package
Choose a base branch
from
feature/prd-664-agent-nodejs-mode-1-oauth-session-core-issue-tokens
base: feature/prd-647-scaffold-the-agent-bff-package
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,693
−13
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
16b5b51
feat(agent-bff): add oauth deps and token encryption key config
Tonours d6e8907
feat(agent-bff): add token cipher and session store with encrypted at…
Tonours 54b257a
feat(agent-bff): add forest server client, oauth errors and pkce helpers
Tonours 809f589
feat(agent-bff): add mode 1 oauth authorize and token endpoints
Tonours 0453e15
feat(agent-bff): wire oauth routes and lazy saas token refresh
Tonours f37980d
fix(agent-bff): cap pending authorization codes to bound memory dos
Tonours d31caaf
fix(agent-bff): harden forest server client url, client lookup and re…
Tonours 219ba73
fix(agent-bff): keep booting when the forest server is unreachable at…
Tonours 574bab9
refactor(agent-bff): reject empty authorize params and split token ha…
Tonours 57f2cad
refactor(agent-bff): reduce oauth config and route dispatch complexity
Tonours bd81365
fix(agent-bff): address review feedback on oauth error mapping, timeo…
Tonours 07550cb
test(agent-bff): align tests with review fixes and raise coverage
Tonours cbde6e5
fix(agent-bff): distinguish transient refresh failures, guard refresh…
Tonours a35a769
test(agent-bff): cover identity delegation, param pollution, 502 mapp…
Tonours 4ca4af3
refactor(agent-bff): extract RouteHandler type alias for route dispatch
Tonours f819f6b
refactor(agent-bff): validate encryption key only when present
Tonours bd4f843
refactor(agent-bff): compute renderingId validity once in toServerTokens
Tonours 68098c1
fix(agent-bff): enforce token expiry cap, zero pending-code cap and r…
Tonours a38bedb
fix(agent-bff): release auth code on post-exchange failure to keep to…
Tonours 2449541
fix(agent-bff): reject auth-code claims at cap instead of evicting li…
Tonours 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
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
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,53 @@ | ||
| import type { UserInfo } from '@forestadmin/forestadmin-client'; | ||
|
|
||
| import jsonwebtoken from 'jsonwebtoken'; | ||
|
|
||
| export const BFF_ACCESS_TOKEN_TYPE = 'bff_access'; | ||
| export const BFF_ACCESS_TOKEN_MAX_EXPIRES_IN = 15 * 60; | ||
|
|
||
| export interface IssueBffAccessTokenParams { | ||
| sid: string; | ||
| user: UserInfo; | ||
| renderingId: number; | ||
| authSecret: string; | ||
| expiresInSeconds: number; | ||
| } | ||
|
|
||
| export interface BffAccessTokenPayload { | ||
| type: typeof BFF_ACCESS_TOKEN_TYPE; | ||
| sid: string; | ||
| id: number; | ||
| email: string; | ||
| first_name: string; | ||
| last_name: string; | ||
| team: string; | ||
| rendering_id: string; | ||
| permission_level: string; | ||
| tags: Record<string, string>; | ||
| } | ||
|
|
||
| export function issueBffAccessToken({ | ||
| sid, | ||
| user, | ||
| renderingId, | ||
| authSecret, | ||
| expiresInSeconds, | ||
| }: IssueBffAccessTokenParams): string { | ||
| const payload: BffAccessTokenPayload = { | ||
| type: BFF_ACCESS_TOKEN_TYPE, | ||
| sid, | ||
| id: user.id, | ||
| email: user.email, | ||
| first_name: user.firstName, | ||
| last_name: user.lastName, | ||
| team: user.team, | ||
| rendering_id: String(renderingId), | ||
| permission_level: user.permissionLevel, | ||
| tags: user.tags ?? {}, | ||
| }; | ||
|
|
||
| return jsonwebtoken.sign(payload, authSecret, { | ||
| algorithm: 'HS256', | ||
| expiresIn: Math.min(expiresInSeconds, BFF_ACCESS_TOKEN_MAX_EXPIRES_IN), | ||
| }); | ||
| } |
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.