Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oidc update
Browse files Browse the repository at this point in the history
ybizeul committed Sep 4, 2024
1 parent c15a47e commit 9bf6831
Showing 4 changed files with 16 additions and 12 deletions.
13 changes: 6 additions & 7 deletions html/src/Pages/SharesPage.tsx
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import { IconChevronDown, IconMoodSad } from "@tabler/icons-react";
import { AxiosError } from "axios";
import { ShareEditor } from "@/Components/ShareEditor";
import { useMediaQuery } from "@mantine/hooks";

import classes from './SharesPage.module.css';

export function SharesPage(props: {owner: string|null}) {
@@ -48,20 +49,18 @@ export function SharesPage(props: {owner: string|null}) {
})
.catch((e) => {
console.log(e)
setError(e)
if (e.response?.status === 401) {
navigate('/')
return
}
})
},[])
},[navigate])

useEffect(() => {
updateShares()
},[updateShares])

if (error) {
if (error.response?.status === 401) {
navigate('/')
return
}

return (
<Center h="100vh">
<Stack align="center" pb="10em">
4 changes: 1 addition & 3 deletions hupload/pkg/apiws/authentication/oidc.go
Original file line number Diff line number Diff line change
@@ -54,10 +54,8 @@ func (o *AuthenticationOIDC) AuthenticateRequest(w http.ResponseWriter, r *http.
if r.URL.Path == "/login" {
http.Redirect(w, r, o.Config.AuthCodeURL("state"), http.StatusFound)
return ErrAuthenticationRedirect
} else {
w.WriteHeader(http.StatusAccepted)
return nil
}
return nil
}

func (o *AuthenticationOIDC) CallbackFunc(h http.Handler) (func(w http.ResponseWriter, r *http.Request), bool) {
8 changes: 7 additions & 1 deletion hupload/pkg/apiws/middleware/auth/basic.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,13 @@ func (a BasicAuthMiddleware) Middleware(next http.Handler) http.Handler {
return
}

// If there is no credentials, skip middleware
var qUser string
var ok bool
if qUser, _, ok = r.BasicAuth(); !ok {
next.ServeHTTP(w, r)
}

// If authentication has been sent, check credentials

err := a.Authentication.AuthenticateRequest(nil, r)
@@ -50,7 +57,6 @@ func (a BasicAuthMiddleware) Middleware(next http.Handler) http.Handler {
return
}

qUser, _, _ := r.BasicAuth()
ServeNextAuthenticated(qUser, next, w, r)
})
}
3 changes: 2 additions & 1 deletion hupload/pkg/apiws/middleware/auth/oidc.go
Original file line number Diff line number Diff line change
@@ -36,9 +36,10 @@ func (a OIDCAuthMiddleware) Middleware(next http.Handler) http.Handler {
return
}
ServeNextError(next, w, r, err)
return
}

ServeNextAuthenticated("", next, w, r)
next.ServeHTTP(w, r)
//ServeNextError(next, w, r, authentication.ErrAuthenticationMissingCredentials)
})
}

0 comments on commit 9bf6831

Please sign in to comment.