-
Notifications
You must be signed in to change notification settings - Fork 903
support login totp mfa #4538
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
support login totp mfa #4538
Changes from all commits
Commits
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
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
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,84 @@ | ||
| /* | ||
| Copyright 2021 The KodeRover Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package login | ||
|
|
||
| import ( | ||
| "github.com/gin-gonic/gin" | ||
|
|
||
| loginsvc "github.com/koderover/zadig/v2/pkg/microservice/user/core/service/login" | ||
| internalhandler "github.com/koderover/zadig/v2/pkg/shared/handler" | ||
| ) | ||
|
|
||
| // @Summary 初始化登录态 MFA 配置 | ||
| // @Description 基于 mfa_challenge_token 生成当前登录挑战所需的 MFA 配置数据,返回 secret、二维码和 required_action | ||
| // @Tags user | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param body body loginsvc.MFASetupArgs true "body" | ||
| // @Success 200 {object} loginsvc.MFASetupResp | ||
| // @Router /api/v1/login/mfa/setup [post] | ||
| func MFASetup(c *gin.Context) { | ||
| ctx := internalhandler.NewContext(c) | ||
| defer func() { internalhandler.JSONResponse(c, ctx) }() | ||
|
|
||
| args := &loginsvc.MFASetupArgs{} | ||
| if err := c.ShouldBindJSON(args); err != nil { | ||
| ctx.RespErr = err | ||
| return | ||
| } | ||
| ctx.Resp, ctx.RespErr = loginsvc.SetupMFA(args, ctx.Logger) | ||
| } | ||
|
|
||
| // @Summary 完成登录态 MFA 绑定 | ||
| // @Description 在登录挑战阶段提交 OTP 完成首次 MFA 绑定,成功后返回正式登录态和恢复码 | ||
| // @Tags user | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param body body loginsvc.MFAEnrollArgs true "body" | ||
| // @Success 200 {object} loginsvc.User | ||
| // @Router /api/v1/login/mfa/enroll [post] | ||
| func MFAEnroll(c *gin.Context) { | ||
| ctx := internalhandler.NewContext(c) | ||
| defer func() { internalhandler.JSONResponse(c, ctx) }() | ||
|
|
||
| args := &loginsvc.MFAEnrollArgs{} | ||
| if err := c.ShouldBindJSON(args); err != nil { | ||
| ctx.RespErr = err | ||
| return | ||
| } | ||
| ctx.Resp, ctx.RespErr = loginsvc.EnrollMFA(args, ctx.Logger) | ||
| } | ||
|
|
||
| // @Summary 完成登录态 MFA 验证 | ||
| // @Description 在登录挑战阶段提交 OTP 或恢复码完成 MFA 验证,成功后返回正式登录态 | ||
| // @Tags user | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param body body loginsvc.MFAVerifyArgs true "body" | ||
| // @Success 200 {object} loginsvc.User | ||
| // @Router /api/v1/login/mfa/verify [post] | ||
| func MFAVerify(c *gin.Context) { | ||
| ctx := internalhandler.NewContext(c) | ||
| defer func() { internalhandler.JSONResponse(c, ctx) }() | ||
|
|
||
| args := &loginsvc.MFAVerifyArgs{} | ||
| if err := c.ShouldBindJSON(args); err != nil { | ||
| ctx.RespErr = err | ||
| return | ||
| } | ||
| ctx.Resp, ctx.RespErr = loginsvc.VerifyMFA(args, ctx.Logger) | ||
| } |
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.