Skip to content

Implement Two-Factor Authentication - #720

Merged
AmirRajabii merged 4 commits into
devfrom
implement-two-factor-authentication
Aug 18, 2026
Merged

Implement Two-Factor Authentication#720
AmirRajabii merged 4 commits into
devfrom
implement-two-factor-authentication

Conversation

@AmirRajabii

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces end-to-end two-factor authentication (2FA) support in the auth-gateway, including TOTP (authenticator app) flows backed by the OTP service, and extends OTP requests with an action context (REGISTER/LOGIN/FORGET/TWO_FACTOR).

Changes:

  • Added user-facing 2FA endpoints and service logic to enable/disable 2FA and to set up/verify TOTP.
  • Extended OTP proxying to include an optional action and added resend OTP endpoints for registration and forgot-password flows.
  • Updated OTP/TOTP query responses to include a TOTP URI and added app name configuration for TOTP labeling.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
otp/otp-app/src/main/kotlin/co/nilin/opex/otp/app/service/TOTPService.kt Returns richer TOTP query response including a generated otpauth URI.
otp/otp-app/src/main/kotlin/co/nilin/opex/otp/app/model/TOTPQueryResponse.kt Adds uri to the TOTP query response model.
otp/otp-app/src/main/kotlin/co/nilin/opex/otp/app/controller/TOTPController.kt Simplifies query endpoint to return the service response directly.
docker-compose.yml Wires APP_NAME env var into auth-gateway container.
common/src/main/kotlin/co/nilin/opex/common/OpexError.kt Adds InvalidOTPType error for 2FA flows.
auth-gateway/auth-gateway-app/src/main/resources/application.yml Adds app.name configuration with default value.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/TwoFactorConfigService.kt New service implementing enable/disable 2FA and TOTP setup/verification.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/RegisterService.kt Adjusts registration OTP request flow and adds resend registration OTP.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/LoginService.kt Updates login flow to support per-user 2FA method incl. TOTP and OTP action tagging.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/ForgetPasswordService.kt Adds OTP action tagging and resend forgot-password OTP.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/proxy/OTPProxy.kt Adds action to OTP requests and adds TOTP endpoints (setup/query/verify).
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/proxy/KeycloakProxy.kt Adds user lookup by UUID and OTP attribute update support; adjusts user creation defaults.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/model/UserRegister.kt Removes first/last name from register request payload.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/model/TwoFactor.kt Adds request/response DTOs for 2FA endpoints.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/model/TOTP.kt Adds DTOs for TOTP setup/query/verify payloads.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/model/OTP.kt Extends OTPAction enum to cover login and 2FA.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/controller/UserTwoFactorConfigController.kt New authenticated endpoints for 2FA config and TOTP setup/verify.
auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/controller/PublicUserController.kt Adds public resend-OTP endpoints for register/forget flows.
Suppressed comments (1)

auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/proxy/KeycloakProxy.kt:431

  • updateOtpConfig() sets Attributes.OTP to a raw String, but attributes are modeled/handled as Map<String, List<String>>. This can cause Keycloak update requests to fail or later reads to misinterpret the OTP config.

Wrap the value in a single-element list.

    suspend fun updateOtpConfig(
        userId: String,
        otpConfig: String
    ) {
        updateUserFields(
            userId = userId,
            updates = mapOf(
                "attributes" to mapOf(
                    Attributes.OTP to otpConfig
                )
            )
        )

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docker-compose.yml Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@AmirRajabii
AmirRajabii merged commit 7050bdf into dev Aug 18, 2026
1 of 2 checks passed
@AmirRajabii
AmirRajabii deleted the implement-two-factor-authentication branch August 18, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants