-
-
Notifications
You must be signed in to change notification settings - Fork 364
doc(MFA): add MFA sample code #5975
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
37 changes: 37 additions & 0 deletions
37
src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/Login.razor
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,37 @@ | ||
| @page "/tutorials/mfa" | ||
| @inject IOptionsMonitor<WebsiteOptions> WebsiteOption | ||
|
|
||
| <div class="bb-sign"> | ||
| <div class="text-center"> | ||
| <img src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" /> | ||
| <h3>Sign in to Blazor</h3> | ||
| </div> | ||
| <div class="bb-sign-body"> | ||
| <div class="mb-2">Username or email address</div> | ||
| <input type="text" class="form-control mb-3" value="[email protected]" /> | ||
| <div class="d-flex mb-2"> | ||
| <div>Password</div> | ||
| <div>Forgot password?</div> | ||
| </div> | ||
| <input type="password" class="form-control" value="123456" /> | ||
| <button type="button" class="form-control bg-success text-white mt-3" @onclick="OnSubmit">Sign in</button> | ||
| <div class="bb-sign-divider text-center mt-3">Or</div> | ||
| <button type="button" class="form-control bg-secondary mt-3"> | ||
| <i class="fa-solid fa-user-lock"></i> | ||
| <span>Sign in with passkey</span> | ||
| </button> | ||
| </div> | ||
| <div class="bb-sign-callout mt-3"> | ||
| <div class="mt-1">New to Blazor? <a href="#">Create an account</a></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| @code { | ||
| [Inject, NotNull] | ||
| private NavigationManager? NavigationManager { get; set; } | ||
|
|
||
| private void OnSubmit() | ||
| { | ||
| NavigationManager.NavigateTo("/tutorials/mfa/two-factor"); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/Login.razor.css
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,50 @@ | ||
| .bb-sign { | ||
| margin: 0 auto; | ||
| width: 320px; | ||
| padding: 0 1rem; | ||
| } | ||
|
|
||
| .bb-sign img { | ||
| background-color: var(--bb-primary-color); | ||
| border-radius: 50%; | ||
| margin-block: 2rem; | ||
| } | ||
|
|
||
| .bb-sign-body { | ||
| background-color: #f6f8fa; | ||
| border: 1px solid var(--bs-border-color); | ||
| border-radius: var(--bs-border-radius); | ||
| padding: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-divider { | ||
| display: flex; | ||
| flex-basis: 100%; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .bb-sign-divider::before, | ||
| .bb-sign-divider::after { | ||
| content: ""; | ||
| position: relative; | ||
| display: inline-block; | ||
| width: 50%; | ||
| height: 1px; | ||
| vertical-align: middle; | ||
| background-color: #d1d9e0; | ||
| } | ||
|
|
||
| .bb-sign-divider::before { | ||
| right: 0.5rem; | ||
| } | ||
|
|
||
| .bb-sign-divider::after { | ||
| left: 0.5rem; | ||
| } | ||
|
|
||
| .bb-sign-callout { | ||
| padding: 1rem; | ||
| border: 1px solid var(--bs-border-color); | ||
| border-radius: var(--bs-border-radius); | ||
| text-align: center; | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/TwoFactor.razor
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,21 @@ | ||
| @page "/tutorials/mfa/two-factor" | ||
| @inject IOptionsMonitor<WebsiteOptions> WebsiteOption | ||
|
|
||
| <div class="bb-sign"> | ||
| <div class="text-center"> | ||
| <img src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" /> | ||
| <h1>Two-factor authentication</h1> | ||
| </div> | ||
| <div class="bb-sign-body"> | ||
| <div class="text-center"> | ||
| <img class="rounded-2" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" /> | ||
| <h3>Blazor Mobile</h3> | ||
| </div> | ||
| <div>We sent you a sign-in request on your Blazor Mobile app. Approve the request to verify your identity.</div> | ||
| </div> | ||
| <div class="bb-sign-callout mt-3"> | ||
| <div class="mt-1"> | ||
| <a href="./tutorials/mfa/two-factor/app">Use your authenticator app</a> | ||
ArgoZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| </div> | ||
| </div> | ||
44 changes: 44 additions & 0 deletions
44
src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/TwoFactor.razor.css
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,44 @@ | ||
| .bb-sign { | ||
| margin: 0 auto; | ||
| width: 320px; | ||
| padding: 0 1rem; | ||
| } | ||
|
|
||
| .bb-sign img { | ||
| background-color: var(--bb-primary-color); | ||
| border-radius: 50%; | ||
| margin-block: 2rem; | ||
| } | ||
|
|
||
| .bb-sign h1 { | ||
| font-size: 24px; | ||
| font-weight: 300; | ||
| letter-spacing: -0.5px; | ||
| margin-block-end: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-body { | ||
| background-color: #f6f8fa; | ||
| border: 1px solid var(--bs-border-color); | ||
| border-radius: var(--bs-border-radius); | ||
| padding: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-body img { | ||
| width: 32px; | ||
| height: auto; | ||
| margin: 0; | ||
| margin-block-end: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-body h3 { | ||
| font-size: 20px; | ||
| font-weight: 400; | ||
| } | ||
|
|
||
| .bb-sign-callout { | ||
| padding: 1rem; | ||
| border: 1px solid var(--bs-border-color); | ||
| border-radius: var(--bs-border-radius); | ||
| text-align: center; | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/TwoFactorApp.razor
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,48 @@ | ||
| @page "/tutorials/mfa/two-factor/app" | ||
| @inject IOptionsMonitor<WebsiteOptions> WebsiteOption | ||
|
|
||
| <div class="bb-sign"> | ||
| <div class="text-center"> | ||
| <img src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" /> | ||
| <h3>Two-factor authentication</h3> | ||
| </div> | ||
| <div class="bb-sign-body"> | ||
| <div class="text-center"> | ||
| <img class="rounded-2" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" /> | ||
| <h3>Authentication code</h3> | ||
| </div> | ||
| <div> | ||
| <OtpInput @bind-Value="@_code"></OtpInput> | ||
| </div> | ||
| <button type="button" class="form-control bg-success text-white mt-3" @onclick="OnVerify">Sign in</button> | ||
| <div class="mt-3"> | ||
| Open your two-factor authenticator (TOTP) app or browser extension to view your authentication code. | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| @code { | ||
| [Inject, NotNull] | ||
| private ITotpService? TotpService { get; set; } | ||
|
|
||
| [Inject, NotNull] | ||
| private ToastService? ToastService { get; set; } | ||
|
|
||
| private string _code = ""; | ||
|
|
||
| private async Task OnVerify() | ||
| { | ||
| if (string.IsNullOrEmpty(_code)) | ||
| { | ||
| return; | ||
| } | ||
| if (TotpService.Verify(_code)) | ||
| { | ||
| await ToastService.Success("Sign In", "Login success. redirect home Url"); | ||
| } | ||
| else | ||
| { | ||
| await ToastService.Error("Sign In", "Login failed."); | ||
| } | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/BootstrapBlazor.Server/Components/Samples/Tutorials/MFA/TwoFactorApp.razor.css
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,42 @@ | ||
| .bb-sign { | ||
| margin: 0 auto; | ||
| width: 406px; | ||
| padding: 0 1rem; | ||
| } | ||
|
|
||
| .bb-sign img { | ||
| background-color: var(--bb-primary-color); | ||
| border-radius: 50%; | ||
| margin-block: 2rem; | ||
| } | ||
|
|
||
| .bb-sign h1 { | ||
| font-size: 24px; | ||
| font-weight: 300; | ||
| letter-spacing: -0.5px; | ||
| margin-block-end: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-body { | ||
| background-color: #f6f8fa; | ||
| border: 1px solid var(--bs-border-color); | ||
| border-radius: var(--bs-border-radius); | ||
| padding: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-body img { | ||
| width: 32px; | ||
| height: auto; | ||
| margin: 0; | ||
| margin-block-end: 1rem; | ||
| } | ||
|
|
||
| .bb-sign-body h3 { | ||
| font-size: 20px; | ||
| font-weight: 400; | ||
| } | ||
|
|
||
| ::deep .bb-opt-input .bb-opt-item { | ||
| --bb-opt-item-width: 50px; | ||
| --bb-opt-font-size: 2em; | ||
| } |
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
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.