mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
fix: only use groups in OAuth
This commit is contained in:
@@ -70,7 +70,7 @@ export const ContinuePage = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
fullWidth
|
fullWidth
|
||||||
mt="sm"
|
mt="xs"
|
||||||
color="gray"
|
color="gray"
|
||||||
onClick={() => (window.location.href = "/")}
|
onClick={() => (window.location.href = "/")}
|
||||||
>
|
>
|
||||||
@@ -110,7 +110,7 @@ export const ContinuePage = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
fullWidth
|
fullWidth
|
||||||
mt="sm"
|
mt="xs"
|
||||||
color="gray"
|
color="gray"
|
||||||
onClick={() => (window.location.href = "/")}
|
onClick={() => (window.location.href = "/")}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import { Button, Code, Paper, Text } from "@mantine/core";
|
|||||||
import { Layout } from "../components/layouts/layout";
|
import { Layout } from "../components/layouts/layout";
|
||||||
import { Navigate } from "react-router";
|
import { Navigate } from "react-router";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { isValidQuery } from "../utils/utils";
|
import { isValidQuery } from "../utils/utils";
|
||||||
|
import { useIsMounted } from "../lib/hooks/use-is-mounted";
|
||||||
|
|
||||||
export const UnauthorizedPage = () => {
|
export const UnauthorizedPage = () => {
|
||||||
const queryString = window.location.search;
|
const queryString = window.location.search;
|
||||||
@@ -12,13 +13,31 @@ export const UnauthorizedPage = () => {
|
|||||||
const groupErr = params.get("groupErr") ?? "";
|
const groupErr = params.get("groupErr") ?? "";
|
||||||
const resource = params.get("resource") ?? "";
|
const resource = params.get("resource") ?? "";
|
||||||
|
|
||||||
|
const [isGroupErr, setIsGroupErr] = React.useState(false);
|
||||||
|
|
||||||
|
const useMounted = useIsMounted();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (useMounted()) {
|
||||||
|
if (isValidQuery(groupErr)) {
|
||||||
|
if (groupErr === "true") {
|
||||||
|
setIsGroupErr(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsGroupErr(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsGroupErr(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
if (!isValidQuery(username)) {
|
if (!isValidQuery(username)) {
|
||||||
return <Navigate to="/" />;
|
return <Navigate to="/" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidQuery(resource) && !isValidQuery(groupErr)) {
|
if (isValidQuery(resource) && !isGroupErr) {
|
||||||
return (
|
return (
|
||||||
<UnauthorizedLayout>
|
<UnauthorizedLayout>
|
||||||
<Trans
|
<Trans
|
||||||
@@ -31,7 +50,7 @@ export const UnauthorizedPage = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidQuery(groupErr) && isValidQuery(resource)) {
|
if (isGroupErr && isValidQuery(resource)) {
|
||||||
return (
|
return (
|
||||||
<UnauthorizedLayout>
|
<UnauthorizedLayout>
|
||||||
<Trans
|
<Trans
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
|
|||||||
// Get the container labels
|
// Get the container labels
|
||||||
labels, err := h.Docker.GetLabels(appId)
|
labels, err := h.Docker.GetLabels(appId)
|
||||||
|
|
||||||
|
log.Debug().Interface("labels", labels).Msg("Got labels")
|
||||||
|
|
||||||
// Check if there was an error
|
// Check if there was an error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to get container labels")
|
log.Error().Err(err).Msg("Failed to get container labels")
|
||||||
@@ -183,8 +185,8 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Interface("labels", labels).Msg("Got labels")
|
// Check groups if using OAuth
|
||||||
|
if userContext.OAuth {
|
||||||
// Check if user is in required groups
|
// Check if user is in required groups
|
||||||
groupOk := h.Auth.OAuthGroup(c, userContext, labels)
|
groupOk := h.Auth.OAuthGroup(c, userContext, labels)
|
||||||
|
|
||||||
@@ -232,6 +234,7 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
|
|||||||
c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%s/unauthorized?%s", h.Config.AppURL, queries.Encode()))
|
c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%s/unauthorized?%s", h.Config.AppURL, queries.Encode()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.Header("Remote-User", utils.SanitizeHeader(userContext.Username))
|
c.Header("Remote-User", utils.SanitizeHeader(userContext.Username))
|
||||||
c.Header("Remote-Name", utils.SanitizeHeader(userContext.Name))
|
c.Header("Remote-Name", utils.SanitizeHeader(userContext.Name))
|
||||||
|
|||||||
Reference in New Issue
Block a user