Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Jan 2, 2025
1 parent 6a6d847 commit e77d074
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
4 changes: 1 addition & 3 deletions web/packages/teleport/src/JoinTokens/JoinTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export const JoinTokens = () => {
const [editingToken, setEditingToken] = useState<JoinToken | null>(null);
const [tokenToDelete, setTokenToDelete] = useState<JoinToken | null>(null);
const [joinTokensAttempt, runJoinTokensAttempt, setJoinTokensAttempt] =
useAsync(async () => {
return ctx.joinTokenService.fetchJoinTokens(null);
});
useAsync(() => ctx.joinTokenService.fetchJoinTokens(null));

const resources = useResources(
joinTokensAttempt.data?.items.map(makeTokenResource) || [],
Expand Down
44 changes: 25 additions & 19 deletions web/packages/teleport/src/MFAContext/MFAContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PropsWithChildren, createContext, useCallback, useRef } from 'react';
import { createContext, PropsWithChildren, useCallback, useState } from 'react';

import AuthnDialog from 'teleport/components/AuthnDialog';
import { useMfa } from 'teleport/lib/useMfa';
import auth, { MfaChallengeScope } from 'teleport/services/auth/auth';
Expand All @@ -11,30 +12,35 @@ export interface MfaContextValue {
export const MfaContext = createContext<MfaContextValue>(null);

export const MfaContextProvider = ({ children }: PropsWithChildren) => {
const allowReuse = useRef(false);
const adminMfa = useMfa({
req: {
scope: MfaChallengeScope.ADMIN_ACTION,
allowReuse: allowReuse.current,
isMfaRequiredRequest: {
admin_action: {},
},
},
});
const adminMfa = useMfa({});

const getAdminActionMfaResponse = useCallback(
async (reusable: boolean = false) => {
allowReuse.current = reusable;
return (await adminMfa.getChallengeResponse()) || {}; // return an empty challenge to prevent mfa retry.
const chal = await auth.getMfaChallenge({
scope: MfaChallengeScope.ADMIN_ACTION,
allowReuse: reusable,
isMfaRequiredRequest: {
admin_action: {},
},
});

const res = await adminMfa.getChallengeResponse(chal);
if (!res) {
return {}; // return an empty challenge to prevent mfa retry.
}

return res;
},
[adminMfa, allowReuse]
[adminMfa]
);

const mfaCtx = {
getAdminActionMfaResponse,
useMfa,
};
auth.setMfaContext(mfaCtx);
const [mfaCtx, setMfaCtx] = useState<MfaContextValue>();

if (!mfaCtx) {
const mfaCtx = { getAdminActionMfaResponse };
setMfaCtx(mfaCtx);
auth.setMfaContext(mfaCtx);
}

return (
<MfaContext.Provider value={mfaCtx}>
Expand Down

0 comments on commit e77d074

Please sign in to comment.