Return 202 when auth needs org
All checks were successful
build-and-deploy / build-deploy (push) Successful in 29s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 29s
This commit is contained in:
@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@@ -33,19 +34,19 @@ class Auth(
|
||||
fun verify(
|
||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||
request: HttpServletRequest
|
||||
): AuthResponse {
|
||||
): ResponseEntity<AuthResponse> {
|
||||
logger.info("Auth verify hit, principalPresent={}", principal != null)
|
||||
val resolved = principal?.let { ResolveResult(it, null) } ?: resolvePrincipalFromHeader(request)
|
||||
return resolved.toResponse()
|
||||
return resolved.toResponseEntity()
|
||||
}
|
||||
|
||||
@GetMapping("/me")
|
||||
fun me(
|
||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||
request: HttpServletRequest
|
||||
): AuthResponse {
|
||||
): ResponseEntity<AuthResponse> {
|
||||
val resolved = principal?.let { ResolveResult(it, null) } ?: resolvePrincipalFromHeader(request)
|
||||
return resolved.toResponse()
|
||||
return resolved.toResponseEntity()
|
||||
}
|
||||
|
||||
private fun buildAuthResponse(principal: MyPrincipal): AuthResponse {
|
||||
@@ -141,11 +142,12 @@ class Auth(
|
||||
)
|
||||
}
|
||||
|
||||
private fun ResolveResult.toResponse(): AuthResponse {
|
||||
private fun ResolveResult.toResponseEntity(): ResponseEntity<AuthResponse> {
|
||||
return if (principal == null) {
|
||||
AuthResponse(status = "NEEDS_ORG", pendingUserId = pendingUserId)
|
||||
ResponseEntity.status(HttpStatus.ACCEPTED)
|
||||
.body(AuthResponse(status = "NEEDS_ORG", pendingUserId = pendingUserId))
|
||||
} else {
|
||||
buildAuthResponse(principal)
|
||||
ResponseEntity.ok(buildAuthResponse(principal))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user