Skip to content

Commit 7d1542e

Browse files
committed
feat(FR-2629): extend tokenLogin helper with optional extraParams (#6851)
Resolves FR-2629 (sub-task of Epic [FR-2616](https://lablup.atlassian.net/browse/FR-2616)) resolves #NNN (FR-MMM) <!-- replace NNN, MMM with the GitHub issue number and the corresponding Jira issue number. --> <!-- Please precisely, concisely, and concretely describe what this PR changes, the rationale behind codes, and how it affects the users and other developers. --> **Checklist:** (if applicable) - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after ## Stack This PR is part of the Story 1 stack for Epic FR-2616 (Extract sToken login flow into reusable boundary component). See the [dev plan](../blob/main/.specs/draft-stoken-login-boundary/dev-plan.md) for the full scope. The Story 1 PR stack is #6850#6851#6852#6853#6854#6855#6856 on top of spec PR #6828. [FR-2616]: https://lablup.atlassian.net/browse/FR-2616?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 9c80372 commit 7d1542e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

react/src/helper/loginSessionAuth.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,35 @@ export async function connectViaGQL(
171171

172172
/**
173173
* Perform token-based login (SSO).
174+
*
175+
* `extraParams` are forwarded to `client.token_login` alongside the `sToken`
176+
* argument. Callers typically collect these from URL query parameters (for
177+
* example, EduAppLauncher forwards `app`, `session_id`, resource hints) for
178+
* the server-side token handler. LoginView callers that do not need to
179+
* forward anything can omit the argument.
180+
*
181+
* Reserved keys (`sToken`, `stoken`) are stripped from `extraParams` before
182+
* forwarding so that the explicit `sToken` argument always wins, regardless
183+
* of whether a caller accidentally (or maliciously) included the token in
184+
* the forwarded query parameters. `client.token_login` merges `extraParams`
185+
* into the request body via `Object.assign`, so an unsanitized map would
186+
* otherwise overwrite the authenticated token field.
174187
*/
175188
export async function tokenLogin(
176189
client: any,
177190
sToken: string,
178191
cfg: LoginConfigState,
179192
endpoints: string[],
193+
extraParams?: Record<string, string>,
180194
): Promise<string[]> {
181-
const loginSuccess = await client.token_login(sToken);
195+
const sanitizedExtraParams = extraParams
196+
? Object.fromEntries(
197+
Object.entries(extraParams).filter(
198+
([key]) => key !== 'sToken' && key !== 'stoken',
199+
),
200+
)
201+
: {};
202+
const loginSuccess = await client.token_login(sToken, sanitizedExtraParams);
182203
if (!loginSuccess) {
183204
throw new Error('Cannot authorize session by token.');
184205
}

0 commit comments

Comments
 (0)