Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class PasswordFlowTokenRequest(
val clientSecret: String?,
val rememberMe: Boolean = true,
val captchaType: CaptchaType? = CaptchaType.INTERNAL,
val captchaCode: String?,
val captchaCode: String,
):Device()

data class ConfirmPasswordFlowTokenRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class RegisterUserRequest(
val firstName: String? = null,
val lastName: String? = null,
val captchaType: CaptchaType? = CaptchaType.INTERNAL,
val captchaCode: String?,
val captchaCode: String,
)

data class VerifyOTPRequest(
Expand Down Expand Up @@ -61,5 +61,5 @@ data class ConfirmForgetRequest(
data class ForgotPasswordRequest(
val username: String,
val captchaType: CaptchaType? = CaptchaType.INTERNAL,
val captchaCode: String?,
val captchaCode: String,
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package co.nilin.opex.auth.service

import co.nilin.opex.auth.data.ActionType
import co.nilin.opex.auth.kafka.AuthEventProducer
import co.nilin.opex.auth.model.*
import co.nilin.opex.auth.proxy.CaptchaProxy
import co.nilin.opex.auth.proxy.DeviceManagementProxy
import co.nilin.opex.auth.proxy.KeycloakProxy
import co.nilin.opex.auth.proxy.OTPProxy
Expand All @@ -14,7 +14,7 @@ import org.springframework.stereotype.Service
class ForgetPasswordService(
private val otpProxy: OTPProxy,
private val keycloakProxy: KeycloakProxy,
private val captchaHandler: CaptchaHandler,
private val captchaProxy: CaptchaProxy,
private val authEventProducer: AuthEventProducer,
private val deviceManagementProxy: DeviceManagementProxy,
private val tempTokenService: TempTokenService
Expand All @@ -23,13 +23,10 @@ class ForgetPasswordService(
private val logger by LoggerDelegate()



suspend fun forgetPassword(request: ForgotPasswordRequest): TempOtpResponse {
captchaHandler.validateCaptchaWithActionCache(
username = request.username,
captchaCode = request.captchaCode,
captchaType = request.captchaType,
action = ActionType.FORGET
captchaProxy.validateCaptcha(
request.captchaCode,
request.captchaType ?: CaptchaType.INTERNAL
)
val uName = Username.create(request.username)
val otpReceiver = OTPReceiver(uName.value, uName.type.otpType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.nilin.opex.auth.service

import co.nilin.opex.auth.data.ActionType
import co.nilin.opex.auth.data.Device
import co.nilin.opex.auth.data.LoginEvent
import co.nilin.opex.auth.kafka.AuthEventProducer
import co.nilin.opex.auth.model.*
import co.nilin.opex.auth.proxy.CaptchaProxy
import co.nilin.opex.auth.proxy.GoogleProxy
import co.nilin.opex.auth.proxy.KeycloakProxy
import co.nilin.opex.auth.proxy.OTPProxy
Expand All @@ -20,7 +20,7 @@ class LoginService(
private val otpProxy: OTPProxy,
private val keycloakProxy: KeycloakProxy,
private val googleProxy: GoogleProxy,
private val captchaHandler: CaptchaHandler,
private val captchaProxy: CaptchaProxy,
private val authEventProducer: AuthEventProducer,
@Value("\${app.pre-auth-client-secret}")
private val preAuthClientSecretKey: String,
Expand All @@ -30,14 +30,13 @@ class LoginService(
private val PRE_AUTH_CLIENT_ID = "pre-auth-client"

suspend fun requestGetToken(request: PasswordFlowTokenRequest): TokenResponse {
captchaHandler.validateCaptchaWithActionCache(
username = request.username,
captchaCode = request.captchaCode,
captchaType = request.captchaType,
action = ActionType.LOGIN
captchaProxy.validateCaptcha(
request.captchaCode,
request.captchaType ?: CaptchaType.INTERNAL
)
val username = Username.create(request.username)
val user = keycloakProxy.findUserByUsername(username) ?: throw OpexError.UsernameOrPasswordIsIncorrect.exception()
val user =
keycloakProxy.findUserByUsername(username) ?: throw OpexError.UsernameOrPasswordIsIncorrect.exception()
val otpTypes = (user.attributes?.get(Attributes.OTP)?.get(0) ?: OTPType.NONE.name).split(",")

if (otpTypes.contains(OTPType.NONE.name)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package co.nilin.opex.auth.service

import co.nilin.opex.auth.data.ActionType
import co.nilin.opex.auth.data.Device
import co.nilin.opex.auth.data.LoginEvent
import co.nilin.opex.auth.data.UserCreatedEvent
import co.nilin.opex.auth.data.UserRole
import co.nilin.opex.auth.kafka.AuthEventProducer
import co.nilin.opex.auth.model.*
import co.nilin.opex.auth.proxy.CaptchaProxy
import co.nilin.opex.auth.proxy.GoogleProxy
import co.nilin.opex.auth.proxy.KeycloakProxy
import co.nilin.opex.auth.proxy.OTPProxy
Expand All @@ -18,19 +18,17 @@ import java.time.LocalDateTime
class RegisterService(
private val otpProxy: OTPProxy,
private val keycloakProxy: KeycloakProxy,
private val captchaHandler: CaptchaHandler,
private val captchaProxy: CaptchaProxy,
private val googleProxy: GoogleProxy,
private val authProducer: AuthEventProducer,
private val tempTokenService: TempTokenService
private val tempTokenService: TempTokenService

) {
) {
//TODO IMPORTANT: remove in production
suspend fun registerUser(request: RegisterUserRequest): TempOtpResponse {
captchaHandler.validateCaptchaWithActionCache(
username = request.username,
captchaCode = request.captchaCode,
captchaType = request.captchaType,
action = ActionType.REGISTER
captchaProxy.validateCaptcha(
request.captchaCode,
request.captchaType ?: CaptchaType.INTERNAL
)
val username = Username.create(request.username)
val userStatus = isUserDuplicate(username)
Expand Down
Loading