Skip to content

fix: redirect unauthorized git users to login screen #10995

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
merged 3 commits into from
Dec 7, 2023

Conversation

Kira-Pilot
Copy link
Member

@Kira-Pilot Kira-Pilot commented Dec 1, 2023

@@ -91,7 +91,7 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({
</div>
)}

{Boolean(info) && Boolean(error) && (
{Boolean(info) && (
Copy link
Member Author

Choose a reason for hiding this comment

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

@aslilac just want to double-check we don't need this error check here.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, this is probably fine

@Kira-Pilot Kira-Pilot requested a review from aslilac December 1, 2023 20:49
@Kira-Pilot Kira-Pilot changed the title fix: redirect to login screen if unauthorized git user fix: redirect unauthorized git users to login screen Dec 1, 2023
httpapi.Write(ctx, rw, http.StatusUnauthorized, codersdk.Response{
Message: "You aren't a member of the authorized Github organizations!",
})
httpmw.RedirectToLogin(rw, r, &url.URL{Path: "/login"}, "You aren't a member of the authorized Github organizations!")
Copy link
Member Author

Choose a reason for hiding this comment

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

if we're ok with this pattern, I can redirect similarly on the other oauth errors.

Copy link
Member

Choose a reason for hiding this comment

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

One issue with this function is that it sets ?redirect=${currentPath}, which we don't want to do. If you could change the httpmw.RedirectToLogin function to accept a nil *http.Request and avoid adding the redirect query param then it should solve the problem

httpapi.Write(ctx, rw, http.StatusUnauthorized, codersdk.Response{
Message: "You aren't a member of the authorized Github organizations!",
})
httpmw.RedirectToLogin(rw, r, &url.URL{Path: "/login"}, "You aren't a member of the authorized Github organizations!")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
httpmw.RedirectToLogin(rw, r, &url.URL{Path: "/login"}, "You aren't a member of the authorized Github organizations!")
httpmw.RedirectToLogin(rw, r, nil, "You aren't a member of the authorized Github organizations!")

dashboardURL defaults to /login if nil

Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

just some super minor suggestions. looks good!

@@ -62,7 +62,7 @@ export const useSingleSignOnSection = () => {
// The redirect on success should be back to the login page with a nice message.
// The user should be logged out if this worked.
encodeURIComponent(
`/login?info=Login type has been changed to ${loginTypeMsg}. Log in again using the new method.`,
`/login?message=Login type has been changed to ${loginTypeMsg}. Log in again using the new method.`,
Copy link
Member

Choose a reason for hiding this comment

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

this'll evaluate to "%2Flogin%3Fmessage%3DLogin%20type%20...", which I'm guessing is what we want but this diff doesn't give much context. if it was fine before though it's probably ok!

@@ -91,9 +91,9 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({
</div>
)}

{Boolean(info) && Boolean(error) && (
{Boolean(message) && (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{Boolean(message) && (
{message && (

nit: technically this cast is superfluous

@@ -63,7 +63,7 @@ export interface SignInFormProps {
isSigningIn: boolean;
redirectTo: string;
error?: unknown;
info?: string;
message?: string;
Copy link
Member

Choose a reason for hiding this comment

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

if this was message?: ReactNode;...

@@ -24,7 +24,8 @@ export const LoginPageView: FC<LoginPageViewProps> = ({
const redirectTo = retrieveRedirect(location.search);
// This allows messages to be displayed at the top of the sign in form.
// Helpful for any redirects that want to inform the user of something.
const info = new URLSearchParams(location.search).get("info") || undefined;
const message =
new URLSearchParams(location.search).get("message") || undefined;
Copy link
Member

Choose a reason for hiding this comment

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

...then you wouldn't need this || undefined!

@Kira-Pilot Kira-Pilot merged commit 091fdd6 into main Dec 7, 2023
@Kira-Pilot Kira-Pilot deleted the unauth-login-page/kirapilot branch December 7, 2023 14:19
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unauthorized login with Github should use frontend page
3 participants