-
-
Notifications
You must be signed in to change notification settings - Fork 175
feat(ui): add two-factor authentication (TOTP) support #5888
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
Open
luannmoreira
wants to merge
4
commits into
master
Choose a base branch
from
feat/ui-react-mfa-login
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,053
−540
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7b679d0
feat(ui-react): add two-factor authentication (TOTP) support
luannmoreira ae756db
test(ui-react): add comprehensive test coverage for MFA components
luannmoreira 3090fa1
fix(ui-react): address MFA code review feedback
luannmoreira a527556
fix(ui-react): populate full session state and fix duplicate buttons
luannmoreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import apiClient from "./client"; | ||
| import type { | ||
| MfaGenerateResponse, | ||
| MfaEnableRequest, | ||
| MfaAuthRequest, | ||
| MfaDisableRequest, | ||
| MfaRecoverRequest, | ||
| MfaResetRequest, | ||
| LoginResponse, | ||
| } from "../types/mfa"; | ||
|
|
||
| // Generate QR code and recovery codes | ||
| export async function generateMfa(): Promise<MfaGenerateResponse> { | ||
| const { data } = await apiClient.get<MfaGenerateResponse>( | ||
| "/api/user/mfa/generate" | ||
| ); | ||
| return data; | ||
| } | ||
|
|
||
| // Enable MFA with verification | ||
| export async function enableMfa(payload: MfaEnableRequest): Promise<void> { | ||
| await apiClient.put("/api/user/mfa/enable", payload); | ||
| } | ||
|
|
||
| // Validate MFA code after password login | ||
| export async function validateMfa( | ||
| payload: MfaAuthRequest | ||
| ): Promise<LoginResponse> { | ||
| const { data } = await apiClient.post<LoginResponse>( | ||
| "/api/user/mfa/auth", | ||
| payload | ||
| ); | ||
| return data; | ||
| } | ||
|
|
||
| // Disable MFA | ||
| export async function disableMfa(payload: MfaDisableRequest): Promise<void> { | ||
| await apiClient.put("/api/user/mfa/disable", payload); | ||
| } | ||
|
|
||
| // Recover account with recovery code | ||
| export async function recoverMfa( | ||
| payload: MfaRecoverRequest | ||
| ): Promise<{ data: LoginResponse; expiresAt: string }> { | ||
| const response = await apiClient.post<LoginResponse>( | ||
| "/api/user/mfa/recover", | ||
| payload | ||
| ); | ||
| return { | ||
| data: response.data, | ||
| expiresAt: (response.headers["x-expires-at"] as string | undefined) || "", | ||
luannmoreira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
|
|
||
| // Request MFA reset via email | ||
| export async function requestMfaReset(identifier: string): Promise<string> { | ||
| await apiClient.post("/api/user/mfa/reset", { identifier }); | ||
| // User ID will come from the email link, not from this response | ||
| return identifier; | ||
luannmoreira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
luannmoreira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Complete MFA reset with email codes | ||
| export async function completeMfaReset( | ||
| userId: string, | ||
| payload: MfaResetRequest | ||
| ): Promise<LoginResponse> { | ||
| const { data } = await apiClient.put<LoginResponse>( | ||
| `/api/user/mfa/reset/${userId}`, | ||
| payload | ||
| ); | ||
| return data; | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
ui-react/apps/admin/src/components/common/AuthFooterLinks.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { BookOpenIcon } from "@heroicons/react/24/outline"; | ||
|
|
||
| export default function AuthFooterLinks() { | ||
| return ( | ||
| <div | ||
| className="flex items-center justify-center gap-6 mt-10 animate-fade-in" | ||
| style={{ animationDelay: "800ms" }} | ||
| > | ||
| <a | ||
| href="https://docs.shellhub.io" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="inline-flex items-center gap-1.5 text-xs text-text-muted hover:text-text-secondary transition-colors" | ||
| > | ||
| <BookOpenIcon className="w-3.5 h-3.5" /> | ||
| Documentation | ||
| </a> | ||
| <span className="w-px h-3 bg-border" /> | ||
| <a | ||
| href="https://github.com/shellhub-io/shellhub" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="inline-flex items-center gap-1.5 text-xs text-text-muted hover:text-text-secondary transition-colors" | ||
| > | ||
| <svg className="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 24 24"> | ||
| <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" /> | ||
| </svg> | ||
| Community | ||
| </a> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.