Skip to content
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

Redirect with query param #2811

Merged
merged 5 commits into from
Oct 16, 2024
Merged

Redirect with query param #2811

merged 5 commits into from
Oct 16, 2024

Conversation

pablonyx
Copy link
Contributor

@pablonyx pablonyx commented Oct 15, 2024

Preserve user context during logout/login:

  • Added state param to get_auth_router for improved tracking
  • UserDropdown logout now redirects to original URL with query params
  • Search/chat pages preserve URL and query params when redirecting to login
Screen.Recording.2024-10-15.at.3.17.04.PM.mov

Copy link

vercel bot commented Oct 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
internal-search ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 15, 2024 11:29pm

@pablonyx pablonyx changed the title validated Redirect with query param Oct 15, 2024
@pablonyx pablonyx marked this pull request as ready for review October 15, 2024 22:50
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR enhances user authentication flow by preserving context during logout/login processes, focusing on maintaining original URLs and query parameters across redirects.

  • Added state parameter to create_danswer_oauth_router in backend/danswer/auth/users.py for improved security and tracking
  • Modified web/src/components/UserDropdown.tsx to redirect to login with encoded current URL as query parameter after logout
  • Updated web/src/app/auth/oauth/callback/route.ts and web/src/app/auth/oidc/callback/route.ts to handle manual redirections and preserve backend-provided redirect URLs
  • Implemented nextUrl parameter in web/src/lib/userSS.ts for authentication URL generation functions to maintain context
  • Adjusted web/src/app/search/page.tsx to handle query parameters during redirection for unauthenticated users

11 file(s) reviewed, 9 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +840 to +849
# Copy headers and other attributes from 'response' to 'redirect_response'
for header_name, header_value in response.headers.items():
redirect_response.headers[header_name] = header_value

if hasattr(response, "body"):
redirect_response.body = response.body
if hasattr(response, "status_code"):
redirect_response.status_code = response.status_code
if hasattr(response, "media_type"):
redirect_response.media_type = response.media_type
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Copying response attributes may expose sensitive information. Ensure only necessary data is transferred

@@ -81,7 +82,6 @@
router as token_rate_limit_settings_router,
)
from danswer.setup import setup_danswer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Removal of setup_multitenant_danswer might affect multi-tenant setups. Verify this change doesn't break existing functionality

@@ -59,7 +63,7 @@ const Page = async ({
let authUrl: string | null = null;
if (authTypeMetadata) {
try {
authUrl = await getAuthUrlSS(authTypeMetadata.authType);
authUrl = await getAuthUrlSS(authTypeMetadata.authType, nextUrl!);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using non-null assertion (!). Consider adding a null check for nextUrl instead.

Comment on lines 91 to 93
alert("Failed to logout");
return;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more user-friendly error message

Comment on lines +104 to +106
const searchParamsString = new URLSearchParams(
searchParams as unknown as Record<string, string>
).toString();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more type-safe approach for converting searchParams

@@ -40,8 +44,12 @@ export const getAuthDisabledSS = async (): Promise<boolean> => {
return (await getAuthTypeMetadataSS()).authType === "disabled";
};

const geOIDCAuthUrlSS = async (): Promise<string> => {
const res = await fetch(buildUrl("/auth/oidc/authorize"));
const geOIDCAuthUrlSS = async (nextUrl: string | null): Promise<string> => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Typo in function name: 'geOIDCAuthUrlSS' should be 'getOIDCAuthUrlSS'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely seems wrong?

Comment on lines 99 to 100
return await getSAMLAuthUrlSS();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: SAML auth URL generation doesn't use nextUrl. Consider if this is intentional or if it should be updated for consistency.

@@ -40,8 +44,12 @@ export const getAuthDisabledSS = async (): Promise<boolean> => {
return (await getAuthTypeMetadataSS()).authType === "disabled";
};

const geOIDCAuthUrlSS = async (): Promise<string> => {
const res = await fetch(buildUrl("/auth/oidc/authorize"));
const geOIDCAuthUrlSS = async (nextUrl: string | null): Promise<string> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely seems wrong?

@pablonyx pablonyx added this pull request to the merge queue Oct 16, 2024
Merged via the queue into main with commit 1a9921f Oct 16, 2024
7 checks passed
@pablonyx pablonyx deleted the user_redirect branch October 17, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants