Add API tokens support #9
@ -1,3 +1,4 @@
|
|||||||
|
import { time } from "../utils/DateUtils";
|
||||||
import { APIClient } from "./ApiClient";
|
import { APIClient } from "./ApiClient";
|
||||||
|
|
||||||
export type RightVerb = "POST" | "GET" | "PUT" | "DELETE" | "PATCH";
|
export type RightVerb = "POST" | "GET" | "PUT" | "DELETE" | "PATCH";
|
||||||
@ -23,6 +24,11 @@ export function APITokenURL(t: APIToken, edit: boolean = false): string {
|
|||||||
return `/token/${t.id}${edit ? "/edit" : ""}`;
|
return `/token/${t.id}${edit ? "/edit" : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ExpiredAPIToken(t: APIToken): boolean {
|
||||||
|
if (!t.max_inactivity) return false;
|
||||||
|
return t.last_used + t.max_inactivity < time();
|
||||||
|
}
|
||||||
|
|
||||||
export interface APITokenPrivateKey {
|
export interface APITokenPrivateKey {
|
||||||
alg: string;
|
alg: string;
|
||||||
priv: string;
|
priv: string;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import React from "react";
|
import VisibilityIcon from "@mui/icons-material/Visibility";
|
||||||
import { APIToken, APITokenURL, TokensApi } from "../api/TokensApi";
|
|
||||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
IconButton,
|
IconButton,
|
||||||
@ -12,11 +10,18 @@ import {
|
|||||||
TableHead,
|
TableHead,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { RouterLink } from "../widgets/RouterLink";
|
import React from "react";
|
||||||
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import VisibilityIcon from "@mui/icons-material/Visibility";
|
import {
|
||||||
|
APIToken,
|
||||||
|
APITokenURL,
|
||||||
|
ExpiredAPIToken,
|
||||||
|
TokensApi,
|
||||||
|
} from "../api/TokensApi";
|
||||||
|
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||||
|
import { RouterLink } from "../widgets/RouterLink";
|
||||||
import { TimeWidget, timeDiff } from "../widgets/TimeWidget";
|
import { TimeWidget, timeDiff } from "../widgets/TimeWidget";
|
||||||
|
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
|
||||||
|
|
||||||
export function TokensListRoute(): React.ReactElement {
|
export function TokensListRoute(): React.ReactElement {
|
||||||
const [list, setList] = React.useState<APIToken[] | undefined>();
|
const [list, setList] = React.useState<APIToken[] | undefined>();
|
||||||
@ -74,8 +79,11 @@ export function TokensListRouteInner(p: {
|
|||||||
key={t.id}
|
key={t.id}
|
||||||
hover
|
hover
|
||||||
onDoubleClick={() => navigate(APITokenURL(t))}
|
onDoubleClick={() => navigate(APITokenURL(t))}
|
||||||
|
style={{ backgroundColor: ExpiredAPIToken(t) ? "red" : "" }}
|
||||||
>
|
>
|
||||||
<TableCell>{t.name}</TableCell>
|
<TableCell>
|
||||||
|
{t.name} {ExpiredAPIToken(t) && <i>(Expired)</i>}
|
||||||
|
</TableCell>
|
||||||
<TableCell>{t.description}</TableCell>
|
<TableCell>{t.description}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<TimeWidget time={t.created} />
|
<TimeWidget time={t.created} />
|
||||||
|
Loading…
Reference in New Issue
Block a user