-
Notifications
You must be signed in to change notification settings - Fork 993
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |||||
"fmt" | ||||||
"net/http" | ||||||
"net/mail" | ||||||
"net/url" | ||||||
"regexp" | ||||||
"sort" | ||||||
"strconv" | ||||||
|
@@ -535,9 +536,7 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) { | |||||
} | ||||||
} | ||||||
if len(selectedMemberships) == 0 { | ||||||
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!") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
dashboardURL defaults to |
||||||
return | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...then you wouldn't need this |
||
const applicationName = getApplicationName(); | ||
const logoURL = getLogoURL(); | ||
const applicationLogo = logoURL ? ( | ||
|
@@ -52,7 +53,7 @@ export const LoginPageView: FC<LoginPageViewProps> = ({ | |
redirectTo={redirectTo} | ||
isSigningIn={isSigningIn} | ||
error={error} | ||
info={info} | ||
message={message} | ||
onSubmit={onSignIn} | ||
/> | ||
<footer css={styles.footer}> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,7 +63,7 @@ export interface SignInFormProps { | |||||
isSigningIn: boolean; | ||||||
redirectTo: string; | ||||||
error?: unknown; | ||||||
info?: string; | ||||||
message?: string; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this was |
||||||
authMethods?: AuthMethods; | ||||||
onSubmit: (credentials: { email: string; password: string }) => void; | ||||||
} | ||||||
|
@@ -73,7 +73,7 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({ | |||||
redirectTo, | ||||||
isSigningIn, | ||||||
error, | ||||||
info, | ||||||
message, | ||||||
onSubmit, | ||||||
}) => { | ||||||
const oAuthEnabled = Boolean( | ||||||
|
@@ -91,9 +91,9 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({ | |||||
</div> | ||||||
)} | ||||||
|
||||||
{Boolean(info) && Boolean(error) && ( | ||||||
{Boolean(message) && ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: technically this cast is superfluous |
||||||
<div css={styles.alert}> | ||||||
<Alert severity="info">{info}</Alert> | ||||||
<Alert severity="info">{message}</Alert> | ||||||
</div> | ||||||
)} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
), | ||
); | ||
}, | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 thehttpmw.RedirectToLogin
function to accept a nil*http.Request
and avoid adding the redirect query param then it should solve the problem